smash.Model.set_nn_parameters_weight#

Model.set_nn_parameters_weight(value=None, initializer='glorot_uniform', random_state=None)[source]#

Set the values of the weight in the parameterization neural network.

Parameters:
valuelist[float or numpy.ndarray] or None, default None

The list of values to set to the weights of trainable layers. If an element of the list is a numpy.ndarray, its shape must be broadcastable into the weight shape of that layer. If not used, a default or specified initialization method will be used.

initializerstr, default ‘glorot_uniform’

Weight 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.

See also

Model.nn_parameters

The weight and bias of the parameterization neural network.

Model.get_nn_parameters_weight

Get the weight 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 3 (the default value is 16, if not set)

>>> setup["hidden_neuron"] = 3
>>> model = smash.Model(setup, mesh)

Set random weights using Glorot uniform initializer

>>> model.set_nn_parameters_weight(initializer="glorot_uniform", random_state=0)
>>> model.get_nn_parameters_weight()
[array([[ 0.09038505,  0.3984533 ,  0.1902808 ,  0.08310751],
        [-0.14136384,  0.27014342, -0.11556603,  0.7254226 ],
        [ 0.8585366 , -0.21582437,  0.54016984,  0.053503  ]], dtype=float32),
array([[ 0.12599404,  0.78805184, -0.7942869 ],
        [-0.764488  , -0.8883829 ,  0.6158923 ],
        [ 0.51504624,  0.68512934,  0.886229  ],
        [ 0.55393404, -0.07132636,  0.5194391 ]], dtype=float32)]

The output contains a list of weight values for trainable layers.

Set weights with specified values

>>> import numpy as np
>>> np.random.seed(0)
>>> model.set_nn_parameters_weight([0.01, np.random.normal(size=(4,3))])
>>> model.get_nn_parameters_weight()
[array([[0.01, 0.01, 0.01, 0.01],
        [0.01, 0.01, 0.01, 0.01],
        [0.01, 0.01, 0.01, 0.01]], dtype=float32),
array([[ 1.7640524 ,  0.4001572 ,  0.978738  ],
        [ 2.2408931 ,  1.867558  , -0.9772779 ],
        [ 0.95008844, -0.1513572 , -0.10321885],
        [ 0.41059852,  0.14404356,  1.4542735 ]], dtype=float32)]