📄 normalizationgenerator.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.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.Example;import edu.udo.cs.yale.example.DataRow;/** Creates the normalized value of all input attributes, i.e. calculates <br> * value / (max - min) * * @version $Id: NormalizationGenerator.java,v 2.3 2003/06/29 14:40:43 mierswa Exp $ */ public class NormalizationGenerator extends FeatureGenerator { public static final String FUNCTION_NAME = "norm"; /** Possible input attributes are numerical single values or interval values. */ private static final Attribute[] INPUT_ATTR = { new Attribute(Ontology.NUMERICAL, Ontology.NON_SERIES), }; public FeatureGenerator newInstance() { return new NormalizationGenerator(); } public Attribute[] getInputAttributes() { return INPUT_ATTR; } public Attribute[] getOutputAttributes(ExampleTable input) { Attribute a = getArgument(0); Attribute ao = new Attribute(Ontology.NUMERICAL, a.getBlockType(), FUNCTION_NAME, new Attribute[] {a}, false, a.getBlockNr(), null); return new Attribute[] { ao }; } public void generate(DataRow data) throws GenerationException { try { Attribute a = getArgument(0); double o = data.get(a); // if max = min, all values are the same and are normalized to 0.0 double n = a.getMaximum() - a.getMinimum(); double r = 0.0d; if (n != 0.0d) r = (o - a.getMinimum()) / n; if (resultAttributes[0] != null) data.set(resultAttributes[0], r); } 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 + -