📄 testmodel.java
字号:
/* * TestModel.java 1.0 21 Jun 2004 * * NeuralNetworkToolkit * Copyright (C) 2004 Universidade de Bras�lia * * This file is part of NeuralNetworkToolkit. * * NeuralNetworkToolkit 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. * * NeuralNetworkToolkit 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 NeuralNetworkToolkit; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 - USA. */package neuralnetworktoolkit.tests;import java.io.*;import neuralnetworktoolkit.datamanager.textfilemanager.*;import neuralnetworktoolkit.math.*;import neuralnetworktoolkit.modelstorage.*;import neuralnetworktoolkit.neuralnetwork.INeuralNetwork;/** * Provides a easy mechanism to test models. * * @version 1.0 21 Jun 2004 * * @author <a href="mailto:hugoiver@yahoo.com.br">Hugo Iver V. Gon�alves</a> * @author <a href="mailto:rodbra@pop.com.br">Rodrigo C. M. Coimbra</a> */public class TestModel { LoadFromFile data; private double rightValues = 0; private double wrongValues = 0; private double rightRate = 0; private double error = 2; private double[][] inferenceData; /** * Tests a model printing on screen the results and some statistics. * * @param nn Model to test. * @param testFile File name to load test data. * @param index Column index of expected output. * @param error Error rate accepted. */ public void testModel(INeuralNetwork nn, String testFile, int index, double error) { double diff = 0; int inferenceIndex = 0; if (Double.compare(error,0)==0) { this.error = Math.sqrt(nn.getError()); System.out.println("Error annulated!"); } else { this.error=error; } try { data = new LoadFromFile(testFile, index); for (int i=0; i<data.getExpectedOutput().length; i++) { nn.inputLayerSetup(data.getInputData()[i]); nn.propagateInput(); for (int j=0; j<nn.retrieveFinalResults().length; j++) { diff = Math.abs( (nn.retrieveFinalResults()[j]-data.getExpectedOutput()[i][0]) ); System.out.print("| " + nn.retrieveFinalResults()[j]+" || "+data.getExpectedOutput()[i][0]+" |"); System.out.println(" Difference: " + diff); if ( (Double.compare(diff, this.error)<0) ) { rightValues++; } else { wrongValues++; } } } rightRate = rightValues/data.getExpectedOutput().length; System.out.println("Error accepted: " + this.error); System.out.println("Accepted values: " + rightValues); System.out.println("Rejected values: " + wrongValues); } catch(IOException ioException) { System.out.println("IOException"); ioException.printStackTrace(); } } //testModel() /** * Validates a model. * <br><b>Not Implemented! Do not use this!</b> */ public void validateModel() { // TODO Implement this (?). } //validateModel() /** * Returns accepted error value. * * @return Accepted error value. */ public double getError() { return error; } //getError() /** * Sets accepted error value. * * @param error Accepted error value. */ public void setError(double error) { this.error = error; } //setError() /** * Returns accepted values rate. * * @return Accepted values rate. */ public double getRightRate() { return rightRate; } //getRightRate()} //TestModel
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -