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

📄 sparsegrid.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
 * @author Valentine Stepanenko (valentine.stepanenko@zsoft.ru)
 * @version 1.0
 */

package com.prudsys.pdm.Models.Regression.SparseGrids;

import java.util.StringTokenizer;

import com.prudsys.pdm.Adapters.PmmlVersion20.SparseGridCoefficients;
import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Core.PmmlPresentable;

/**
  * Represents one Grid of Sparse Grids
  * mining function. <p>
  *
  * From PDM CWM extension. <p>
  *
  * Attributes:
  * <ul>
  *   <li> <i>gridName/i>: Name of the sparse grid. Currently,
  *   there is no standard for chosing the name. <br>
  *     - type: String <br>
  *     - multiplicity: exactly one
  *   <li> <i>numberOfAttributes</i>: Defines the number of attributes
  *   of the Sparse Grid model. <br>
  *     - type: Integer <br>
  *     - multiplicity: exactly one
  *   <li> <i>sparseGridHeader</i>: Definition of the levels per
  *   dimension. Usually a string of the form "3_5_3_9_3". <br>
  *     - type: String <br>
  *     - multiplicity: exactly one
  *   <li> <i>sparseGridCoefficients</i>: Coefficients of the basis
  *   function defined on this grid. <br>
  *     - type: Float[] <br>
  *     - multiplicity: one or more
  * </ul>
  *
  * In addition, functionality from extended PMML was added.
  * It corresponds to the PMML element SparseGrid.
  *
  * @see SparseGridMiningModel
  * @see com.prudsys.pdm.Adapters.PmmlVersion20.SparseGrid
  */
public class SparseGrid extends com.prudsys.pdm.Cwm.Core.Class implements PmmlPresentable
{
  // -----------------------------------------------------------------------
  //  Variables declarations
  // -----------------------------------------------------------------------
  /** Identifier of Sparse Grid. */
  private String gridName;

  /** Number of attributes. */
  private int numberOfAttributes;

  /** Header of SG specifying the grid structure. */
  private String sparseGridHeader;

  /** Coefficients of SG. */
  private double[] sparseGridCoefficients;

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

  // -----------------------------------------------------------------------
  //  Getter and setter methods
  // -----------------------------------------------------------------------
  /**
   * Returns grid name.
   *
   * @return grid name
   */
  public String getGridName()
  {
    return gridName;
  }

  /**
   * Sets grid name.
   *
   * @param gridName new grid name
   */
  public void setGridName(String gridName)
  {
    this.gridName = gridName;
  }

  /**
   * Sets number of attributes.
   *
   * @param numberOfAttributes new number of attributes
   */
  public void setNumberOfAttributes(int numberOfAttributes)
  {
    this.numberOfAttributes = numberOfAttributes;
  }

  /**
   * Returns number of attributes.
   *
   * @return number of attributes
   */
  public int getNumberOfAttributes()
  {
    return numberOfAttributes;
  }

  /**
   * Sets grid header.
   *
   * @param sparseGridHeader new grid header
   */
  public void setSparseGridHeader(String sparseGridHeader)
  {
    this.sparseGridHeader = sparseGridHeader;
  }

  /**
   * Returns grid header.
   *
   * @return grid header
   */
  public String getSparseGridHeader()
  {
    return sparseGridHeader;
  }

  /**
   * Sets array of grid coefficients.
   *
   * @param sparseGridCoefficients new array of grid coefficients
   */
  public void setSparseGridCoefficients(double[] sparseGridCoefficients)
  {
    this.sparseGridCoefficients = sparseGridCoefficients;
  }

  /**
   * Returns array of sparse grid coefficients.
   *
   * @return array of coefficients
   */
  public double[] getSparseGridCoefficients()
  {
    return sparseGridCoefficients;
  }

  // -----------------------------------------------------------------------
  //  Methods of PMML handling
  // -----------------------------------------------------------------------
    /**
     * Write grid to PMML element.
     *
     * @return PMML element of "sparse" grid
     * @exception MiningException
     */
    public Object createPmmlObject() throws MiningException
    {
       // Create grid:
       com.prudsys.pdm.Adapters.PmmlVersion20.SparseGrid grid =
         new com.prudsys.pdm.Adapters.PmmlVersion20.SparseGrid();

       // Set grid name:
       grid.setGridName( gridName );

       // Create header object:
       com.prudsys.pdm.Adapters.PmmlVersion20.SparseGridHeader gridHeader =
         new com.prudsys.pdm.Adapters.PmmlVersion20.SparseGridHeader();

       // Set number of attributes and header info:
       gridHeader.setNumberOfAttributes( String.valueOf( numberOfAttributes ) );
       gridHeader.setText( sparseGridHeader );

       // Add header to grid:
       grid.setSparseGridHeader( gridHeader );

       // Create coefficients object:
       com.prudsys.pdm.Adapters.PmmlVersion20.SparseGridCoefficients gridCoef =
         new com.prudsys.pdm.Adapters.PmmlVersion20.SparseGridCoefficients();

       gridCoef.setNumberOfCoefficients(
         String.valueOf(sparseGridCoefficients.length) );
       String sCoeff  = "";
       for (int i = 0; i < sparseGridCoefficients.length; i++) {
         sCoeff = sCoeff + String.valueOf(sparseGridCoefficients[i]);
         if ( i < sparseGridCoefficients.length - 1)
           sCoeff = sCoeff + " ";
       };
       gridCoef.setText( sCoeff );

       grid.setSparseGridCoefficients( gridCoef );

       return grid;
    }

    /**
     * Read grid from PMML element.
     *
     * @param pmmlObject PMML element to read in
     * @exception MiningException always thrown
     */
    public void parsePmmlObject( Object pmmlObject ) throws MiningException
    {
       // Get grid:
       com.prudsys.pdm.Adapters.PmmlVersion20.SparseGrid grid =
         (com.prudsys.pdm.Adapters.PmmlVersion20.SparseGrid) pmmlObject;

       // Get grid name:
       gridName = grid.getGridName();

       // Get grid header:
       com.prudsys.pdm.Adapters.PmmlVersion20.SparseGridHeader gridHeader =
         grid.getSparseGridHeader();

       // Get number of attributes and header info:
       numberOfAttributes = Integer.parseInt( gridHeader.getNumberOfAttributes() );
       sparseGridHeader   = gridHeader.getText();

       // Get coefficients:
       SparseGridCoefficients coeff = grid.getSparseGridCoefficients();
       int nCoeff = Integer.parseInt( coeff.getNumberOfCoefficients() );
       sparseGridCoefficients = new double[ nCoeff ];
       StringTokenizer stg = new StringTokenizer( coeff.getText() );
       int iCount = 0;
       while (stg.hasMoreTokens()) {
         sparseGridCoefficients[iCount] = Double.parseDouble(stg.nextToken());
         iCount = iCount + 1;
       };
    }

    // -----------------------------------------------------------------------
    //  Other export methods
    // -----------------------------------------------------------------------
    /**
     * Returns sparse grid as string.
     *
     * @return string representation of sparse grid
     */
    public String toString() {

      String str = "Grid name: " + gridName;
      str        = str + " numberOfAttributes: " + String.valueOf(numberOfAttributes);
      str        = str + " sparseGridHeader: " + sparseGridHeader;
      str        = str + " sparseGridCoefficients: ";
      for (int i = 0; i < sparseGridCoefficients.length; i++)
        str = str + String.valueOf( sparseGridCoefficients[i] + " " );

      return str;
    }

}

⌨️ 快捷键说明

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