📄 runvector.java
字号:
/* * YALE - Yet Another Learning Environment * Copyright (C) 2002, 2003 * Simon Fischer, Ralf Klinkenberg, Ingo Mierswa, * Katharina Morik, Oliver Ritthoff * Artificial Intelligence Unit * Computer Science Department * University of Dortmund * 44221 Dortmund, Germany * email: yale@ls8.cs.uni-dortmund.de * web: http://yale.cs.uni-dortmund.de/ * * This program 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. * * This program 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA. */package edu.udo.cs.yale.operator.performance;import edu.udo.cs.yale.tools.ResultService;import edu.udo.cs.yale.tools.LogService;import edu.udo.cs.yale.operator.Operator; import edu.udo.cs.yale.operator.IOObject; import edu.udo.cs.yale.operator.ResultObjectAdapter; import edu.udo.cs.yale.example.Attribute;import java.util.ArrayList;import java.util.Iterator;import java.util.ListIterator;/** Collects the performance vectors of a run. The performance criteria can be averaged by using * <code>average()</code>. * @author Ingo Mierswa * @version $Id: RunVector.java,v 2.3 2003/04/11 13:42:12 fischer Exp $ */public class RunVector extends ResultObjectAdapter { /** list of performance vectors. */ private ArrayList vectorList; public RunVector() { vectorList = new ArrayList(); } public void add(PerformanceVector pv) { vectorList.add(pv); } /** Returns the performance vector with index i. */ public PerformanceVector get(int index) { return (PerformanceVector)vectorList.get(index); } /** Returns all performance vectors as list. */ public ArrayList getVectorList() { return vectorList; } /** Returns the number of performance vectors. */ public int size() { return vectorList.size(); } /** Calculates the mean value of the performance criteria of the performance vectors and returns * a vector of performance criteria which contain for each criterium the mean value. */ public PerformanceVector average() { // SF 2003/04/11: // Use PerformanceVector.buildAverage() instead of tedious calculations // This will calculate (i.e. update) variance and average correctly in time O(1) // and the variance reflect variance of all examples PerformanceVector output = (PerformanceVector)get(0).clone(); for (int i = 1; i < size(); i++) { PerformanceVector pv = get(i); for (int j = 0; j < pv.size(); j++) { output.get(j).buildAverage(pv.get(j)); } } return output; // // Mittelwertarray, soviele wie es Kriterien gibt // double[] values = new double[first.size()];// // Varianzarray, soviele wie es Kriterien gibt// double[] variances = new double[first.size()];// // Aufaddieren:// // ------------// // Die einzelnen Vektoren mit den Kriterien drin durchgehen// ListIterator i = vectorList.getVectorList().listIterator();// while (i.hasNext()) {// // Fuer jeden Kriteriumsvektor seinen Wert im Valuesarray aufsummieren// PerformanceVector currentCriteriaList = (PerformanceVector)i.next();// int index = 0;// for (int c = 0; c < currentCriteriaList.size(); c++) {// double value = currentCriteriaList.get(c).getValue();// values[index++] += value;// }// }// // Mittelwert und Varianz:// // -----------------------// // Die Anzahl der Kriterien durchgehen// for (int m = 0; m < first.size(); m++) {// // Mittelwert berechnen: // values[m] /= vectorList.getVectorList().size();// // Varianz berechnen:// // die einzelnen Vektoren mit den Kriterien durchgehen und jeweils// // fuer jedes Kriterium die Differenzen zum Mittelwert usw. bestimmen// ListIterator v = vectorList.getVectorList().listIterator();// while (v.hasNext()) {// // fuer jeden Kriteriumvektor bestimme die Differenz zum Mittelwert, // // quadriere diese und summiere sie auf.// PerformanceVector currentCriteriaList = (PerformanceVector)v.next();// double var = 0;// var = currentCriteriaList.get(m).getValue() - values[m];// var *= var;// variances[m] += var;// }// variances[m] /= vectorList.getVectorList().size();// variances[m] = Math.sqrt(variances[m]);// }// // Setzen der Werte:// // -----------------// for (int o = 0; o < output.size(); o++) {// PerformanceCriterion criterion = output.get(o);// criterion.setValue(values[o]);// criterion.setVariance(variances[o]);// }// return output; } public String toString() { String result = "RunVector: \n"; ListIterator i = vectorList.listIterator(); while (i.hasNext()) result += (PerformanceVector)i.next() + "\n"; return result; } /** returns a <tt>String</tt> containing a time series of the values of each performance measures. * and the average of all performance measures over all runs. */ public String toResultString() { // Output format: // Time series of performance criterion 'error': 0.1 0.2 0.3 ... // Time series of performance criterion 'recall': 0.1 0.2 0.3 ... // ... // Average of performance criterion 'error': 0.2 (standard deviation: 0.15) // ... String result = ""; PerformanceVector averagePerformance = average(); // compute the averages // ---- print the time series of all performance criteria ---- for (int criterionIndex = 0; criterionIndex < averagePerformance.size(); criterionIndex++) { result += "Time series of performance criterion '"+((this.get(0)).get(criterionIndex)).getName()+"':"; for (int timeIndex = 0; timeIndex < this.size(); timeIndex++) { PerformanceVector currentPerformance = get(timeIndex); PerformanceCriterion criterion = currentPerformance.get(criterionIndex); result += " "+criterion.getValue(); } result += "\n"; } // ---- print the overall average (and variance) ---- for (int i = 0; i < averagePerformance.size(); i++) { PerformanceCriterion criterion = averagePerformance.get(i); result += " Average of performance criterion '"+criterion.getName()+"': " + criterion.getValue(); if (criterion.getVariance() >= 0) { result += " (" + criterion.getVariance() + ")"; } result += "\n"; // Alternativ: criterion.toResultString() } result += "\n"; return result; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -