Hello everyone,
I go straight to the point
I'm trying to study neural networks with java, I have some questions about JOONE I hope you can help me
1) How do I IMPORT and USE through java code a .snet neural network, I mean: Once imported, how can I use it in my java code? I successfully exported the network created (XOR), but I can not properly load and use the trained network, I do not know where I make the mistake
the model considered is the XOR one.
a)ExtractTrainedNet (performs the extraction of a previously saved neural network, the network works fine, it has been tested with the editor)
b)NestedANN
(This code will take care of the trained network previously saved, INPUT data are read from a text file, the result is written to another file) the network created is:
packagexor;importjava.io.File;importjava.io.FileOutputStream;importjava.io.ObjectOutputStream;importorg.joone.engine.*;importorg.joone.engine.learning.*;importorg.joone.io.*;importorg.joone.net.NestedNeuralLayer;importorg.joone.net.NeuralNet;importorg.joone.net.NeuralNetLoader;publicclassNestedANNimplementsNeuralNetListener{publicNestedANN(){}/***@paramargs*/publicstaticvoidmain(String[]args){NestedANNnsta=newNestedANN();nsta.start_nestedNet();}publicvoidstart_nestedNet(){StringtrainedNeuralNet="C:\\Users\\...\\Desktop\\TraindeXOR.snet";/**Createthethreelayers*///InputLayer-->NestedANNLayer-->OutputLayerLinearLayerinput=newLinearLayer();//INPUTLayerNestedNeuralLayernest=newNestedNeuralLayer();//NestedNerualLayer//SigmoidLayeroutput=newSigmoidLayer();//OutputLayerLinearLayeroutput=newLinearLayer();//OUTPUTLayer/**Setlayerdimension(INPUT,NestedNeural,OUTPUT)*/input.setRows(200);//INPUTnest.setNeuralNet(trainedNeuralNet);//NestedNeuraloutput.setRows(1);//OUTPUT/**Buildtheneuralnetconnection*/SangerSynapsesynapse_IN=newSangerSynapse();/*Input->Nestedconnection*/SangerSynapsesynapse_NO=newSangerSynapse();/*Nested->Outputconnection*///ConnecttheINPUTwiththeNestedlayerinput.addOutputSynapse(synapse_IN);nest.addInputSynapse(synapse_IN);//ConnecttheNestedlayerwiththeOUTPUTlayernest.addOutputSynapse(synapse_NO);output.addInputSynapse(synapse_NO);/**DefineanINPUTforthenet*/FileInputSynapseinputStream=newFileInputSynapse();/*Thefirsttwocolumnscontaintheinputvalues*///inputStream.setAdvancedColumnSelector("1,2");inputStream.setFirstCol(1);//startCol1inputStream.setLastCol(2);//lastCol2/*Thisisthefilethatcontainstheinputdata*/inputStream.setInputFile(newFile("C:\\Users\\....\\Desktop\\testSet.txt"));//addtheinputsynapsetothefirstlayer,Theinputsynapseextendsthe//Synapseobject,soitcanbeattachedtoalayerlikeasynapseinput.addInputSynapse(inputStream);//createanoutputsynapseFileOutputSynapsefileOutput=newFileOutputSynapse();fileOutput.setFileName("C:\\Users\\...\\Desktop\\OutTestSet.txt");//attachtheoutputsynapsetothelastlayeroftheNNoutput.addOutputSynapse(fileOutput);NeuralNetnnet=newNeuralNet();nnet.addLayer(input,NeuralNet.INPUT_LAYER);nnet.addLayer(nest);nnet.addLayer(output,NeuralNet.OUTPUT_LAYER);/**Setparametersforthemonitor*/Monitormonitor=nnet.getMonitor();monitor.setLearningRate(0.7);//era0.8monitor.setMomentum(0.9);//era0.3/**Theapplicationregistersitselfasamonitor's listener, so it can receive thenotificationsofterminationfromthenet.*/monitor.addNeuralNetListener(this);//Setallthetrainingparametersofthenetmonitor.setTrainingPatterns(4);/*# of rows in the input file */monitor.setTotCicles(1);/*Howmanytimesthenetmustbetrained*/nest.setLearning(false);//Laretenondeveessereaddestratannet.getMonitor().setLearning(false);//Startthenestedneuralnetwork//nest.start();//monitor.setLearning(false);/*Thenetmustbetrained*/nnet.go();/*Thenetworkstartsthetrainingphase*///Startthenestedneuralnetworknest.start();}//MethodforrestoreneuralNetpublicNeuralNetrestoreNeuralNet(StringfileName){NeuralNetLoaderloader=newNeuralNetLoader(fileName);NeuralNetnnet=loader.getNeuralNet();returnnnet;}publicvoidnetStopped(NeuralNetEvente){System.out.println("Training finished");}publicvoidcicleTerminated(NeuralNetEvente){Monitormon=(Monitor)e.getSource();longc=mon.getCurrentCicle();/*Wewantprinttheresultsevery100epochs*/if(c%100==0){System.out.println(c+" epochs remaining - RMSE = "+mon.getGlobalError());}}publicvoidnetStarted(NeuralNetEvente){System.out.println("Training...");}publicvoiderrorChanged(NeuralNetEvente){Monitormon=(Monitor)e.getSource();/*Wewantprinttheresultsevery200cycles*/if(mon.getCurrentCicle()%200==0)System.out.println(mon.getCurrentCicle()+" epochs remaining - RMSE = "+mon.getGlobalError());}publicvoidnetStoppedError(NeuralNetEvente,Stringerror){}}
I hope I have clearly explained the problem I'm facing,
thanks for your help
Marco
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2011-06-29
Sorry, there is a copying error in this line:
/* * Set layer dimension (INPUT, NestedNeural, OUTPUT) */input.setRows(200);//INPUTnest.setNeuralNet(trainedNeuralNet);//NestedNeuraloutput.setRows(1);//OUTPUT
The correct code is:
/* * Set layer dimension (INPUT, NestedNeural, OUTPUT) */input.setRows(2);//INPUTnest.setNeuralNet(trainedNeuralNet);//NestedNeuraloutput.setRows(1);//OUTPUT
I hope that there are no other copying errors, however I think that in general the logic of the code is not correct
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello everyone,
I go straight to the point
I'm trying to study neural networks with java, I have some questions about JOONE I hope you can help me
1) How do I IMPORT and USE through java code a .snet neural network, I mean: Once imported, how can I use it in my java code? I successfully exported the network created (XOR), but I can not properly load and use the trained network, I do not know where I make the mistake
the model considered is the XOR one.
a)ExtractTrainedNet (performs the extraction of a previously saved neural network, the network works fine, it has been tested with the editor)
b)NestedANN
(This code will take care of the trained network previously saved, INPUT data are read from a text file, the result is written to another file) the network created is:
INPUT Layer (.txt) -> NestedANN (trained neurla network) -> OUTPUT Layer (.txt)
the goal is to create all alone through JAVA code
I hope I have clearly explained the problem I'm facing,
thanks for your help
Marco
Sorry, there is a copying error in this line:
The correct code is:
I hope that there are no other copying errors, however I think that in general the logic of the code is not correct