Neuroph无法训练集

时间:2016-08-04 12:44:01

标签: java neural-network

我一直在努力训练网络,但我无法做到。 Neuroph Studio根本没有帮助,它在训练时总是返回null。 然后我在Java应用程序中尝试了这段代码:

// create new perceptron network
NeuralNetwork neuralNetwork = new Perceptron(2, 1);

// create training set
DataSet trainingSet = new DataSet(2, 1);

// add training data to training set (logical OR function)
trainingSet.addRow(new DataSetRow(new double[]{0, 0}, new double[]{0.5d}));
trainingSet.addRow(new DataSetRow(new double[]{0, 1}, new double[]{1}));
trainingSet.addRow(new DataSetRow(new double[]{1, 0}, new double[]{1}));
trainingSet.addRow(new DataSetRow(new double[]{1, 1}, new double[]{1}));

// learn the training set
neuralNetwork.learn(trainingSet);

// save the trained network into file
neuralNetwork.save("or_perceptron.nnet");

// load the saved network
neuralNetwork = NeuralNetwork.createFromFile("or_perceptron.nnet");

// set network input
neuralNetwork.setInput(1, 1);

// calculate network
neuralNetwork.calculate();

// get network output
double[] networkOutput = neuralNetwork.getOutput();
for (double res : networkOutput) {
    System.out.println(res);
}

这有效,但我想训练这样的事情:

输入:0.30.5
输出:0.2

它一直在训练,神经病有什么问题,或者它根本不起作用?

1 个答案:

答案 0 :(得分:0)

最后,唯一有效的方法是从外部文件加载训练集。也许还有另一种解决方案,但这是我最后唯一有用的方法。