Skip to content

Commit

Permalink
adding predictor structure to algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
theGreatHerrLebert committed Nov 21, 2023
1 parent 4452421 commit deee416
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 0 deletions.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
29 changes: 29 additions & 0 deletions imspy/imspy/algorithm/rt/predictors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import numpy as np
import tensorflow as tf
import importlib.resources as resources

"""
def get_model_path(model_name: str) -> str:
return resources.files('ionmob.pretrained_models').joinpath(model_name)
def get_gru_predictor(model_name: str = 'GRUPredictor') -> tf.keras.models.Model:
return tf.keras.models.load_model(get_model_path(model_name))
"""


class ProjectToInitialSqrtCCS(tf.keras.layers.Layer):
"""
Simple sqrt regression layer, calculates ccs value as linear mapping from mz, charge -> ccs
"""

def __init__(self, slopes, intercepts):
super(ProjectToInitialSqrtCCS, self).__init__()
self.slopes = tf.constant([slopes])
self.intercepts = tf.constant([intercepts])

def call(self, inputs, **kwargs):
mz, charge = inputs[0], inputs[1]
# since charge is one-hot encoded, can use it to gate linear prediction by charge state
return tf.expand_dims(tf.reduce_sum((self.slopes * tf.sqrt(mz) + self.intercepts) * tf.squeeze(charge), axis=1),
1)

0 comments on commit deee416

Please sign in to comment.