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

📄 sequencenumbercallback.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.1
  */
package com.prudsys.pdm.Models.Sequential;

import com.prudsys.pdm.Automat.MiningAutomationAssignment;
import com.prudsys.pdm.Automat.RetrospectiveCallback;
import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Core.Event.AlgorithmStatusMessage;

/**
 * Calculates parameter settings for reaching a given number
 * of sequences.
 */
public class SequenceNumberCallback extends RetrospectiveCallback
{
  /** Minimal admissible stepsize for changing support value. */
  protected double minStepSize = 0.0000001;

  private double iv     = 1.0;
  private double delta0 = 2.0;
  private double delta  = delta0;

  /**
   * Empty constructor.
   */
  public SequenceNumberCallback()
  {
  }

  /**
   * Calculates new mining parameters to reach the prescribed
   * number of sequences.
   *
   * @return status of calculation
   * @exception MiningException error during calculation
   */
  protected int runParameterCalculation() throws MiningException {

    // Get support parameter from current mining settings:
    double supp = ((SequentialSettings) currentMiningSettings).getMinimumSupport();

    // Get assessment value for rules:
    int minRuleNumb = (int) miningAutomationAssignment.getMinAssessment();
    int maxRuleNumb = (int) miningAutomationAssignment.getMaxAssessment();
    int nRules      = (int) currentAssessment;

    // Get number of current iterations:
    int nIter  = getNumberOfCallbackSteps() + 1;

    // Make sure that lower bound not lowered:
    boolean lowerBound = false;
    int nTransact = ((SequentialAlgorithm) miningAlgorithm).getNumberOfTransactions();
    if (nTransact > 0 && supp <= 1.0 / nTransact)
      lowerBound = true;

    //System.out.println("Iter: " + nIter + " supp = " + supp*100.0 + " Number of sequences found = " + nRules);
    MiningAutomationAssignment maa = getMiningAlgorithm().getAutomationAssignment();
    if(maa!=null && SequenceNumberAssessment.class.isInstance(maa.getMiningModelAssessment())
        && ((SequenceNumberAssessment)maa.getMiningModelAssessment()).getRuleType()==1)
      getMiningAlgorithm().fireMiningEvent(new AlgorithmStatusMessage(getMiningAlgorithm().getAlgorithmLevel(), "SequentialIterationSequences", new Object[] {new Integer(nIter), new Double(supp*100.0), new Integer(nRules)}));
    else
      getMiningAlgorithm().fireMiningEvent(new AlgorithmStatusMessage(getMiningAlgorithm().getAlgorithmLevel(), "SequentialIterationRules", new Object[] {new Integer(nIter), new Double(supp*100.0), new Integer(nRules)}));

    // Use method of nesting intervals:
    if (nRules < minRuleNumb) {
      // Lower bound doesn't reach => quit;
      if (lowerBound) {
        getMiningAlgorithm().fireMiningEvent(new AlgorithmStatusMessage(getMiningAlgorithm().getAlgorithmLevel(), "SequentialIterationLowerBound", null));
        System.out.println("Terminate, because of: Cannot decrease support value because already at lower bound.");
        return CALCULATION_STATUS_NO_IMPROVEMENT;
      };

      if (nIter == 1)
        iv = supp / delta0;
      supp = supp - iv;
      iv   = iv / delta;
    };

    if (nRules > maxRuleNumb && maxRuleNumb > -1) {
      if (nIter == 1)
        iv = (1.0 - supp) / delta0;
      supp = supp + iv;
      iv   = iv / delta;
    };

    // Too small iteration steps => quit:
    if (iv < minStepSize) {
      getMiningAlgorithm().fireMiningEvent(new AlgorithmStatusMessage(getMiningAlgorithm().getAlgorithmLevel(), "SequentialIterationStepSize", null));
      System.out.println("Terminate, because of: Step size too small. iv = " + iv*100.0);
      return CALCULATION_STATUS_NO_IMPROVEMENT;
    };

    // Set support value to new mining settings:
   ((SequentialSettings) newMiningSettings).setMinimumSupport(supp);

    return CALCULATION_STATUS_SUCCESSFUL;
  }

  /**
   * Returns minimum step size of support value change (default: 0.0000001).
   *
   * @return minimum step size
   */
  public double getMinStepSize()
  {
    return minStepSize;
  }

  /**
   * Sets minimum step size of support value change (default: 0.0000001).
   *
   * @param minStepSize new minimum stepsize
   */
  public void setMinStepSize(double minStepSize)
  {
    this.minStepSize = minStepSize;
  }

}

⌨️ 快捷键说明

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