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

📄 infinitevaluereplenishment.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.operator.preprocessing;

import edu.udo.cs.yale.example.Attribute;

/** Replaces positive and negative infinite values in examples by one of the functions 
 *  "none", "zero", "max_byte", "max_int", 
 *  "max_double", and "missing". "none" means, that the value is
 *  not replaced. The max_xxx functions replace plus infinity by the upper bound and minus infinity
 *  by the lower bound of the range of the Java type xxx. "missing" means, that the
 *  value is replaced by nan (not a number), which is internally used to represent missing values.
 *  A {@link MissingValueReplenishment} operator can be used to replace missing values by average, maximum,
 *  minimum etc. afterwards.<br/>
 *  For each attribute, 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.
 *
 *  @version $Id: InfiniteValueReplenishment.java,v 1.2 2004/08/27 11:57:44 ingomierswa Exp $
 */
public class InfiniteValueReplenishment extends ValueReplenishment {

    private static final int NONE       = 0;
    private static final int ZERO       = 1;
    private static final int MAX_BYTE   = 2;
    private static final int MAX_INT    = 3;
    private static final int MAX_DOUBLE = 4;
    private static final int MISSING    = 5;
    private static final String[] REP_NAMES = { "none", "zero", "max_byte", "max_int", "max_double", "missing" };

    public boolean replenishValue(double currentValue) { 
	return Double.isInfinite(currentValue); 
    }
    public String[] getFunctionNames() { return REP_NAMES; }
    public int getDefaultFunction() { return NONE; }
    public int getDefaultColumnFunction() { return ZERO; }

    /** Replaces the values */
    public double getReplenishmentValue(int functionIndex, Attribute attribute, double currentValue) {
	double sign = (currentValue > 0) ? +1d : -1d;
	switch (functionIndex) {
	case NONE:
	    return currentValue;
	case ZERO:
	    return 0.0;
	case MAX_BYTE:
	    return (currentValue > 0) ? Byte.MAX_VALUE : Byte.MIN_VALUE;
	case MAX_INT:
	    return (currentValue > 0) ? Integer.MAX_VALUE : Integer.MIN_VALUE;
	case MAX_DOUBLE:
	    return (currentValue > 0) ? Double.MAX_VALUE : -Double.MAX_VALUE;
	case MISSING:
	    return Double.NaN;
	default:
	    throw new RuntimeException("Illegal value functionIndex: "+functionIndex);
	}
    }
}

⌨️ 快捷键说明

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