Reputation: 464
I have a neural network created using the neuroph java framework. The network has 2 input neurons, 1 output, and 2 hidden layers with 8 neurons. And I'm trying to create a simple network to test.
ds.addRow(new DataSetRow(new double[] {0.1, 0.1}, new double[] {0.1}));
ds.addRow(new DataSetRow(new double[] {0.2, 0.2}, new double[] {0.2}));
ds.addRow(new DataSetRow(new double[] {0.3, 0.3}, new double[] {0.3}));
ds.addRow(new DataSetRow(new double[] {0.4, 0.4}, new double[] {0.4}));
ds.addRow(new DataSetRow(new double[] {0.5, 0.5}, new double[] {0.5}));
ds.addRow(new DataSetRow(new double[] {0.6, 0.6}, new double[] {0.6}));
ds.addRow(new DataSetRow(new double[] {0.7, 0.7}, new double[] {0.7}));
ds.addRow(new DataSetRow(new double[] {0.8, 0.8}, new double[] {0.8}));
ds.addRow(new DataSetRow(new double[] {0.9, 0.9}, new double[] {0.9}));
ds.addRow(new DataSetRow(new double[] {1.0, 1.0}, new double[] {1.0}));
BackPropagation backPropagation = new BackPropagation();
backPropagation.setMaxIterations(100000);
backPropagation.setMaxError(0.0075);
backPropagation.setMomentum(0.10);
backPropagation.setLearningRate(0.30);
As you can see from the code, it's a pretty straightforward network, where the first set of doubles is the input, and the last one is the correct output, so that the inputs 0.3, 0.3 should give 0.3 etc. However, when running it, and after training it, when I enter different inputs, I either get a 0.0 or 1.0 (mostly 1.0, when it's 0.0, 0.0 I get 0 returned)? Why is that? Why nothing in between.
Upvotes: 0
Views: 53
Reputation: 464
Problem was that the neural network I was using here is a simple Perceptron network, which is a great network for supervised learning and a linear classifier meaning that it will only output 1's or 0's. For this use case, a Multi Layer Perceptron is a better network to use as it can gives an output between 0 & 1.
Here's an example in code using the Neuroph Java Framework.
MultiLayerPerceptron ann = new MultiLayerPerceptron(TransferFunctionType.LINEAR, 1, 3, 1);
ann.learn(ds);
where 1 is the number of neurons of the input layer, 3 neurons for the hidden layer & the last 1 is the number of neurons in the output layer. And then simply add the dataset into the network to learn.
Upvotes: 1