Documentation ¶
Overview ¶
Package perceptron provides the ability to create, train and use a linear classifier which takes a number of inputs and returns a single output.
A Perceptron has a set of input weights and an activation threshold.
For a given set of inputs i1...in, the activity is calculated as
sum(i * w)
where w1...wn are weights for the inputs. The output is 1 if the activity > threshold, else 0.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Perceptron ¶
func New ¶
func New(numInputs int) *Perceptron
New creates a new Perceptron with the specified number of inputs. It assigns random weights to each of the inputs and generates a random activation threshold for the Perceptron.
func (*Perceptron) Activates ¶
func (p *Perceptron) Activates(input []int) int
Activates checks if the Perceptron activates for the given input. It returns 0 or 1 depending on the input and how the perceptron has been trained.
func (*Perceptron) Activity ¶
func (p *Perceptron) Activity(input []int) float64
Activity calculates the activity on the Perceptron for a given input. It doesn't calculate if the Perceptron actually fires, see "Activates" instead.
func (*Perceptron) Train ¶
func (p *Perceptron) Train(input []int, expectedOutput int)
Train takes a given input and an expected output. If the Perceptron doesn't activate, it adjusts the activation threshold and input weights based on the delta between the expected and calculated output.