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

📄 miningalgorithm.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 (valentine.stepanenko@zsoft.ru)
  * @version 1.1
  */

package com.prudsys.pdm.Core;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import com.prudsys.pdm.Automat.MiningAutomationAssignment;
import com.prudsys.pdm.Automat.MiningAutomationCallback;
import com.prudsys.pdm.Automat.MiningModelAssessment;
import com.prudsys.pdm.Automat.RetrospectiveCallback;
import com.prudsys.pdm.Automat.SlidingCallback;
import com.prudsys.pdm.Core.Event.AlgorithmStatusMessage;
import com.prudsys.pdm.Input.MiningInputStream;

/**
 * Base class describing the mining algorithm. All allgorithms must
 * extend this class. <p>
 *
 * From PDM CWM extension. <p>
 *
 * Superclasses:
 * <ul>
 *   <li> Class
 * </ul>
 * Attributes:
 * <ul>
 *   <li> <i>timeSpentToBuildModel</i>: Time required to build the mining model. <br>
 *     - type: Float <br>
 *     - multiplicity: exactly one
 * </ul>
 * References:
 * <ul>
 *   <li> <i>miningInputStream</i>: References the mining algorithms's input data. <br>
 *       - class: MiningInputStream <br>
 *       - multiplicity: zero or one
 *   <li> <i>metaData</i>: References the mining algorithms's meta data, from input data. <br>
 *       - class: MiningDataSpecification <br>
 *       - multiplicity: zero or one
 *   <li> <i>applicationInputSpecification</i>: References the mining algorithms's application
 *   input specification. <br>
 *       - class: ApplicationInputSpecification <br>
 *       - multiplicity: zero or one
 *   <li> <i>miningSettings</i>: References the mining algorithm's settings. <br>
 *       - class: MiningSettings <br>
 *       - defined by: DerivedFromSettings::settings <br>
 *       - multiplicity: zero or one
 *   <li> <i>miningAlgorithmSpecification</i>: References the mining algorithm's specific settings. <br>
 *       - class: MiningAlgorithmSpecification <br>
 *       - multiplicity: zero or one
 *   <li> <i>listenerList</i>: References the listeners assigned to the mining algorithm. <br>
 *       - class: EventListenerList <br>
 *       - multiplicity: zero or one
 *   <li> <i>miningAutomationAssignment</i>: References the mining algorithm's automation specification. <br>
 *       - class: MiningAutomationAssignment <br>
 *       - multiplicity: zero or one
 *   <li> <i>model</i>: References the MiningModel produced by the mining algorithm. <br>
 *       - class: MiningModel <br>
 *       - defined by: ProducedByModel::model <br>
 *       - multiplicity: exactly one
 * </ul>
 */
public abstract class MiningAlgorithm extends com.prudsys.pdm.Cwm.Core.Class
{
    // -----------------------------------------------------------------------
    //  Variables declarations
    // -----------------------------------------------------------------------
    /** Input stream of the algorithm. */
    protected MiningInputStream miningInputStream;

    /** Meta data of input stream. */
    protected MiningDataSpecification metaData;

    /** Mining settings of the algorithm (also assigned to model). */
    protected MiningSettings miningSettings;

    /** Algorithm-specific settings of the algorithm. */
    protected MiningAlgorithmSpecification miningAlgorithmSpecification;

    /** Listeners assigned to the algorithm. */
    protected EventListenerList listenerList = new EventListenerList();

    /** Application input specification assigned to the model. */
    protected ApplicationInputSpecification applicationInputSpecification;

    /** Mining model generated by the algorithm. */
    protected MiningModel miningModel;

    /** Automation object assigned to algorithm. */
    protected MiningAutomationAssignment miningAutomationAssignment;

    /** Time for generating the model. */
    protected double timeSpentToBuildModel;

    /** Parent for current algorithm. */
    protected MiningAlgorithm parentAlgorithm = null;
    
    protected int algorithmLevel = 0;

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

    /**
     * Constructs mining algorithm from input stream, mining settings,
     * and mining algorithm specification.
     *
     * @param miningInputStream mining input stream of algorithm
     * @param miningSettings mining settings of algorithm
     * @param miningAlgorithmSpecification mining algorithm specification of algorithm
     * @throws IllegalArgumentException if arguments are incorrect
     */
    public MiningAlgorithm( MiningInputStream miningInputStream, MiningSettings miningSettings, MiningAlgorithmSpecification miningAlgorithmSpecification )  throws IllegalArgumentException
    {
        setMiningInputStream( miningInputStream );
        setMiningSettings( miningSettings );
        setMiningAlgorithmSpecification( miningAlgorithmSpecification );
    }

    /**
     * Constructs mining algorithm from input stream and mining settings.
     *
     * @param miningInputStream mining input stream of algorithm
     * @param miningSettings mining settings of algorithm
     * @throws IllegalArgumentException if arguments are incorrects
     */
    public MiningAlgorithm( MiningInputStream miningInputStream, MiningSettings miningSettings ) throws IllegalArgumentException
    {
        setMiningInputStream( miningInputStream );
        setMiningSettings( miningSettings );
    }

