📄 performancevector.java
字号:
/*
* YALE - Yet Another Learning Environment
* Copyright (C) 2001-2004
* Simon Fischer, Ralf Klinkenberg, Ingo Mierswa,
* Katharina Morik, Oliver Ritthoff
* Artificial Intelligence Unit
* Computer Science Department
* University of Dortmund
* 44221 Dortmund, Germany
* email: yale-team@lists.sourceforge.net
* 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.math.Averagable;
import edu.udo.cs.yale.tools.math.AverageVector;
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.ResultObjectAdapter;
import java.util.ArrayList;
import java.util.Iterator;
import java.awt.Component;
import javax.swing.JLabel;
/** Handles several performance criteria. It is possible to obtain more than one criterion
* and therefore they are added to a criteria list.
*
* @author Ingo
* @version $Id: PerformanceVector.java,v 2.17 2004/09/19 13:37:35 ingomierswa Exp $
*/
public class PerformanceVector extends AverageVector {
public static class DefaultComparator implements PerformanceComparator {
private double mdlWeight = 0.0d;
public DefaultComparator(double mdlWeight) {
this.mdlWeight = mdlWeight;
}
public int compare(PerformanceVector av1, PerformanceVector av2) {
if (av1.getCriterion("mdl") != null) {
int mainResult = av1.getMainCriterion().compareTo(av2.getMainCriterion());
double fitness1 = av1.getMainCriterion().getFitness();
double fitness2 = av2.getMainCriterion().getFitness();
double mdl1 = av1.getCriterion("mdl").getValue();
double mdl2 = av2.getCriterion("mdl").getValue();
double result1 = fitness1 / Math.max(fitness1, fitness2) - mdlWeight * (mdl1 / Math.max(mdl1, mdl2));
double result2 = fitness2 / Math.max(fitness1, fitness2) - mdlWeight * (mdl2 / Math.max(mdl1, mdl2));
return Double.compare(result1, result2);
} else {
return av1.getMainCriterion().compareTo(av2.getMainCriterion());
}
}
}
/** Used to compare two average vectors. */
private PerformanceComparator comparator = new DefaultComparator(0.0d);
/** Name of the main criterion. */
private String mainCriterion = null;
public void setComparator(PerformanceComparator comparator) {
this.comparator = comparator;
}
public void addCriterion(PerformanceCriterion crit) {
addAveragable(crit);
}
public PerformanceCriterion getCriterion(int index) {
return (PerformanceCriterion)getAveragable(index);
}
public PerformanceCriterion getCriterion(String name) {
return (PerformanceCriterion)getAveragable(name);
}
/** Sets the name of the main average (must be added by {@link #addAveragable(Averagable)}) */
public void setMainCriterionName(String mcName) {
if (getAveragable(mcName) == null) {
LogService.logMessage("Main criterion not found: '"+mcName+"'.", LogService.ERROR);
}
this.mainCriterion = mcName;
}
/** Returns the main {@link PerformanceCriterion}. If the main criterion is not specified
* by {@link #setMainCriterionName(String)}, the first criterion is returned. */
public PerformanceCriterion getMainCriterion() {
if (mainCriterion == null) {
return (PerformanceCriterion)getAveragable(0);
} else {
PerformanceCriterion pc = (PerformanceCriterion)getAveragable(mainCriterion);
if (pc == null) return (PerformanceCriterion)getAveragable(0);
return pc;
}
}
public int compareTo(Object o) {
double result = comparator.compare(this, (PerformanceVector)o);
if (result < 0.0) return -1;
else if (result > 0.0) return +1;
else return 0;
}
protected Object clone() {
PerformanceVector av = new PerformanceVector();
for (int i = 0; i < size(); i++) {
Averagable avg = (Averagable)getAveragable(i);
av.addAveragable((Averagable)(avg).clone());
}
return av;
}
public String toString() {
StringBuffer result = new StringBuffer("PerformanceVector [");
for (int i = 0; i < size(); i++) {
Averagable avg = getAveragable(i);
boolean isMainCriterion = ((mainCriterion != null) && (avg.getName().equals(mainCriterion)));
if ((mainCriterion != null) && (avg.getName().equals(mainCriterion))) {
result.append("\n*****");
} else {
result.append("\n-----");
}
result.append(avg);
}
result.append("]");
return result.toString();
}
public String toHTML() {
StringBuffer result = new StringBuffer("<h1>"+getName()+"</h1>");
result.append("<h3>main criterion: "+getMainCriterion().getName()+"</h3><ol>");
for (int i = 0; i < size(); i++) {
Averagable avg = getAveragable(i);
result.append("<li>" + avg.toHTML() + "</li>");
}
result.append("</ol>");
return result.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -