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

📄 featureweights.java

📁 著名的开源仿真软件yale
💻 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.features;import edu.udo.cs.yale.operator.ResultObjectAdapter;import edu.udo.cs.yale.operator.Saveable;import java.io.*;import java.util.Iterator;import java.util.Map;import java.util.LinkedHashMap;/** FeatureWeights holds the information about the weights of attributes of an example set. It is delivered by *  several feature weighting algorithms. * *  @version $Id: FeatureWeights.java,v 2.1 2003/08/29 00:39:32 mierswa Exp $ */public class FeatureWeights extends ResultObjectAdapter implements Saveable {    private Map weightMap = new LinkedHashMap();    /** Adds a weight for the attribute with the given name. */    public void addWeight(String name, double weight) {	weightMap.put(name, new Double(weight));    }    /** Returns the weight for the attribute with the given name. Returns Double.NaN if the weight for the      *  queried attribute is not known. */    public double getWeight(String name) {	Double value = (Double)weightMap.get(name);	if (value == null) return Double.NaN;	else return value.doubleValue();    }        public void save(File file) throws IOException {		PrintWriter out = new PrintWriter(new FileWriter(file));	Iterator i = weightMap.keySet().iterator();	while (i.hasNext()) {	    String key    = (String)i.next();	    double weight = ((Double)weightMap.get(key)).doubleValue();	    out.println(key + ": \t" + weight);	}	out.close();    }    public String toString() {	StringBuffer result = new StringBuffer("");	Iterator i = weightMap.keySet().iterator();	while (i.hasNext()) {	    String key = (String)i.next();	    result.append(key + ": " + ((Double)weightMap.get(key)).doubleValue() + "\n");	}	return result.toString();    }    public static FeatureWeights load(File file) throws IOException {	FeatureWeights result = new FeatureWeights();	BufferedReader in = new BufferedReader(new FileReader(file));	String line = null;	while ((line = in.readLine()) != null) {	    String name = line.substring(0, line.indexOf(":")).trim();	    String weightString = line.substring(line.indexOf(":") + 1).trim();	    double weight = 1.0d;	    try {		weight = Double.parseDouble(weightString);	    } catch (NumberFormatException e) {		throw new IOException("Cannot parse weight from weight file " + file + ": " + e.getMessage());	    }	    result.addWeight(name, weight);	}	in.close();	return result;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -