neuron

package
v0.0.0-...-f041eb8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Neuron

type Neuron struct {

	// Holds the partial derivative of error with respect to the total net input.
	// This value is only relevant for the output layer neurons.
	PdErrorWrtTotalNetInputOfOutputNeuron float64
	// contains filtered or unexported fields
}

Neuron type defines a neuron in the neural network.

func New

func New(weights []float64, bias float64, activationService *activation.Service) (*Neuron, error)

New creates a new neuron for the neural network.

func (*Neuron) Bias

func (n *Neuron) Bias() float64

Bias function returns the bias value to the neuron.

func (*Neuron) CalculateDerivativeOutputWrtTotalNetInput

func (n *Neuron) CalculateDerivativeOutputWrtTotalNetInput() float64

CalculateDerivativeOutputWrtTotalNetInput function is used by both hidden and output layer neurons. It returns the derivative (not partial derivative) of a neuron's output with respect to the total net input.

func (*Neuron) CalculateError

func (n *Neuron) CalculateError(targetOutput float64) float64

CalculateError returns the error in the last output of the neuron.

func (*Neuron) CalculateOutput

func (n *Neuron) CalculateOutput(inputs []float64) float64

CalculateOutput calculates and returns output of a neuron for given inputs.

func (*Neuron) CalculatePdErrorWrtTotalNetInputOfOutputNeuron

func (n *Neuron) CalculatePdErrorWrtTotalNetInputOfOutputNeuron(targetOutput float64) float64

CalculatePdErrorWrtTotalNetInputOfOutputNeuron function is only for output layer neurons. It returns the partial differential of output's error with respect to the total net input to the neuron. i.e. ∂Error/∂Input

By applying the chain rule, https://en.wikipedia.org/wiki/Chain_rule ∂Error/∂Input = ∂Error/∂Output * ∂Output/∂Input

func (*Neuron) CalculatePdTotalNetInputWrtWeight

func (n *Neuron) CalculatePdTotalNetInputWrtWeight(index int) float64

CalculatePdTotalNetInputWrtWeight function is used by both hidden and output layer neurons. It returns the partial derivative of total net input to a neuron with respect to one of its weight i.e. ∂TotalNetInput/∂Weight.

The total net input of a neuron is a weighted summation of all the inputs and their respective weights to the neuron plus the bias of the neuron. Total Net Input = (n Σ ᵢ = 1) ((inputᵢ * weightᵢ) + biasᵢ)

The partial derivative of the total net input with respect to the weight is the input for that particular weight since all the weighted sums and the bias are treated as constants.

func (*Neuron) Output

func (n *Neuron) Output() float64

Output function returns the last output from the neuron.

func (*Neuron) SetNewBias

func (n *Neuron) SetNewBias(value float64)

SetNewBias function updates the value of newBias of a neuron.

func (*Neuron) SetNewWeight

func (n *Neuron) SetNewWeight(value float64, index int)

SetNewWeight function updates the value in the newWeights array at the given index.

func (*Neuron) String

func (n *Neuron) String() string

func (*Neuron) UpdateWeightsAndBias

func (n *Neuron) UpdateWeightsAndBias()

UpdateWeightsAndBias function update sthe weights and bias of the neuron with the newWeights and newBias values.

func (*Neuron) Weight

func (n *Neuron) Weight(index int) float64

Weight function returns the weight to the neuron for a given index.

func (*Neuron) Weights

func (n *Neuron) Weights() []float64

Weights function returns the current set of weights to the neuron.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL