JOONE 인공지능 인 스 턴 스 구현
package com.sweetop.test;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Vector;
import org.joone.engine.FullSynapse;
import org.joone.engine.LinearLayer;
import org.joone.engine.Monitor;
import org.joone.engine.NeuralNetEvent;
import org.joone.engine.NeuralNetListener;
import org.joone.engine.Pattern;
import org.joone.engine.SigmoidLayer;
import org.joone.engine.learning.TeachingSynapse;
import org.joone.io.FileInputSynapse;
import org.joone.io.FileOutputSynapse;
import org.joone.io.MemoryInputSynapse;
import org.joone.io.MemoryOutputSynapse;
import org.joone.net.NeuralNet;
public class Test implements NeuralNetListener,Serializable {
/**
*
*/
private static final long serialVersionUID = 61750666816215273L;
private NeuralNet nnet = null;
private MemoryInputSynapse inputSynapse, desiredOutputSynapse;
private MemoryOutputSynapse outputSynapse;
// XOR input
private double[][] inputArray = new double[][] { { 1.0, 1.0 },
{ 1.0, 2.0 }, { 2.0, 2.0 }, { 2.0, 3.0 }, { 1.0, 3.0 } };
// XOR desired output
private double[][] desiredOutputArray = new double[][] { { 2.0/10 },
{ 3.0/10 }, { 4.0/10 }, { 5.0/10 }, { 4.0/10 } };
protected void initNeuralNet() {
// First create the three layers
LinearLayer input = new LinearLayer();
SigmoidLayer hidden = new SigmoidLayer();
SigmoidLayer output = new SigmoidLayer();
input.setLayerName("input");
hidden.setLayerName("hidden");
output.setLayerName("output");
// set the dimensions of the layers
input.setRows(2);
hidden.setRows(3);
output.setRows(1);
// Now create the two Synapses
FullSynapse synapse_IH = new FullSynapse(); /* input -> hidden conn. */
FullSynapse synapse_HO = new FullSynapse(); /* hidden -> output conn. */
// Connect the input layer whit the hidden layer
input.addOutputSynapse(synapse_IH);
hidden.addInputSynapse(synapse_IH);
// Connect the hidden layer whit the output layer
hidden.addOutputSynapse(synapse_HO);
output.addInputSynapse(synapse_HO);
// the input to the neural net
inputSynapse = new MemoryInputSynapse();
input.addInputSynapse(inputSynapse);
// the output of the neural net
outputSynapse = new MemoryOutputSynapse();
output.addOutputSynapse(outputSynapse);
// The Trainer and its desired output
desiredOutputSynapse = new MemoryInputSynapse();
TeachingSynapse trainer = new TeachingSynapse();
trainer.setDesired(desiredOutputSynapse);
nnet = new NeuralNet();
nnet.addLayer(input, NeuralNet.INPUT_LAYER);
nnet.addLayer(hidden, NeuralNet.HIDDEN_LAYER);
nnet.addLayer(output, NeuralNet.OUTPUT_LAYER);
nnet.setTeacher(trainer);
output.addOutputSynapse(trainer);
train();
//File
}
public void test(double[][] d){
inputSynapse.setInputArray(d);
inputSynapse.setAdvancedColumnSelector("1,2");
nnet.getMonitor().setTotCicles(1);
nnet.start();
nnet.getMonitor().Go();
for (Object o : outputSynapse.getAllPatterns()) {
Pattern p = (Pattern) o;
System.out.println(10*p.getArray()[0]);
}
}
public void train() {
// set the inputs
inputSynapse.setInputArray(inputArray);
inputSynapse.setAdvancedColumnSelector("1,2");
// set the desired outputs
desiredOutputSynapse.setInputArray(desiredOutputArray);
desiredOutputSynapse.setAdvancedColumnSelector("1");
// get the monitor object to train or feed forward
Monitor monitor = nnet.getMonitor();
// set the monitor parameters
monitor.setLearningRate(0.8);
monitor.setMomentum(0.3);
monitor.setTrainingPatterns(inputArray.length);
monitor.setTotCicles(100000);
monitor.setLearning(true);
nnet.addNeuralNetListener(this);
nnet.start();
nnet.getMonitor().Go();
for (Object o : outputSynapse.getAllPatterns()) {
Pattern p = (Pattern) o;
System.out.println(10*p.getArray()[0]);
}
}
public void cicleTerminated(NeuralNetEvent e) {
}
public void errorChanged(NeuralNetEvent e) {
}
public void netStarted(NeuralNetEvent e) {
// TODO Auto-generated method stub
}
public void netStopped(NeuralNetEvent e) {
// TODO Auto-generated method stub
}
public void netStoppedError(NeuralNetEvent e, String error) {
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.