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

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

package com.prudsys.pdm.Models.AssociationRules;

import com.prudsys.pdm.Core.Category;

/**
 * Class representing an association rule. <p>
 *
 * From PDM CWM extension.
 *
 * @see ItemSet
 * @version 3.0, 2003/06/03
 */
public class RuleSet extends com.prudsys.pdm.Cwm.Core.ModelElement implements com.prudsys.pdm.Core.MiningMatrixElement
{
    // -----------------------------------------------------------------------
    //  Variables declarations
    // -----------------------------------------------------------------------
    /** Premise itemset of rule. */
    public ItemSet premise;

    /** Conclusion itemset of rule. */
    public ItemSet conclusion;

    /** Support of rule. */
    public double support;

    /** Confidence of rule. */
    public double confidence;

    /** Lift of rule (if defined). */
    public double lift = Category.MISSING_VALUE;

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

    /**
     * Constructs rule set from two itemsets and support and confidence
     * values.
     *
     * @param a itemset to be used as premise
     * @param b itemset to be used as conclusion
     * @param s support value
     * @param c confidence value
     */
    public RuleSet(ItemSet a, ItemSet b, double s, double c)
    {
        premise = a;
        conclusion = b;
        support = s;
        confidence = c;
    }

    /**
    * Initialize object. (Added by Alexey Grinyuk.)
    *
    * @param prem premise.
    * @param concl conclusion.
    * @param supp support.
    * @param conf confidence.
    */
    public void initializeRuleSet(ItemSet prem, ItemSet concl, double supp, double conf)
    {
        premise=prem;
        conclusion=concl;
        support=supp;
        confidence=conf;
    }

    // -----------------------------------------------------------------------
    //  Getter and setter methods
    // -----------------------------------------------------------------------
    /**
    * Get the premise itemset.
    *
    * @return premise itemset
    */
    public ItemSet getPremise()
    {
        return premise;
    }

    /**
    * Get the conclusion itemset.
    *
    * @return conclusion itemset
    */
    public ItemSet getConclusion()
    {
        return conclusion;
    }

    /**
    * Get the number of items in rule.
    * Obviously, this is the sum of the size of
    * both premise and conclusion itemsets.
    *
    * @return number of items in rule
    */
    public int getSize()
    {
        int size = premise.getSize() + conclusion.getSize();

        return size;
    }

    /**
    * Get the support of the rule.
    *
    * @return support value
    */
    public double getSupport()
    {
        return support;
    }

    /**
    * Get the confidence of the rule.
    *
    * @return confidence value
    */
    public double getConfidence()
    {
        return confidence;
    }

    /**
    * Get the lift of the rule.
    *
    * @return lift value
    */
    public double getLift()
    {
        return lift;
    }

    /**
     * Set lift of the rule.
     *
     * @param lift new lift value
     */
    public void setLift(double lift)
    {
         this.lift = lift;
    }

    // -----------------------------------------------------------------------
    //  java.lang.Object methods
    // -----------------------------------------------------------------------
    /**
     * Find out if two rule sets are equal.
     * They must have the same premise and conclusion.
     * The support and confidence values are not compared.
     *
     * @param obj the ruleset to compare with
     * @return true if equal, otherwise false
    */
    public boolean equals(Object obj)
    {
        RuleSet rs = (RuleSet) obj;
        if ( ! rs.getPremise().equals( premise ) ||
             ! rs.getConclusion().equals( conclusion ) )
          return false;

        return true;
    }

    /**
     * Calculates the hash code.
     *
     * @return hash code
     */
    public int hashCode() {

        return premise.hashCode() + conclusion.hashCode();
    }

    /**
    * String representation of rule set.
    *
    * @return String representation
    */
    public String toString()
    {
        String text = "";
        for (int i = 0; i < premise.getSize(); i++)
          text = text + premise.getIntegerAt(i)+"\t";
        text = text + "==>";
        for (int i = 0; i < conclusion.getSize(); i++)
          text = text + conclusion.getIntegerAt(i)+"\t";
        text = text + "Support="+(Math.round((support*1000))/10.0)+"%";
        text = text + "\tConfidence="+(Math.round((confidence*1000))/10.0)+"%";
        if ( !Category.isMissingValue(lift) )
          text = text + "\tLift="+(Math.round((lift*1000))/10.0)+"%";

        return text;
    }

    /**
    * Prints the association rule.
    */
    public void print()
    {
        System.out.println(toString());
    }
}

⌨️ 快捷键说明

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