this class is responsible for creating a layer of neurons.
example usage
this example demonstrates three ways to instantiate the class.
example1 is creating a Layer with 8 neurons.
example2, on the other hand, is creating a Layer with 2 neurons and defining their weights.
while example3 is creating a Layer with 2 neurons of the same weights, but correcting the bias of both.
example usage
this example creates a layer containing 2 neurons with weights already defined and displays the value of the weights property.
example usage
this example creates a layer containing 2 neurons with weights and bias to display the bias value in the console.
example usage
this example creates a layer containing 5 neurons that displays the result of the calculate method as output.
example usage
this example clearly shows how the calculation method takes as an argument an array of inputs and the activation function ReLU.
return
this method returns a numerical array as output calculated by the layer's neurons.
example usage
this example creates a layer containing 2 neurons and passes the numeric array 2D weights of each neuron as an argument.
example usage
this example creates a layer containing 3 neurons and passes a numerical array argument as a bias for the layer's neurons.
Detailed information
see detailed examples of each of the references.
# Layer : Class
const example1 = new Layer(8)
const weights = [
[100, 1, 5],
[-200, 5, 10]
]
const example2 = new Layer(2, weights)
const bias = [0, 3]
const example3 = new Layer(2, weights, bias)
example usage
this example demonstrates three ways to instantiate the class.
example1 is creating a Layer with 8 neurons.
example2, on the other hand, is creating a Layer with 2 neurons and defining their weights.
while example3 is creating a Layer with 2 neurons of the same weights, but correcting the bias of both.
description
Layer is a class that creates a set of internal neurons.
constructor
weights : Array 2D [Number]
bias : Array [Number]
# weights : Property
const example = new Layer(2, [[100, 1, 5], [-200, 5, 10]])
console.log(example.weights)
example usage
this example creates a layer containing 2 neurons with weights already defined and displays the value of the weights property.
description
weights is a property that contains all the weights of all neurons grouped in a numerical array 2D.
return
weights : Array 2D [Number]
# bias : Property
const example = new Layer(2, [[100, 1, 5], [-200, 5, 10]], [0, 3])
console.log(example.bias)
example usage
this example creates a layer containing 2 neurons with weights and bias to display the bias value in the console.
description
bias is a property that returns a numerical matrix used in the neurons of the layer.
return
bias : Array [Number]
# outputs : Property
const example = new Layer(5)
// calculate...
console.log(example.outputs)
example usage
this example creates a layer containing 5 neurons that displays the result of the calculate method as output.
description
outputs is a property that returns a numerical array with the result of the calculation made through the neurons of the layer.
return
outputs : Array [Number]
# calculate : Method
const example = new Layer(7)
const inputs = [200, 15, 8]
const outputs = example.calculate(inputs, ReLU)
console.log(outputs)
example usage
this example clearly shows how the calculation method takes as an argument an array of inputs and the activation function ReLU.
return
this method returns a numerical array as output calculated by the layer's neurons.
description
calculate is a method used to calculate an array of inputs according to the layer's neuron configuration and return an output using an activation function.
parameters
inputs : Array
callback : Function
# setWeights : Method
const example = new Layer(2)
const weights = [
[100, 1, 5],
[-200, 5, 10]
]
example.setWeights(weights)
example usage
this example creates a layer containing 2 neurons and passes the numeric array 2D weights of each neuron as an argument.
description
setWeights is a method used by inserting a numerical array 2D as arguments to define the weights of each neuron.
parameters
weights : Array 2D [Number]
# setBias : Method
const example = new Layer(3)
const bias = [7, 0, 5]
example.setBias(bias)
example usage
this example creates a layer containing 3 neurons and passes a numerical array argument as a bias for the layer's neurons.
description
setBias is a method that receives a numerical array to reset the bias of the neurons in the layer.
parameters
bias : Array [Number]