Neuroph is a open source Framework includes many classes of algorithms known neural network. We've talked about this Framework on occasion. All documentation for the API and even examples can be found in the page of them:
http://neuroph.sourceforge.net/index.html In this post, just one example with the algorithm Momentum "Backpropagation Neuroph provided to solve the XOR problem. To say that most source is based on the examples of the project page, simply modified the learning algorithm of the network. It is not very complicated. ________________________________________________________________
| / / Author: Juan Jose Fumero Alfonso |
import org. neuroph.core.NeuralNetwork;
org.neuroph.nnet.MultiLayerPerceptron import, import
org.neuroph.core.learning.TrainingElement;
| org.neuroph.core.learning.SupervisedTrainingElement; |
org.neuroph.nnet.learning.MomentumBackpropagation;
import
| import org.neuroph.util.TransferFunctionType; |
class XorBackPropagation {
public
static
| void |
String
[] args) { | new | TrainingSet
trainingSet.
addElement (
new
SupervisedTrainingElement (
| double []{ |
0 ,
}, new
- double
- []{ 1
}));
trainingSet. addElement
( new
SupervisedTrainingElement ( new double, 0 }, new double []{ 1 })); trainingSet. addElement ( new SupervisedTrainingElement ( new double []{ 1 , 1 }, new double
[]{ 1[]{ 0 }));
// create multi layer perceptron MultiLayerPerceptron myMlPerceptron = new MultiLayerPerceptron (TransferFunctionType. TANH , 2
,
3 , 1 );
//Create Backpropagation with momentum MomentumBackpropagation mb =
new MomentumBackpropagation (myMlPerceptron); //Properties to MomentumBackpropagation mb. setMomentum ( 0.85 );
mb.
setMaxError ( 0.0001 ); mb.
setMaxIterations ( 1000 ); //Learn long t1, t2; t1 =
System . currentTimeMillis ();
mb. learn (trainingSet); t2 = System . currentTimeMillis (); System.
out. println ( "Training time"
+ (t2-t1) + "milliseconds" ) / / Get net NeuralNetwork nn = mb. getNeuralNetwork (); / / Display the results
for (TrainingElement trainingElement: trainingSet. training element
()) {
nn. setInput (trainingElement. getInput ()); nn. calculate ();
Vector
\u0026lt; Double
> NetworkManager output = nn.
getOutput ();
System . out
. print ( "Input:" + training element.
getInput ()); System
. out . println ( "Output:" +
networkOutput); }
System .
exit ( 0);}
} ________________________________________________________________
0 comments:
Post a Comment