trainer.java

来自「利用JAVA分别实现了神经网络和遗传算法并对XOR问题给出了两者的比较」· Java 代码 · 共 107 行

JAVA
107
字号
/*	Copyright 2006, 2007 Brian Greer	This file is part of the Java NN Trainer.	Java NN Trainer is free software; you can redistribute it and/or modify	it under the terms of the GNU General Public License as published by	the Free Software Foundation; either version 2 of the License, or	(at your option) any later version.	Java NN Trainer is distributed in the hope that it will be useful,	but WITHOUT ANY WARRANTY; without even the implied warranty of	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the	GNU General Public License for more details.	You should have received a copy of the GNU General Public License	along with Java NN Trainer; if not, write to the Free Software	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA*/package algorithms;import java.util.Vector;import java.util.Random;public abstract class Trainer extends Thread{	public static final int NONE = 0;	public static final int BACKPROP = 1;	public static final int QUICKPROP = 2;	public static final int GA = 3;	public static final int PSO = 4;	int numGenerations;	int numPatterns;	int numInput, numHidden, numOutput;	double [][] inputs;	double [][] targets;	double minError;	boolean isRunning = false;	Vector trainerListeners = new Vector();	Random random = new Random(System.currentTimeMillis());	public Trainer(int numHidden, double [][] inputs, double [][] targets, double minError){		numGenerations = 0;		numPatterns = inputs.length;		if(numPatterns > 0){			numInput = inputs[0].length;			this.numHidden = numHidden;			numOutput = targets[0].length;			this.inputs = inputs;			this.targets = targets;			this.minError = minError;		}		else			throw (new NullPointerException("No Patterns Supplied"));	}	public void kill(){		isRunning = false;	}	public abstract void run();	public void addTrainerListener(TrainerListener listener){		trainerListeners.addElement(listener);	}	public void broadcastBegin(){		isRunning = true;		int numListeners = trainerListeners.size();		for(int i = 0; i < numListeners; i++)			((TrainerListener)trainerListeners.elementAt(i)).trainingBegin(this);	}	public void broadcastEnd(){		isRunning = false;		int numListeners = trainerListeners.size();		for(int i = 0; i < numListeners; i++)			((TrainerListener)trainerListeners.elementAt(i)).trainingEnd(this);	}	public void broadcastGenerationComplete(NeuralNetwork nn){		int numListeners = trainerListeners.size();		for(int i = 0; i < numListeners; i++)			((TrainerListener)trainerListeners.elementAt(i)).trainingGenerationComplete(nn, this);	}	public int getNumGenerations(){		return numGenerations;	}	public abstract int getType();}// vim:noet:ts=3:sw=3

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?