File size: 1,034 Bytes
2065c50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from tensorflow.keras.saving import register_keras_serializable
from tensorflow.keras import layers, models, backend as K
import tensorflow as tf

@register_keras_serializable()
def drainage_penalty(inputs):
    dd = inputs[:, 2]
    return (1.0 - 0.4 * tf.sigmoid((dd - 3.5) * 2))[:, None]

@register_keras_serializable()
def convergence_suppressor(inputs):
    ci = inputs[:, 4]
    return (1.0 + 0.3 * tf.sigmoid((ci - 0.5) * 8))[:, None]

@register_keras_serializable()
def intensity_slope_amplifier(inputs):
    rainfall_intensity = inputs[:, 0]
    slope = inputs[:, 1]
    runoff_boost = tf.sigmoid((rainfall_intensity - 75) * 0.08)
    slope_boost = tf.sigmoid((slope - 10) * 0.05)
    return (1.0 + 0.35 * runoff_boost * slope_boost)[:, None]

def clip_modulation(x):
    return tf.clip_by_value(x, 0.7, 1.3)

CUSTOM_OBJECTS = {
    'drainage_penalty': drainage_penalty,
    'intensity_slope_amplifier': intensity_slope_amplifier,
    'convergence_suppressor': convergence_suppressor,
    'clip_modulation': clip_modulation
}