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

📄 multipletomultiplemapping.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 *    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 Valentine Stepanenko (ValentineStepanenko@zsoft.ru)
  * @author Michael Thess
  * @version 1.1
  */

package com.prudsys.pdm.Transform;

import java.util.Vector;

import com.prudsys.pdm.Adapters.PmmlVersion20.DerivedField;
import com.prudsys.pdm.Adapters.PmmlVersion20.NormDiscrete;
import com.prudsys.pdm.Core.MiningAttribute;
import com.prudsys.pdm.Core.MiningDataSpecification;
import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Cwm.Transformation.ClassifierFeatureMap;
import com.prudsys.pdm.Cwm.Transformation.ClassifierMap;
import com.prudsys.pdm.Cwm.Transformation.FeatureMap;
import com.prudsys.pdm.Input.MiningVector;
import com.prudsys.pdm.Models.Statistics.StatisticsMiningModel;
import com.prudsys.pdm.Utils.IntVector;

/**
 * Transforms multiple attributes into multiple attributes.<p>
 *
 * This is done in two ways: an inherit multiple-to-multiple
 * mapping can be defined via the transformAttribute and
 * transformAttributeValue methods in all transformations
 * extending this class. <p>
 *
 * In addition, the arrays featureMap and cfMap (of the mother
 * class ClassifierMap) allow to include objects for ono-to-one
 * mappings (featureMap) and one-to-multiple mappings (cfMap)
 * representing the corresponding special cases of transformations. <p>
 *
 * The following correspondends of terms to CWM transformation holds:
 * classifier map (CWM)         <-> multiple-to-multiple map (XELOPES)
 * classifier feature map (CWM) <-> one-to-multiple map (XELOPES)
 * feature map (CWM)            <-> one-to-one map (XELOPES)
 */
public class MultipleToMultipleMapping extends ClassifierMap implements MiningTransformer
{
  // -----------------------------------------------------------------------
  //  Variables declarations
  // -----------------------------------------------------------------------
  /** Names of source attributes. */
  protected String[] sourceName;

  /** Names of target attributes. */
  protected String[] targetName;

  /** Remove source attribute after its transformation? */
  protected boolean removeSourceAttributes = true;

  /** Statistics mining model required by some extensions. */
  protected StatisticsMiningModel statisticsMiningModel;

  /** Pretransformed meta data. */
  protected MiningDataSpecification pretransformedMetaData;

  /** Transformed meta data. */
  protected MiningDataSpecification transformedMetaData;

  // -----------------------------------------------------------------------
  //  Constructor
  // -----------------------------------------------------------------------
  /**
   * Empty constructor.
   */
  public MultipleToMultipleMapping()
  {
  }

  // -----------------------------------------------------------------------
  //  Getter and setter methods
  // -----------------------------------------------------------------------
  /**
   * Sets new names of source attributes.
   *
   * @param sourceName new names of source attributes
   */
  public void setSourceName(String[] sourceName)
  {
    this.sourceName = sourceName;
  }

  /**
   * Returns names of source attributes.
   *
   * @return source attribute names
   */
  public String[] getSourceName()
  {
    return sourceName;
  }

  /**
   * Sets new names of target attributes.
   *
   * @param targetName new names of target attributes
   */
  public void setTargetName(String[] targetName)
  {
    this.targetName = targetName;
  }

  /**
   * Returns names of target attributes.
   *
   * @return names of target attributes
   */
  public String[] getTargetName()
  {
    return targetName;
  }

  /**
   * Set remove all source attributes after transformation (default: no).
   *
   * @param removeSourceAttributes set remove source attributes after transformation
   */
  public void setRemoveSourceAttributes(boolean removeSourceAttributes)
  {
    this.removeSourceAttributes = removeSourceAttributes;
  }

  /**
   * Remove all source attributes after transformation (default: no)?
   *
   * @return true if remove source attributes after trafo, otherwise false
   */
  public boolean isRemoveSourceAttributes()
  {
    return removeSourceAttributes;
  }

  /**
   * Sets statistics mining model required for some transformations.
   *
   * @param statisticsMiningModel new statistics mining model
   */
  public void setStatisticsMiningModel(StatisticsMiningModel statisticsMiningModel)
  {
    this.statisticsMiningModel = statisticsMiningModel;
  }

  /**
   * Returns statistics mining model required for some transformations.
   *
   * @return statistics mining model
   */
  public StatisticsMiningModel getStatisticsMiningModel()
  {
    return statisticsMiningModel;
  }

  /**
   * Sets array of feature maps.
   *
   * @param featureMap new array of feature maps
   */
  public void setOneToOneMapping(FeatureMap[] featureMap) {

    this.featureMap = featureMap;

    for (int i = 0; i < featureMap.length; i++)
      featureMap[i].classifierMap = this;
  }

