public class Net
extends java.lang.Object
Create a neural network:
Net net = new Net(new int[]{3, 4, 5});
Get the prediction for an input:
net.predict(new double[]{0.4, 0.05, 0.2});
Fit network to a single observation:
net.fit(0.1, new double[]{0.4, 0.05, 0.2}, new double[]{0.03. 0.8});
Get the JSON representation of the network:
net.json();
Constructor and Description |
---|
Net(int[] layerSizes)
Creates a random neural network.
|
Net(int[] layerSizes,
java.util.function.IntFunction<Fun> activationF,
java.util.function.IntFunction<java.lang.Double> weightInitF)
Creates a neural network.
|
Net(int[] layerSizes,
java.lang.Long seed)
Creates a non-random neural network.
|
Net(java.lang.String json)
Cretaes a neural network by parsing its JSON representation.
|
Modifier and Type | Method and Description |
---|---|
double[] |
errors(double[] inputValues,
double[] expectedOutput,
boolean inParallel) |
void |
fit(double learningRate,
double[] inputValues,
double[] expectedOutput)
Adjust the weights of the neural network to the provided observation.
|
void |
fitPar(double learningRate,
double[] inputValues,
double[] expectedOutput)
Adjust the weights of the neural network to the provided observation.
|
java.lang.String |
json()
The JSON representation of the neural network.
|
double[] |
parPredict(double[] inputValues)
Makes a prediction for the provided input.
|
double[] |
predict(double[] inputValues)
Makes a prediction for the provided input.
|
java.lang.String |
svg()
An SVG representation of the neural network.
|
public Net(int[] layerSizes, java.util.function.IntFunction<Fun> activationF, java.util.function.IntFunction<java.lang.Double> weightInitF)
layerSizes
- The size of each layer.activationF
- A function that accepts the index of a layer and returns an activation function for its neurons.weightInitF
- A function that accepts the index of a layer and returns a weight for the synapses of its neurons.public Net(int[] layerSizes)
The activation function of all neurons is sigmoid. The weight distribution of the synapses is normal between -1.0 and 1.0.
layerSizes
- The size of each layer.
The first number in the list defines the size of the input layer.
The last number in the list defines the size of the output layer.
In order for a neural network to be deep, the list should contain more than two numbers.public Net(int[] layerSizes, java.lang.Long seed)
Calling this function with the same parameters multiple times, should always return the same neural network. The activation function of the nodes is sigmoid. The weight distribution of the synapses is normal between -1.0 and 1.0.
layerSizes
- The size of each layer.seed
- A number used to initialize the internal pseudorandom number generator.public Net(java.lang.String json)
json
- The JSON representation of a neural network.public double[] predict(double[] inputValues)
inputValues
- The values of the features. Their size should be equal to the size of the input layer.public double[] parPredict(double[] inputValues)
The calculation is performed in parallel. When the neural network has huge layers, the parallel calculation boosts the performance.
inputValues
- The values of the features. Their size should be equal to the size of the input layer.public double[] errors(double[] inputValues, double[] expectedOutput, boolean inParallel)
public void fit(double learningRate, double[] inputValues, double[] expectedOutput)
In order for it to be trained, it should fit with multiple observations.
learningRate
- A number that controls how much the weights are adjusted to the observation.inputValues
- The feature values of the observation.expectedOutput
- The expected output of the observation.
It's size should be equal to the size of the output layer.public void fitPar(double learningRate, double[] inputValues, double[] expectedOutput)
The calculation is performed in parallel. When the neural network has huge layers, the parallel calculation boosts the performance.
learningRate
- A number that controls how much the weights are adjusted to the observation.inputValues
- The feature values of the observation.expectedOutput
- The expected output of the observation.
It's size should be equal to the size of the output layer.public java.lang.String json()
public java.lang.String svg()