本文整理汇总了Java中org.encog.neural.networks.BasicNetwork.compute方法的典型用法代码示例。如果您正苦于以下问题:Java BasicNetwork.compute方法的具体用法?Java BasicNetwork.compute怎么用?Java BasicNetwork.compute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.encog.neural.networks.BasicNetwork
的用法示例。
在下文中一共展示了BasicNetwork.compute方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getError
import org.encog.neural.networks.BasicNetwork; //导入方法依赖的package包/类
private double[] getError(NeuralDataSet trainingSet, BasicNetwork network){
double total = 0.0;
double size = 0;
double RSS = 0.0;
double Ry = 0.0;
for (MLDataPair pair : trainingSet) {
final MLData output = network.compute(pair.getInput());
if (Double.isNaN(output.getData(0))) {
throw new RuntimeException("There is a NaN! may be something wrong with the data conversion");
}
double result = (Double.isNaN(output.getData(0)))? pair.getIdeal().getData(0) : output.getData(0);
//System.out.print("Result ********** " +result+"\n");
total += calculateEachMAPE(pair.getIdeal().getData(0),
result);
double difference = pair.getIdeal().getData(0) - result;
RSS += Math.pow(difference, 2);
Ry += Math.pow(pair.getIdeal().getData(0) - meanIdeal, 2);
size++;
}
return new double[]{Ry==0?RSS:RSS/Ry,
total/size};
}
示例2: enquireNeuralNetwork
import org.encog.neural.networks.BasicNetwork; //导入方法依赖的package包/类
public int enquireNeuralNetwork(final BasicNetwork neuralNetwork, DataPoint dataPoint) {
MLData input = new BasicMLData(2);
input.setData(0, dataPoint.getX());
input.setData(1, dataPoint.getY());
MLData output = neuralNetwork.compute(input);
// Check to see which button has the highest output
double buttons[] = output.getData();
int buttonIndex = -1;
for (int i = 0; i < buttons.length; i++) {
if (buttons[i] > 0 && (buttonIndex == -1 || buttons[i] > buttons[buttonIndex])) {
buttonIndex = i;
}
}
return buttonIndex;
}
示例3: main
import org.encog.neural.networks.BasicNetwork; //导入方法依赖的package包/类
/**
* The main method.
* @param args No arguments are used.
*/
public static void main(final String args[]) {
// create a neural network, without using a factory
BasicNetwork network = new BasicNetwork();
network.addLayer(new BasicLayer(null,true,2));
network.addLayer(new BasicLayer(new ActivationSigmoid(),true,3));
network.addLayer(new BasicLayer(new ActivationSigmoid(),false,1));
network.getStructure().finalizeStructure();
network.reset();
// create training data
MLDataSet trainingSet = new BasicMLDataSet(XOR_INPUT, XOR_IDEAL);
// train the neural network
final ResilientPropagation train = new ResilientPropagation(network, trainingSet);
int epoch = 1;
do {
train.iteration();
System.out.println("Epoch #" + epoch + " Error:" + train.getError());
epoch++;
} while(train.getError() > 0.01);
train.finishTraining();
// test the neural network
System.out.println("Neural Network Results:");
for(MLDataPair pair: trainingSet ) {
final MLData output = network.compute(pair.getInput());
System.out.println(pair.getInput().getData(0) + "," + pair.getInput().getData(1)
+ ", actual=" + output.getData(0) + ",ideal=" + pair.getIdeal().getData(0));
}
Encog.getInstance().shutdown();
}
示例4: main
import org.encog.neural.networks.BasicNetwork; //导入方法依赖的package包/类
/**
* The main method.
* @param args No arguments are used.
*/
public static void main(final String args[]) {
// create a neural network, without using a factory
BasicNetwork network = new BasicNetwork();
network.addLayer(new BasicLayer(null,true,2));
network.addLayer(new BasicLayer(new ActivationSigmoid(),true,3));
network.addLayer(new BasicLayer(new ActivationSigmoid(),false,1));
network.getStructure().finalizeStructure();
network.reset();
// create training data
MLDataSet trainingSet = new BasicMLDataSet(XOR_INPUT, XOR_IDEAL);
// train the neural network
final ResilientPropagation train = new ResilientPropagation(network, trainingSet);
int epoch = 1;
do {
train.iteration();
System.out.println("Epoch #" + epoch + " Error:" + train.getError());
epoch++;
} while(train.getError() > 0.01);
train.finishTraining();
// test the neural network
System.out.println("Neural Network Results:");
for(MLDataPair pair: trainingSet ) {
final MLData output = network.compute(pair.getInput());
System.out.println(pair.getInput().getData(0) + "," + pair.getInput().getData(1)
+ ", actual=" + output.getData(0) + ",ideal=" + pair.getIdeal().getData(0));
}
Encog.getInstance().shutdown();
}
示例5: test
import org.encog.neural.networks.BasicNetwork; //导入方法依赖的package包/类
public static void test(double[][] inputValues, double[][] outputValues)
{
NeuralDataSet trainingSet = new BasicNeuralDataSet(inputValues, outputValues);
BasicNetwork network = new BasicNetwork();
network.addLayer(new BasicLayer(new ActivationSigmoid(), false, 4));
network.addLayer(new BasicLayer(new ActivationSigmoid(), false, 1000));
network.addLayer(new BasicLayer(new ActivationLinear(), false, 1));
network.getStructure().finalizeStructure();
network.reset();
final Train train = new ResilientPropagation(network, trainingSet);
int epoch = 1;
do
{
train.iteration();
System.out.println("Epoch #" + epoch + " Error:" + train.getError());
epoch++;
}
while(epoch < 10000);
System.out.println("Neural Network Results:");
for(MLDataPair pair : trainingSet)
{
final MLData output = network.compute(pair.getInput());
System.out.println(pair.getInput().getData(0) + "," + pair.getInput().getData(1) + ", actual="
+ output.getData(0) + ",ideal=" + pair.getIdeal().getData(0));
}
}