  /**
   * Returns array of feature maps.
   *
   * @return array of feature maps
   */
  public FeatureMap[] getOneToOneMapping() {

    return featureMap;
  }

  /**
   * Sets array of classifier feature maps.
   *
   * @param cfMap new array of classifier feature maps
   */
  public void setOneToMultipleMapping(ClassifierFeatureMap[] cfMap) {

    this.cfMap = cfMap;

    for (int i = 0; i < cfMap.length; i++)
      cfMap[i].classifierMap = this;
  }

  /**
   * Returns array of classifier feature maps.
   *
   * @return array of classifier feature maps
   */
  public ClassifierFeatureMap[] getOneToMultipleMapping() {

    return cfMap;
  }

  /**
   * Returns source attribute names. If no source attribute names are defined,
   * all attributes names are considered as source names.
   *
   * @return dynamic source attributes
   */
  protected String[] getSourceNameDynamic() {

     if (sourceName == null) {
       MiningDataSpecification metaData = getSourceMetaData();
       int nSource = metaData.getAttributesNumber();
       String[] sn = new String[nSource];
       for (int i = 0; i < nSource; i++)
         sn[i] = metaData.getMiningAttribute(i).getName();
       return sn;
     }
     else
       return sourceName;
  }

  /**
   * Returns target attribute names.
   *
   * @return dynamic target attributes
   */
  protected String[] getTargetNameDynamic() {

    return targetName;
  }

  /**
   * Returns source attribute at specified index.
   * If no source attributes are defined, all attributes
   * are considered as source.
   *
   * @param index index of source attribute
   * @return source attribute, null if not found
   */
  protected MiningAttribute getSourceAttribute(int index) {

    MiningDataSpecification metaData = getSourceMetaData();

    // No source attributes specified => use whole meta data:
    if (sourceName == null)
      return metaData.getMiningAttribute(index);

    // Source attributes given => use index of source attributes:
    if (index < 0 || index >= sourceName.length)
      return null;
    MiningAttribute attribute = metaData.getMiningAttribute(sourceName[index]);

    return attribute;
  }

  /**
   * Returns meta data of sources, i.e. the pretransformed meta data.
   *
   * @return source meta data
   */
  protected MiningDataSpecification getSourceMetaData() {

    return pretransformedMetaData;
  }

  /**
   * Returns true if this class implements transformAttribute and
   * transformAttributeValues methods.
   *
   * Not very nice implementation because it checks the absolute
   * class path.
   *
   * @return true if transformations are implemented, else false
   */
  protected boolean containsMultipleToMultipleMapping() {

    if (getClass().getName().equals( "com.prudsys.pdm.Transform.MultipleToMultipleMapping" ))
      return false;

    return true;
  }

  // -----------------------------------------------------------------------
  //  Transformation methods
  // -----------------------------------------------------------------------
  /**
   * Transforms the source attributes. Must be implemented by classes
   * extending this class.
   *
   * @return transformed attributes
   * @exception MiningException cannot transform source attributes
   */
  public MiningAttribute[] transformAttribute() throws MiningException
  {
      throw new java.lang.UnsupportedOperationException("Method transformAttribute not implemented.");
  }

  /**
   * Transforms the attribute values. Must be implemented by classes extending
   * this class.
   *
   * @param attributeValues values of attribute to be transformed
   * @return tranformed values
   * @exception MiningException cannot transform attribute values
   */
  public double[] transformAttributeValue( double[] attributeValues ) throws MiningException
  {
      throw new java.lang.UnsupportedOperationException("Method transformAttributeValue not implemented.");
  }

  /**
   * Transforms mining vector.
   *
   * Notice that this method can also be applied to a mining vector without
   * own meta data. In this case the last meta data transformation is used
   * as transformation ressource. Such last meta data transformation could have
   * been done either explicitly, applying transform to some meta data, or
   * implicitely, when a mining vactor with meta data was transformed. If
   * none of both cases has ever happened, for the mining vector (without
   * meta data) an exception is thrown.
   *
   * @param vector mining vector to transform, must contain meta data
   * @return transformed mining vector, without meta data
   * @exception MiningException cannot transform mining vector
   */
  public MiningVector transform( MiningVector vector ) throws MiningException {

    // Transform meta data:
    MiningDataSpecification vecMetaData = vector.getMetaData();
    if (vecMetaData != null) {
      if (vecMetaData != pretransformedMetaData)
        transformedMetaData = transform(vecMetaData); // Caching
    }
    else {
      if (transformedMetaData == null)
        throw new MiningException("No meta data ressource for trafo available");
    }

    // Transform mining vector:
    double values[] = new double[transformedMetaData.getAttributesNumber()];
    int k = 0; // absolute value coordinate index

    // Transformations from mining feature map:

⌨️ 快捷键说明

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