⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 attributevector.java

📁 一个很好的LIBSVM的JAVA源码。对于要研究和改进SVM算法的学者。可以参考。来自数据挖掘工具YALE工具包。
💻 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 + -