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

📄 interval.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.2
  */

package com.prudsys.pdm.Core;


/**
  * Interval described by lower and upper bounds and closure. <p>
  *
  * From PDM CWM Extension. <p>
  *
  * Superclasses:
  * <ul>
  *   <li> ModelElement
  * </ul>
  * Attributes:
  * <ul>
  *   <li> <i>lowerBound</i>: Least value. <br>
  *     - type: Float <br>
  *     - multiplicity: exactly one
  *   <li> <i>upperBound</i>: Greatest value. <br>
  *     - type: Float <br>
  *     - multiplicity: exactly one
  *   <li> <i>closure</i>: Closure of interval. The following closures
  *   are predefined: openOpen, openClosed, closedOpen, closedClosed. <br>
  *     - type: Integer <br>
  *     - multiplicity: exactly one
  * </ul>
  * Constraints:
  * <ul>
  *   <li> lowerBound must be less or equal to upperBound.
  * </ul>
  *
  * It corresponds to the PMML element Interval.
  *
  * @see com.prudsys.pdm.Adapters.PmmlVersion20.Interval
  */
public class Interval extends com.prudsys.pdm.Cwm.Core.ModelElement implements MiningMatrixElement, Cloneable
{
    // -----------------------------------------------------------------------
    //  Constants of closure of interval
    // -----------------------------------------------------------------------
    /** Lower bound and upper bound open. */
    public static final int OPEN_OPEN = 0;

    /** Lower bound open, upper bound closed. */
    public static final int OPEN_CLOSED = 1;

    /** Lower bound closed, upper bound open. */
    public static final int CLOSED_OPEN = 2;

    /** Lower and upper bound open. */
    public static final int CLOSED_CLOSED = 3;

    // -----------------------------------------------------------------------
    //  Variables declarations
    // -----------------------------------------------------------------------
    /** Lower bound of range. */
    private double lowerBound = Double.NEGATIVE_INFINITY;

    /** Upper bound of range. */
    private double upperBound = Double.POSITIVE_INFINITY;

    /** Closure of range. */
    private int closure = OPEN_OPEN;

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

    /**
     * Interval with its parameters given.
     *
     * @param lowerBound lower bound of its values
     * @param upperBound upper bound of its values
     * @param closure closure of interval
     */
    public Interval(double lowerBound, double upperBound, int closure)
    {
        this.lowerBound = lowerBound;
        this.upperBound = upperBound;
        this.closure    = closure;
    }

    // -----------------------------------------------------------------------
    //  Getter and setter methods
    // -----------------------------------------------------------------------
    /**
     * Returns lower bound.
     *
     * @return lower bound
     */
    public double getLowerBound()
    {
        return lowerBound;
    }

    /**
     * Sets lower bound.
     *
     * @param lowerBound new lower bound
     */
    public void setLowerBound(double lowerBound)
    {
        this.lowerBound = lowerBound;
    }

    /**
     * Returns upper bound.
     *
     * @return upper bound
     */
    public double getUpperBound()
    {
        return upperBound;
    }

    /**
     * Sets upper bound.
     *
     * @param upperBound new upper bound
     */
    public void setUpperBound(double upperBound)
    {
        this.upperBound = upperBound;
    }

    /**
     * Returns closure of interval.
     *
     * @return closure of interval
     */
    public int getClosure()
    {
      return closure;
    }

    /**
     * Sets closure of interval.
     *
     * @param closure new closure of interval
     */
    public void setClosure(int closure)
    {
      this.closure = closure;
    }

    // -----------------------------------------------------------------------
    //  Methods of PMML handling
    // -----------------------------------------------------------------------
    /**
     * Create PMML object Interval for use in PMML documents.
     *
     * @return PMMLs Interval object
     * @exception MiningException if there are some PMML creating errors
     * @see com.prudsys.pdm.Adapters.PmmlVersion20.Interval
     */
    public Object createPmmlObject() throws MiningException
    {
        com.prudsys.pdm.Adapters.PmmlVersion20.Interval interval = new com.prudsys.pdm.Adapters.PmmlVersion20.Interval();

        String clstr = "openOpen";
        if (closure == OPEN_OPEN)
          clstr = "openOpen";
        else if (closure == OPEN_CLOSED)
          clstr = "openClosed";
        else if (closure == CLOSED_OPEN)
          clstr = "closedOpen";
        else if (closure == CLOSED_CLOSED)
          clstr = "closedClosed";
        interval.setClosure(clstr);
        interval.setLeftMargin( Double.toString( lowerBound ) );
        interval.setRightMargin( Double.toString( upperBound ) );

        return interval;
    }

    /**
     * Reads from PMML object Interval.
     *
     * @param pmml PMMLs Interval object
     * @exception MiningException cannot parse PMML object
     * @see com.prudsys.pdm.Adapters.PmmlVersion20.DataField
     */
    public void parsePmmlObject( Object pmml ) throws MiningException
    {
        com.prudsys.pdm.Adapters.PmmlVersion20.Interval interval =
            (com.prudsys.pdm.Adapters.PmmlVersion20.Interval) pmml;

        lowerBound = Double.NEGATIVE_INFINITY;
        upperBound = Double.POSITIVE_INFINITY;
        try
        {
              lowerBound = Double.parseDouble( interval.getLeftMargin() );
              upperBound = Double.parseDouble( interval.getRightMargin() );
        }
        catch (Exception ex)
        {
        };

        closure = OPEN_OPEN;
        String clstr = interval.getClosure();
        if ( clstr.equals("openOpen") )
          closure = OPEN_OPEN;
        else if ( clstr.equals("openClosed") )
          closure = OPEN_CLOSED;
        else if ( clstr.equals("closedOpen") )
          closure = CLOSED_OPEN;
        else if ( clstr.equals("closedClosed") )
          closure = CLOSED_CLOSED;
    }

    // -----------------------------------------------------------------------
    //  java.lang.Object methods
    // -----------------------------------------------------------------------
    /**
     * Copies interval.
     *
     * @return copy of interval
     */
    public Object clone() {

      Interval interval = new Interval( this.lowerBound, this.upperBound, this.closure );

      return interval;
    }

    /**
     * Returns interval as string.
     *
     * @return interval information as string
     */
    public String toString()
    {
        String l = "(";
        String r = ")";
        if (closure == CLOSED_OPEN || closure == CLOSED_CLOSED)
          l = "[";
        if (closure == OPEN_CLOSED || closure == CLOSED_CLOSED)
          r = "]";
        String description = l + lowerBound + "," + upperBound + r;

        return description;
    }
}

⌨️ 快捷键说明

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