📄 normalizationgenerator.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.generator;
import edu.udo.cs.yale.tools.Ontology;
import edu.udo.cs.yale.tools.LogService;
import edu.udo.cs.yale.example.Attribute;
import edu.udo.cs.yale.example.ExampleTable;
import edu.udo.cs.yale.example.DataRow;
import edu.udo.cs.yale.example.ExampleSet;
/** Creates the normalized value of all input attributes, i.e. calculates <br>
* (value - min) / (max - min) for normalization between 0 and 1 and
* (value - min) / (max - min) * (MAX - MIN) + MIN for
* normalization between MIN and MAX.
*
* @version $Id: NormalizationGenerator.java,v 2.9 2004/08/27 11:57:33 ingomierswa Exp $
*/
public class NormalizationGenerator extends SingularNumericalGenerator {
public static final String FUNCTION_NAME = "norm";
private double min;
private double max;
/** Creates a new normalization generator. This generator normalizes the values between 0 and 1. */
public NormalizationGenerator() {
this(0.0d, 0.1d);
}
/** Creates a new normalization operator which normalizes the values between min and max. */
public NormalizationGenerator(double min, double max) {
this.min = min;
this.max = max;
}
public FeatureGenerator newInstance() {
return new NormalizationGenerator();
}
public double calculateValue(double value) {
return Double.NaN;
}
public void generate(DataRow data) throws GenerationException {
try {
Attribute a = getArgument(0);
double value = data.get(a);
double minA = a.getMinimum();
double maxA = a.getMaximum();
// if max = min or minA = maxA, all values are the same and are normalized to 0.0
double result = 0.0d;
if (((maxA - minA) != 0.0d) && ((max - min) != 0.0d)) {
result = (value - minA) / (maxA - minA) * (max - min) + min;
}
if (resultAttributes[0] != null)
data.set(resultAttributes[0], result);
} catch (ArrayIndexOutOfBoundsException ex) {
throw new GenerationException("a1:" + getArgument(0));
}
}
public void setFunction(String name) {
if (!FUNCTION_NAME.equals(name))
LogService.logMessage("Illegal function name '"+name+"' for "+getClass().getName()+".",
LogService.ERROR);
}
public String getFunction() {
return FUNCTION_NAME;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -