i am experiencing an annoying issue with the neural network that i have created and that i use as a core element of a deep ensemble network to learn the uncertainty in a regression task
def NLL(y, distr):
return -distr.log_prob(y)
def normal_sp(params):
return tfd.Normal(loc=params[:,0:1], scale=1e-3 + tf.math.softplus(0.005* params[:,1:2]))
def create_model():
inputs = Input(shape=(1,),name="input layer")
x = Dense(20, activation="relu",
kernel_regularizer=regularizers.L2( l2=1e-4),
bias_regularizer=regularizers.L2(1e-4))(inputs)
x = Dense(50, activation="relu",
kernel_regularizer=regularizers.L2( l2=1e-4),
bias_regularizer=regularizers.L2(1e-4))(x)
x = Dense(20, activation="relu",
kernel_regularizer=regularizers.L2( l2=1e-4),
bias_regularizer=regularizers.L2(1e-4))(x)
params_mc = Dense(2,activation="relu",activity_regularizer=regularizers.L2(1e-5))(x)
dist_mc = tfp.layers.DistributionLambda(normal_sp, name='normal_sp')( params_mc )
modello = Model(inputs=inputs, outputs=dist_mc)
return modello
optimizer = tf.optimizers.Adam(learning_rate=0.0002)
model = create_model();
model.compile(optimizer=optimizer,loss=NLL,jit_compile=True )
model.fit(X, y, epochs=5000, verbose=0, batch_size=batch_size,validation_data=(X_val,y_val) )
the problem is that this network around 30% of the times refuses to learn anything and mess up the entire ensemble. for example this is the plot of the prediction of 5 trained models
the fourth model is stuck around zero and ruins everything
I don't understand what is the problem, it makes no sense.
