📄 example3.java
字号:
package neuralNetwork;
/*
Coded by Aydin Gurel, 2003
The code is free, but please contact me if you wish to use the code entirely or partially in any kind of project so that I can reference it and please don't delete these lines so that other people can reach this information. Also, please inform me if you encounter a bug.
aydingurel@hotmail.com
http://aydingurel.brinkster.com/neural
The purpose of this example is to show you how this package should be used, rather than to give you clues about how to train and use a neural network in general.
In this example, we:
-create a multilayer perceptron,
-create random input values,
-calculate target as sin ( x1 + x2 )
-train the net with these values without using pattern sets,
-test it
*/
import java.io.*;
public class example3 {
public static void main(String args[]) {
Randomizer randomizer = new Randomizer();
// create a multilayer perceptron with three layers:
// one input layer with two units; one hidden layer
// with three neurons, using tanh function;
// one output layer with one neuron using linear function.
// except for noofneurons, all parameters for the input layer
// are ineffectual.
int[] noofneurons = {2,3,1};
double[] learnratecoeff = {1, 1, 1};
char[] axonfamily = {'t', 't', 'l'};
double[] momentumrate = {0, .4, .4};
double[] flatness = {1, 1, 1};
System.out.println("Creating the net");
NeuralNet mynet = new NeuralNet(noofneurons, learnratecoeff, axonfamily, momentumrate, flatness, randomizer);
// train the net using incremental training
System.out.println("Beginning incremental training");
Pattern pattern;
double[] inputs = new double[2];
double[] outputs = new double[1];
for (int i = 0; i < 3000; i++) {
inputs[0] = randomizer.Uniform(-1,1);
inputs[1] = randomizer.Uniform(-1,1);
outputs[0] = Math.sin(inputs[0] + inputs[1]);
pattern = new Pattern(inputs, outputs);
mynet.IncrementalTrain(.2, pattern);
}
System.out.println("Training is over");
// test it
inputs[0] = -0.5;
inputs[1] = 0.3;
System.out.println("Feeding the net");
outputs = mynet.Output(inputs);
System.out.println("Sin ( -0.5 + 0.3 ) = "+outputs[0]);
mynet = null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -