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

📄 missingvaluereplenishment.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;import edu.udo.cs.yale.operator.parameter.*;import edu.udo.cs.yale.example.ExampleSet;import edu.udo.cs.yale.example.ExampleReader;import edu.udo.cs.yale.example.Example;import edu.udo.cs.yale.example.Attribute;import edu.udo.cs.yale.tools.LogService;import java.util.List;import java.util.HashMap;import java.util.Map;import java.util.Iterator;/** Replaces missing values in examples. If a value is missing, it is replaced by one of the *  functions minimum, maximum, average, and none, which is applied to the non missing attribute *  values of the example set. None means, that the value is not replaced. *  The function can be selected using the parameter list <code>columns</code>. If an attribute's *  name appears in this list as a key, the value is used as the function name. If the attribute's *  name is not in the list, the function specified by the <code>default</code> parameter is used. * *  @yale.xmlclass MissingValueReplenishment *  @author Ingo, Simon *  @version $Id: MissingValueReplenishment.java,v 2.2 2003/04/04 11:59:27 fischer Exp $ */public class MissingValueReplenishment extends Operator {    private static final Class[] INPUT_CLASSES = { ExampleSet.class };    private static final Class[] OUTPUT_CLASSES = { ExampleSet.class };    public static final int NONE    = 0;    public static final int MINIMUM = 1;    public static final int MAXIMUM = 2;    public static final int AVERAGE = 3;    public static final String[] REP_NAMES = { "none", "minimum", "maximum", "average" };    private Map replenishments = new HashMap();    private int deflt;    public void initApply() throws OperatorException {	super.initApply();	replenishments = new HashMap();	deflt = getParameterAsInt("default");	List columns = getParameterList("columns");	Iterator i = columns.listIterator();	while (i.hasNext()) {	    Object[] pair = (Object[])i.next();	    replenishments.put((String)pair[0], (Integer)pair[1]);	    LogService.logMessage("MissingValueReplenishment: Replenish missing values in column " + pair[0] +				  " with the " + pair[1] + " of the column.", LogService.MINIMUM);	}	LogService.logMessage("MissingValueReplenishment: Replenish all other missing values with the " + REP_NAMES[deflt] +			      " of the column.", LogService.MINIMUM);    }    public IOObject[] apply() throws OperatorException {        // get the input example set	IOContainer input = getInput();	ExampleSet eSet = (ExampleSet) input.getInput(ExampleSet.class);		ExampleReader reader = eSet.getExampleReader();	while (reader.hasNext()) {	    Example example = reader.next();	    for (int i = 0; i < example.getNumberOfAttributes(); i++) {		if (Double.isNaN(example.getValue(i))) {		    example.setValue(i, getReplenishmentValue(example.getAttribute(i)));		}	    }	}	return new IOObject[] { eSet };    }    /** Replaces tha values */    private double getReplenishmentValue(Attribute attribute) {	int rep = deflt;	Object repObject = replenishments.get(attribute.getName());	if (repObject != null) rep = ((Integer)repObject).intValue();	switch (rep) {	case NONE:	    return Double.NaN;	case MINIMUM:	    return attribute.getMinimum();	case MAXIMUM:	    return attribute.getMaximum();	case AVERAGE:	    return attribute.getAverage();	default:	    LogService.logMessage("MissingValueReplenishment: Has not replenish the missing value. Leave it to NaN.", LogService.WARNING);	    return Double.NaN;	}    }        public Class[] getOutputClasses() { return OUTPUT_CLASSES; }    public Class[] getInputClasses() { return INPUT_CLASSES; }    public List getParameterTypes() {	List types = super.getParameterTypes();	types.add(new ParameterTypeCategory("default", "Function to apply to all columns that are not explicitliy specified by parameter 'columns'.", REP_NAMES, NONE));	types.add(new ParameterTypeList("columns", "List of replacement functions for each column.", new ParameterTypeCategory("replace_with", "The key is the attribute name. The value is the name of function used to replace the missing value.", REP_NAMES, AVERAGE)));	return types;    }}

⌨️ 快捷键说明

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