Linear¶
-
class
Linear(output_size: int, weight_initializer: bluebird.weight_initializers.WeightInitializer = <bluebird.weight_initializers.HeWeightInitializer object>, bias_initializer: bluebird.weight_initializers.WeightInitializer = <bluebird.weight_initializers.ZerosWeightInitializer object>)¶ Bases:
bluebird.layers.layer.LayerIt calculates the output based on formula:
output = input @ weights + bias
Example:
linear = Lainear(50) net = NeuralNet([ ... linear, ... ])
-
__init__(output_size: int, weight_initializer: bluebird.weight_initializers.WeightInitializer = <bluebird.weight_initializers.HeWeightInitializer object>, bias_initializer: bluebird.weight_initializers.WeightInitializer = <bluebird.weight_initializers.ZerosWeightInitializer object>) → None¶ Initializes the object.
- Parameters
output_size (int) – dimension of the output
activation (
Activation) – activation functionweight_initializer (
WeightInitializer, optional) – defines how weights are initialized, defaults to HeWeightInitializerbias_initializer (
WeightInitializer, optional) – defines how weights are initialized, defaults to ZerosWeightInitializer
Methods
__init__(output_size[, weight_initializer, …])Initializes the object.
backward(grad)Used to calculate the gradients of weights and biases.
build(input_size)Called by the model, before its training step.
forward(inputs[, training])Called each time the data passes throughout the nework.
Returns params of layer.
-
backward(grad: numpy.ndarray) → numpy.ndarray¶ Used to calculate the gradients of weights and biases.
- Parameters
grad (
Tensor) – gradient from previous layer or loss function.- Returns
Gradient
- Return type
Tensor
-
build(input_size: int) → None¶ Called by the model, before its training step.
It sets the input size and initializes the weights.
- Parameters
input_size (int) – output size from previous layer
-
forward(inputs: numpy.ndarray, training: bool = False) → numpy.ndarray¶ Called each time the data passes throughout the nework.
- Parameters
inputs (
Tensor) – output from the previous layertraining (bool, optional) – set to true during training, and is false when network predicts
- Returns
processed input data
- Return type
Tensor
-
get_params() → Dict¶ Returns params of layer.
- Returns
all params of layer
- Return type
dict
-