Package libai.nn.supervised
Class Perceptron
- java.lang.Object
-
- libai.nn.NeuralNetwork
-
- libai.nn.supervised.SupervisedLearning
-
- libai.nn.supervised.Perceptron
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
Adaline
public class Perceptron extends SupervisedLearning
Perceptron is the first trainable neural network proposed. The network is formed by one matrix (Weights) and one vector (Bias). The output for the network is calculated by O = sign(W * pattern + b).- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Perceptron(int in, int out)
Constructor.Perceptron(int in, int out, java.util.Random rand)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Matrix
getWeights()
Column
simulate(Column p)
Calculates the output for thepattern
.void
simulate(Column pattern, Column result)
Calculate the output for the pattern and left the result on result.void
train(Column[] patterns, Column[] answers, double alpha, int epochs, int offset, int length, double minerror)
Train the perceptron using the standard update rule:
W = W + alpha.e.pattern^t
b = b + alpha.e-
Methods inherited from class libai.nn.NeuralNetwork
error, error, euclideanDistance2, euclideanDistance2, gaussian, getDefaultRandomGenerator, getPlotter, getProgressBar, initializeProgressBar, open, open, open, save, setPlotter, setProgressBar, train, train
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from class libai.nn.supervised.SupervisedLearning
validatePreconditions
-
-
-
-
Constructor Detail
-
Perceptron
public Perceptron(int in, int out)
Constructor.- Parameters:
in
- Number of inputs for the network = number of elements in the patterns.out
- Number of outputs for the network.
-
Perceptron
public Perceptron(int in, int out, java.util.Random rand)
Constructor.- Parameters:
in
- Number of inputs for the network = number of elements in the patterns.out
- Number of outputs for the network.rand
- Random generator used for creating matrices
-
-
Method Detail
-
train
public void train(Column[] patterns, Column[] answers, double alpha, int epochs, int offset, int length, double minerror)
Train the perceptron using the standard update rule:
W = W + alpha.e.pattern^t
b = b + alpha.e- Specified by:
train
in classNeuralNetwork
- Parameters:
patterns
- The patterns to be learned.answers
- The expected answers.alpha
- The learning rate.epochs
- The maximum number of iterationsoffset
- The first pattern positionlength
- How many patterns will be used.minerror
- The minimal error expected.
-
simulate
public Column simulate(Column p)
Description copied from class:NeuralNetwork
Calculates the output for thepattern
.- Specified by:
simulate
in classNeuralNetwork
- Parameters:
p
- Pattern to use as input.- Returns:
- The output for the neural network.
-
simulate
public void simulate(Column pattern, Column result)
Calculate the output for the pattern and left the result on result. result = signum(W * pattern + b)- Specified by:
simulate
in classNeuralNetwork
- Parameters:
pattern
- The input patternresult
- The output result.
-
getWeights
public Matrix getWeights()
-
-