?? trainer.java
字號:
/* 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 + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -