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

📄 zetnormalstream.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
字号:
/*
 *    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., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

 /**
  * Title: XELOPES Data Mining Library
  * Description: The XELOPES library is an open platform-independent and data-source-independent library for Embedded Data Mining.
  * Copyright: Copyright (c) 2002 Prudential Systems Software GmbH
  * Company: ZSoft (www.zsoft.ru), Prudsys (www.prudsys.com)
  * @author Michael Thess
  * @version 1.0
  */
package com.prudsys.pdm.Transform.Special;

import com.prudsys.pdm.Core.MiningAttribute;
import com.prudsys.pdm.Core.MiningDataSpecification;
import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Core.NumericAttribute;
import com.prudsys.pdm.Input.MiningInputStream;
import com.prudsys.pdm.Models.Statistics.SimpleStats;
import com.prudsys.pdm.Transform.MiningTransformationFactory;
import com.prudsys.pdm.Transform.MiningTransformationStep;
import com.prudsys.pdm.Transform.OneToOne.Identity;
import com.prudsys.pdm.Transform.OneToOne.ZetNormal;

/**
 * Realization of normalization for a given mining input
 * stream. Only numeric attributes are normalized.
 */
public class ZetNormalStream extends VectorTransformationStream
{
  // -----------------------------------------------------------------------
  //  Variables declarations
  // -----------------------------------------------------------------------
  /** Array of mean values of all attributes. */
  private double[] meanValues = null;

  /** Array of deviation values of all attributes. */
  private double[] deviationValues = null;

  // -----------------------------------------------------------------------
  //  Constructors
  // -----------------------------------------------------------------------
  /**
   * Empty constructor.
   */
  public ZetNormalStream()
  {
  }

  /**
   * Constructor for given stream.
   *
   * @param inputStream mining input stream for normalization
   */
  public ZetNormalStream(MiningInputStream inputStream) {

    this.inputStream = inputStream;
  }

  // -----------------------------------------------------------------------
  //  Getter and setter methods
  // -----------------------------------------------------------------------
  /**
   * Returns array of mean values.
   *
   * @return array of mean values
   */
  public double[] getMeanValues()
  {
    return meanValues;
  }

  /**
   * Returns array of deviation values.
   *
   * @return array of deviation values
   */
  public double[] getDeviationValues()
  {
    return deviationValues;
  }

  // -----------------------------------------------------------------------
  //  Transformation methods
  // -----------------------------------------------------------------------
  /**
   * Calculates mean and deviation values for numeric attributes.
   *
   * @exception MiningException error while calculating minmax values
   */
  private void calcMeanDevValues() throws MiningException {

    // Calculate simple statistics:
    SimpleStats sist = new SimpleStats();
    sist.setInputStream(inputStream);
    sist.runCalculation(true);

    // Fill arrays of mean and deviation values:
    MiningDataSpecification metaData = inputStream.getMetaData();
    int nAtt  = metaData.getAttributesNumber();
    meanValues      = new double[nAtt];
    deviationValues = new double[nAtt];
    for (int i = 0; i < nAtt; i++) {
      MiningAttribute att = metaData.getMiningAttribute(i);
      if (att instanceof NumericAttribute) {
        meanValues[i]      = sist.getCalculatedValue(att, SimpleStats.STAT_MEAN );
        deviationValues[i] = sist.getCalculatedValue(att, SimpleStats.STAT_DEVIATION );
      };
    };
  }

  /**
   * Creates mining transformation step for zet normalization of
   * numeric attributes.
   *
   * @return mining transformation step
   * @exception MiningException no input stream defined
   */
  public MiningTransformationStep createMiningTransformationStep() throws MiningException  {

      // No mining input stream defined => exception:
      if (inputStream == null)
        throw new MiningException("No mining input stream defined");

      // Get minimum and maximum values of all numeric attributes:
      calcMeanDevValues();

      // Mining transformation factory:
      MiningTransformationFactory mtf = new MiningTransformationFactory();

      boolean notrans = true;
      MiningDataSpecification metaData = inputStream.getMetaData();
      for (int i = 0; i < metaData.getAttributesNumber(); i++) {
        // Get attribute and name:
        MiningAttribute mAtt = metaData.getMiningAttribute(i);
        String attName = mAtt.getName();

        // Don't use excluded attributes, if defined:
        if ( excludedAttributeNames != null && excludedAttributeNames.indexOf(attName) > -1)
          continue;

        // Add zet normalization if numeric attribute:
        if (mAtt instanceof NumericAttribute) {
          ZetNormal zn = new ZetNormal();
          zn.setSourceName( attName );
          zn.setTargetName( "n_" + attName );
          zn.setMean( meanValues[i] );
          zn.setDeviation( deviationValues[i] );
          mtf.addOneToOneMapping(zn);
          notrans = false;
        };
      };

      // No transformations at all => just 1 required, use first attribute:
      if (notrans) {
        MiningAttribute mAtt = metaData.getMiningAttribute(0);
        Identity id          = new Identity();
        id.setSourceName( mAtt.getName() );
        mtf.addOneToOneMapping(id);
      };

      // Create transformation step for normalization:
      mts = mtf.createMiningTransformationStep();

      return mts;
  }

  // -----------------------------------------------------------------------
  //  Other methods
  // -----------------------------------------------------------------------
  /**
   * Returns zet normalization description.
   *
   * @returns description of zet normalization
   */
  public String toString() {

    String mess = "Zet normalization stream.";

    return mess;
  }

}

⌨️ 快捷键说明

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