File size: 1,831 Bytes
5151965
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from tensorflow.keras.models import load_model
from tensorflow.keras.saving import register_keras_serializable
import tensorflow as tf

@register_keras_serializable()
class CAPEAmplifier(tf.keras.layers.Layer):
    def __init__(self, threshold=2000, scale=0.001, **kwargs):
        super().__init__(**kwargs)
        self.threshold = threshold
        self.scale = scale

    def call(self, inputs):
        cape = inputs[:, 1]
        boost = tf.sigmoid((cape - self.threshold) * self.scale)
        mod = 1.0 + 0.3 * boost
        return tf.expand_dims(mod, axis=-1)

@register_keras_serializable()
class LCLSuppressor(tf.keras.layers.Layer):
    def __init__(self, threshold=1400, scale=0.002, **kwargs):
        super().__init__(**kwargs)
        self.threshold = threshold
        self.scale = scale

    def call(self, inputs):
        lcl = inputs[:, 2]
        suppression = tf.sigmoid((lcl - self.threshold) * self.scale)
        return tf.expand_dims(1.0 - 0.25 * suppression, axis=-1)

@register_keras_serializable()
class STPActivator(tf.keras.layers.Layer):
    def __init__(self, threshold=1.5, scale=1.0, **kwargs):
        super().__init__(**kwargs)
        self.threshold = threshold
        self.scale = scale

    def call(self, inputs):
        stp = inputs[:, 4]
        activation = tf.sigmoid((stp - self.threshold) * self.scale)
        return tf.expand_dims(1.0 + 0.2 * activation, axis=-1)

@register_keras_serializable()
class ModulationMixer(tf.keras.layers.Layer):
    def call(self, inputs):
        cape_mod, lcl_mod, stp_mod = inputs
        combined = cape_mod * lcl_mod * stp_mod
        return 1.0 + 0.3 * tf.tanh(combined - 1.0)

CUSTOM_OBJECTS = {
    'ModulationMixer': ModulationMixer,
    'STPActivator': STPActivator,
    'CAPEAmplifier': CAPEAmplifier,
    'LCLSuppressor': LCLSuppressor
}