    // -----------------------------------------------------------------------
    //  Getter and setter methods
    // -----------------------------------------------------------------------
    /**
     * Returns parent algorithm.
     * 
     * @return parent algorithm
     */
    public MiningAlgorithm getParentAlgorithm() {
      return parentAlgorithm;
    }

    /**
     * Sets parent algorithm.
     * 
     * @param parent parent algorithm for current one
     */
    public void setParentAlgorithm(MiningAlgorithm parent) {
      this.parentAlgorithm = parent;

      Object[] list = parent.listenerList.getListenerList();
      if(list!=null && list.length > 1)
        for(int i=0; i < list.length; i+=2)
          if(list[i+1] instanceof MiningListener)
            addMiningListener((MiningListener)list[i+1]);
      
      MiningAlgorithm algo = parent;

      int counter = 0;
      while(algo!=null) {
        algo = algo.getParentAlgorithm();
        counter++;
      }

      this.algorithmLevel = counter;
    }
    
    /**
     * Returns number of parents.
     * 
     * @return algorithm level
     */
    public int getAlgorithmLevel() {
      return algorithmLevel;
    }
    
    /**
     * Returns mining input stream.
     *
     * @return mining input stream
     */
    public MiningInputStream getMiningInputStream()
    {
        return miningInputStream;
    }

    /**
     * Sets mining input stream for algorithm.
     *
     * @param miningInputStream new mining input stream
     * @throws IllegalArgumentException if arguments are incorrects
     */
    public void setMiningInputStream( MiningInputStream miningInputStream ) throws IllegalArgumentException
    {
        if( miningInputStream == null ) throw new IllegalArgumentException( "Mining input data can't be null." );
        this.miningInputStream = miningInputStream;
    }

    /**
     * Returns meta data.
     *
     * @return meta data
     */
    public MiningDataSpecification getMetaData()
    {
        return metaData;
    }

    /**
     * Creates an instance of the mining settings class that is required
     * to run the algorithm. The mining settings are assigned through the
     * setMiningSettings method.
     *
     * @return new instance of the mining settings class of the algorithm
     */
    public MiningSettings createMiningSettings() {

      return new MiningSettings();
    }

    /**
     * Returns mining settings.
     *
     * @return mining settings
     */
    public MiningSettings getMiningSettings()
    {
        return miningSettings;
    }

    /**
     * Sets mining settings for algorithm. Constructs also
     * meta data and application input specification.
     *
     * @param miningSettings new mining settings
     * @throws IllegalArgumentException if argument is incorrect
     */
    public void setMiningSettings( MiningSettings miningSettings ) throws IllegalArgumentException
    {
        miningSettings.verifySettings();
        this.metaData       = miningSettings.getDataSpecification();
        this.miningSettings = miningSettings;
        if( this.applicationInputSpecification == null )
        {
            this.applicationInputSpecification = new ApplicationInputSpecification( metaData );
            this.applicationInputSpecification.initApplicationInputSpecification( miningSettings );
        }
    }

    /**
     * Returns mining algorithm specification.
     *
     * @return mining algorithm specification
     */
    public MiningAlgorithmSpecification getMiningAlgorithmSpecification()
    {
        return miningAlgorithmSpecification;
    }

    /**
     * Sets mining algorithm specification for algorithm.
     *
     * Using Java's reflection mechanism, the corresponding
     * setter methods of the algorithm class are called with the
     * algorithm parameter values of the mining algorithm specification
     * as arguments.
     *
     * @param miningAlgorithmSpecification new mining algorithm specification
     * @throws IllegalArgumentException if arguments are incorrects
     */
    public void setMiningAlgorithmSpecification( MiningAlgorithmSpecification miningAlgorithmSpecification ) throws IllegalArgumentException
    {
        if( miningAlgorithmSpecification == null ) throw new IllegalArgumentException( "Mining application can't be null." );
        MiningAlgorithmParameter[] attribute = miningAlgorithmSpecification.getInputAttribute();
        String method, type, value;
        for (int i = 0; i < attribute.length; i++)
        {
            method = attribute[i].getMethod();
            type = attribute[i].getType();
            value = attribute[i].getValue();
            callSetMethod( method, type, value );
        }
        this.miningAlgorithmSpecification = miningAlgorithmSpecification;
    }

    /**
     * Call setter method of mining algorithm class for passing a new
     * parameter value to the algorithm.
     *
     * @param method name of the setter method
     * @param type type of the value ("byte", "java.lang.String", ...)
     * @param value as string
     * @throws IllegalArgumentException if arguments are incorrects
     */
    private void callSetMethod( String method, String type, String value ) throws IllegalArgumentException
    {
        Class algorithmClass = getClass();
        try
        {
            Class paramTypes[] = new Class[1];
            Object arguments[] = new Object[1];

            if( type.equals( "byte" ) )
            {
              byte in = Byte.parseByte( value );
              paramTypes[0] = byte.class;
              arguments[0] = new Byte( in );
            }
            else
            if( type.equals( "short" ) )
            {
              short in = Short.parseShort( value );
              paramTypes[0] = short.class;
              arguments[0] = new Short( in );
            }
            else
            if( type.equals( "int" ) )
            {
              int in = Integer.parseInt( value );

⌨️ 快捷键说明

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