?? attributevector.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.example;
import edu.udo.cs.yale.operator.ResultObjectAdapter;
import java.awt.Component;
import javax.swing.JLabel;
import java.util.*;
/** Container class for <code>AttributeCounter</code>s.
*
* @author ingo
* @version $Id: AttributeVector.java,v 2.4 2004/08/27 11:57:31 ingomierswa Exp $
*/
public class AttributeVector extends ResultObjectAdapter {
private Map attributeCounters = new HashMap();
private int numberOfRuns = 0;
public AttributeVector(ExampleSet exampleSet, int numberOfRuns) {
for (int i = 0; i < exampleSet.getNumberOfAttributes(); i++) {
Attribute attribute = exampleSet.getAttribute(i);
attributeCounters.put(attribute.getConstructionDescription(), new AttributeCounter(attribute));
}
this.numberOfRuns = numberOfRuns;
}
/** Each time this method is called, the associated attribute counter is searched (or
* constructed if necessary) and its counter is increased by one. */
public void countAttribute(Attribute attribute) {
AttributeCounter counter = (AttributeCounter)attributeCounters.get(attribute.getConstructionDescription());
if (counter == null)
attributeCounters.put(attribute.getConstructionDescription(), new AttributeCounter(attribute));
else
counter.incrementCounter();
}
public String toString() {
LinkedList result = new LinkedList();
Iterator i = attributeCounters.values().iterator();
while (i.hasNext()) {
AttributeCounter counter = (AttributeCounter)i.next();
int currentCount = counter.getUseCount();
result.add(counter);
}
Collections.sort(result);
String resultString = "Attribute selection counter:\n";
i = result.listIterator();
while (i.hasNext()) {
AttributeCounter counter = (AttributeCounter)i.next();
int currentCount = counter.getUseCount();
resultString += counter.getAttribute().getConstructionDescription() + ": " + currentCount +
" (" + Math.round(((double)currentCount / (double)numberOfRuns) * 100.0d) + "%)";
if (i.hasNext()) resultString += ",\n";
}
return resultString;
}
/** Returns a html description of the attribute vector. */
protected String toHTML() {
StringBuffer buffer = new StringBuffer("");
buffer.append("<h1>"+edu.udo.cs.yale.tools.Tools.classNameWOPackage(this.getClass())+"</h1>");
buffer.append("<b>Number of attributes:</b> "+attributeCounters.size()+"<br>");
buffer.append("<table bgcolor=\"#E3D8C3\" border=\"1\">");
buffer.append("<tr bgcolor=\"#ccccff\"><th>Index</th><th>Name</th><th>Generated from</th><th>Count</th><th>Percent</th></tr>");
List result = new LinkedList();
Iterator i = attributeCounters.values().iterator();
while (i.hasNext()) {
AttributeCounter counter = (AttributeCounter)i.next();
int currentCount = counter.getUseCount();
result.add(counter);
}
Collections.sort(result);
i = result.iterator();
while (i.hasNext()) {
AttributeCounter counter = (AttributeCounter)i.next();
int currentCount = counter.getUseCount();
double percent = Math.round(((double)currentCount / (double)numberOfRuns) * 100.0d);
Attribute attribute = counter.getAttribute();
buffer.append("<tr><td>"+attribute.getIndex()+"</td><td>"+attribute.getName()+"</td><td>"+
attribute.getConstructionDescription()+"<td>"+currentCount+"<td>"+percent+"</td></tr>");
}
buffer.append("</table>");
return buffer.toString();
}
/** Returns a html label. */
public Component getVisualisationComponent() {
JLabel label = new JLabel("<html>" + toHTML() + "</html>");
label.setBorder(javax.swing.BorderFactory.createEmptyBorder(11,11,11,11));
label.setFont(label.getFont().deriveFont(java.awt.Font.PLAIN));
return label;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -