smash.Model.set_nn_parameters_bias#
- Model.set_nn_parameters_bias(value=None, initializer='zeros', random_state=None)[source]#
Set the values of the bias in the parameterization neural network.
- Parameters:
- valuelist[float or
numpy.ndarray] or None, default None The list of values to set to the biases of trainable layers. If an element of the list is a
numpy.ndarray, its shape must be broadcastable into the bias shape of that layer. If not used, a default or specified initialization method will be used.- initializerstr, default ‘zeros’
Bias initialization method. Should be one of
'uniform','glorot_uniform','he_uniform','normal','glorot_normal','he_normal','zeros'. Only used if value is not set.- random_stateint or None, default None
Random seed used for the initialization in case of using initializer.
Note
If not given, the neural network parameters will be initialized with a random seed.
- valuelist[float or
See also
Model.nn_parametersThe weight and bias of the parameterization neural network.
Model.get_nn_parameters_biasGet the bias of the parameterization neural network.
Examples
>>> from smash.factory import load_dataset >>> setup, mesh = load_dataset("cance")
Set the hydrological module to
'gr4_mlp'(hybrid hydrological model with multilayer perceptron)>>> setup["hydrological_module"] = "gr4_mlp"
Set the number of neurons in the hidden layer to 6 (the default value is 16, if not set)
>>> setup["hidden_neuron"] = 6 >>> model = smash.Model(setup, mesh)
Set random biases using Glorot normal initializer
>>> model.set_nn_parameters_bias(initializer="glorot_normal", random_state=0) >>> model.get_nn_parameters_bias() [array([ 0.94292563, 0.21389303, 0.5231575 , 1.1978078 , 0.99825174, -0.522377 ], dtype=float32), array([ 0.60088867, -0.09572671, -0.06528133, 0.2596853 ], dtype=float32)]
The output contains a list of bias values for trainable layers.
Set biases with specified values
>>> import numpy as np >>> np.random.seed(0) >>> model.set_nn_parameters_bias([np.random.normal(size=6), 0]) >>> model.get_nn_parameters_bias() [array([ 1.7640524, 0.4001572, 0.978738 , 2.2408931, 1.867558 , -0.9772779], dtype=float32), array([0., 0., 0., 0.], dtype=float32)]