Skip to content

Commit

Permalink
Merge pull request #51 from theGreatHerrLebert/david@mixture
Browse files Browse the repository at this point in the history
adding predictor structure to algorithm
  • Loading branch information
theGreatHerrLebert authored Nov 21, 2023
2 parents 8a272c5 + deee416 commit 829b5b2
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 829b5b2

Please sign in to comment.