View Javadoc
1   package org.thegalactic.rule;
2   
3   /*
4    * AssociationRule.java
5    *
6    * Copyright: 2010-2015 Karell Bertet, France
7    * Copyright: 2015-2016 The Galactic Organization, France
8    *
9    * License: http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html CeCILL-B license
10   *
11   * This file is part of java-lattices.
12   * You can redistribute it and/or modify it under the terms of the CeCILL-B license.
13   */
14  import java.util.SortedSet;
15  
16  /**
17   * This class gives a representation for an association rule.
18   *
19   * A rule is composed of a premise and a conclusion that are comparable sets,
20   * i.e. sets of elements that can be sorted by the lectic order defined by class
21   * `ComparableSet`. An association rule extends regular rule with the notion of
22   * support and confidence. The confidence represents the number of observations
23   * for which the rule is true. The support represents the minimum number of
24   * observations for the rule to be relevant.
25   *
26   * @todo do we use composition over inheritance?
27   */
28  public class AssociationRule extends Rule {
29  
30      /* ------------- FIELDS ------------------ */
31      /**
32       * The confidence of the rule.
33       */
34      private double confidence;
35  
36      /**
37       * The support of the rule.
38       */
39      private double support;
40  
41      /* ------------- CONSTRUCTORS ------------------ */
42      /**
43       * Constructs a new empty Rule with a empty premise and an empty conclusion.
44       */
45      public AssociationRule() {
46          super();
47      }
48  
49      /**
50       * Constructs a new Rule with the premise and the conclusion given in
51       * parameters.
52       *
53       * @param premise    a set of indexed elements
54       * @param conclusion a set of indexed elements
55       */
56      public AssociationRule(final SortedSet<Comparable> premise, final SortedSet<Comparable> conclusion) {
57          super(premise, conclusion);
58      }
59  
60      /**
61       * Constructs a new Rule with the premise, the conclusion, the confidence
62       * and the support given in parameters.
63       *
64       * @param premise    a set of indexed elements
65       * @param conclusion a set of indexed elements
66       * @param support    a support value
67       * @param confidence a confidence value
68       */
69      public AssociationRule(
70              final SortedSet<Comparable> premise,
71              final SortedSet<Comparable> conclusion,
72              final double support,
73              final double confidence
74      ) {
75          super(premise, conclusion);
76          this.support = support;
77          this.confidence = confidence;
78      }
79  
80      /* ------------- ACCESSORS METHODS ------------------ */
81      /**
82       * Returns the confidence value of the rule.
83       *
84       * @return confidence value
85       */
86      public final double getConfidence() {
87          return this.confidence;
88      }
89  
90      /**
91       * Returns the support value of the rule.
92       *
93       * @return support value
94       */
95      public final double getSupport() {
96          return this.support;
97      }
98  
99      /* ------------- MODIFICATION METHODS ------------------ */
100     /**
101      * Set the confidence value of the rule.
102      *
103      * @param confidence the confidence value
104      */
105     public final void setConfidence(final double confidence) {
106         this.confidence = confidence;
107     }
108 
109     /**
110      * Set the support value of the rule.
111      *
112      * @param support the support value
113      */
114     public final void setSupport(final double support) {
115         this.support = support;
116     }
117 
118     /* ------------- OVERRIDEN METHODS ------------------ */
119     /**
120      * Returns a String representation of this component.
121      *
122      * The following format is used:
123      *
124      * ~~~
125      * [premise] -> [conclusion] : s:support/c:confidence
126      * ~~~
127      *
128      * @return a string made of premises followed by -> and the conclusions.
129      */
130     @Override
131     public String toString() {
132         final StringBuilder builder = new StringBuilder();
133         builder.append(super.toString()).append(" : s:").append(this.support).append("/c:").append(this.confidence);
134         return builder.toString();
135     }
136 }