smash.factory.Net.set_bias#

Net.set_bias(value=None, random_state=None)[source]#

Set the values of the bias in the neural network Net.

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

The list of values to set to the biases of all 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, initialization methods defined in trainable layers will be used with a random or specified seed depending on random_state.

random_stateint or None, default None

Random seed used for the initialization method defined in each trainable layer. Only used if value is not set.

Note

If not given, the parameters will be initialized with a random seed.

See also

Net.get_bias

Get the biases of the trainable layers of the neural network Net.

Examples

>>> from smash.factory import Net
>>> net = Net()
>>> net.add_dense(4, input_shape=3, activation="tanh")
>>> net.add_dense(2, bias_initializer="he_normal")
>>> net
+-------------------------------------------------------+
| Layer Type         Input/Output Shape  Num Parameters |
+-------------------------------------------------------+
| Dense              (3,)/(4,)           16             |
| Activation (TanH)  (4,)/(4,)           0              |
| Dense              (4,)/(2,)           10             |
+-------------------------------------------------------+
Total parameters: 26
Trainable parameters: 26

Set biases with specified values

>>> net.set_bias([1.2, 1.3])

Get the bias values

>>> net.get_bias()
[array([[1.2, 1.2, 1.2, 1.2]]), array([[1.3, 1.3]])]

Set random biases

>>> net.set_bias(random_state=0)
>>> net.get_bias()  # default bias initializer is zeros
[array([[0., 0., 0., 0.]]), array([[2.49474675, 0.56590775]])]