I am trying to train an xor network with deeplearning4j, but I think I really did not understand how to use the dataset.
I wanted to create an NN with two inputs, two hidden neurons and one output neuron.
here is what i have:
package org.deeplearning4j.examples.xor; import org.deeplearning4j.eval.Evaluation; import org.deeplearning4j.nn.api.Layer; import org.deeplearning4j.nn.api.OptimizationAlgorithm; import org.deeplearning4j.nn.conf.MultiLayerConfiguration; import org.deeplearning4j.nn.conf.NeuralNetConfiguration; import org.deeplearning4j.nn.conf.Updater; import org.deeplearning4j.nn.conf.distribution.UniformDistribution; import org.deeplearning4j.nn.conf.layers.GravesLSTM; import org.deeplearning4j.nn.conf.layers.RnnOutputLayer; import org.deeplearning4j.nn.multilayer.MultiLayerNetwork; import org.deeplearning4j.nn.weights.WeightInit; import org.deeplearning4j.optimize.listeners.ScoreIterationListener; import org.nd4j.linalg.api.ndarray.INDArray; import org.nd4j.linalg.dataset.DataSet; import org.nd4j.linalg.factory.Nd4j; import org.nd4j.linalg.lossfunctions.LossFunctions.LossFunction; public class XorExample { public static void main(String[] args) { INDArray input = Nd4j.zeros(4, 2); INDArray labels = Nd4j.zeros(4, 1); input.putScalar(new int[] { 0, 0 }, 0); input.putScalar(new int[] { 0, 1 }, 0); input.putScalar(new int[] { 1, 0 }, 1); input.putScalar(new int[] { 1, 1 }, 0); input.putScalar(new int[] { 2, 0 }, 0); input.putScalar(new int[] { 2, 1 }, 1); input.putScalar(new int[] { 3, 0 }, 1); input.putScalar(new int[] { 3, 1 }, 1); labels.putScalar(new int[] { 0, 0 }, 0); labels.putScalar(new int[] { 1, 0 }, 1); labels.putScalar(new int[] { 2, 0 }, 1); labels.putScalar(new int[] { 3, 0 }, 0); DataSet ds = new DataSet(input,labels);
the output looks like this:
Mรคr 20, 2016 7:03:06 PM com.github.fommil.jni.JniLoader liberalLoad INFORMATION: successfully loaded C:\Users\LuckyPC\AppData\Local\Temp\jniloader5209513403648831212netlib-native_system-win-x86_64.dll Number of parameters in layer 0: 46 Number of parameters in layer 1: 3 Total number of network parameters: 49 odosBaseOptimizer - Objective function automatically set to minimize. Set stepFunction in neural net configuration to change default settings. odolScoreIterationListener - Score at iteration 0 is 0.6931495070457458 Exception in thread "main" java.lang.IllegalArgumentException: Unable to getFloat row of non 2d matrix at org.nd4j.linalg.api.ndarray.BaseNDArray.getRow(BaseNDArray.java:3640) at org.deeplearning4j.eval.Evaluation.eval(Evaluation.java:107) at org.deeplearning4j.examples.xor.XorExample.main(XorExample.java:80)
source share