public class Rule
extends java.lang.Object
Representation of a string of simple rules chained by 'and's: exemple[a1][=|>|<=]v1 && exemple[a2][=|>=|<=]v2 The rule has also a positive value (confidence) associated.
Modifier and Type | Field and Description |
---|---|
static int |
EQUAL
Flag for equal operator
|
static int |
GREATER
Flag for greater operator
|
static int |
LOWER
Flag for lower operator
|
Constructor and Description |
---|
Rule()
Constructs an empty rule.
|
Modifier and Type | Method and Description |
---|---|
int |
apply(MyDataset data)
It returns the number of the instances covered by the rule in a given dataset
|
int |
apply(MyDataset data,
Mask select)
Returns the number of the instances covered by the rule in a given dataset
|
int |
apply(MyDataset data,
Mask select,
int ignore)
Returns the number of the instances covered by the rule in a given dataset.
|
keel.Algorithms.Rule_Learning.Slipper.Stats |
apply(MyDataset data,
Mask positives,
Mask negatives)
It returns the number of true positives,true negatives,false positives and false negatives of the rule in a given dataset
|
Rule |
getCopy()
It returns a copy of this rule
|
double |
getCr()
Returns the confidence of the rule.
|
static double |
getDefaultW(MyDataset data,
Mask actives,
double[] distribution)
Computes W+ or W- for the default rule,
according to the function W=sum(Di) i e R
|
SimpleRule |
getSimpleRule(int i)
Returns the i-ieth simple rule of this rule.
|
java.lang.String |
getType()
It returns the right side (class) of the rule.
|
double |
getW(MyDataset data,
Mask actives,
double[] distribution)
Computes W+ or W- for this rule,
according to the function W=sum(Di) i e R
|
void |
grow(int attribute,
double value,
int operator)
Adds a simple rule to this rule.
|
void |
grow(SimpleRule sr)
Adds a simple rule to this rule.
|
boolean |
isEqual(Rule r)
Return wether this rule is equal to another given rule
|
void |
prune(int pos)
Deletes a simple rule from this chain
|
void |
setCr(double newCr)
Sets the new confidence of the rule.
|
void |
setCr(MyDataset data,
Mask positives,
Mask negatives,
double[] distribution)
Computes the confidence of this rule, according to the equation 4
of [AAAI99]:
Cr=1/2ln((W+ + 1/(2n))/(W_ + 1/(2n)))
W+: sum of the weights of the positive instances that are covered by the current rule
W_: sum of the weights of the negative instances that are covered by the current rule
n: |p|+|n|
|
void |
setType(java.lang.String new_class)
It sets the right side of the rule.
|
int |
size()
Returns the size (number of simple rules) of the rule
|
java.lang.String |
toString()
Returns a string representation of this Rule, containing the String representation of each SimpleRule.
|
public static int GREATER
public static int LOWER
public static int EQUAL
public int apply(MyDataset data, Mask select, int ignore)
data
- MyDataset the datasetselect
- Mask the mask with the active entries of the datasetignore
- int id of the single rule that it will be ignore in the applying of the rulepublic int apply(MyDataset data, Mask select)
data
- MyDataset the datasetselect
- Mask the mask with the active entries of the datasetpublic int apply(MyDataset data)
data
- MyDataset the datasetpublic keel.Algorithms.Rule_Learning.Slipper.Stats apply(MyDataset data, Mask positives, Mask negatives)
data
- MyDataset the datasetpositives
- active positive instances of datanegatives
- active negative instances of datapublic static double getDefaultW(MyDataset data, Mask actives, double[] distribution)
data
- MyDataset the datasetactives
- Mask the active entries (positives or negatives)distribution
- double[] the distribution D of weightspublic double getW(MyDataset data, Mask actives, double[] distribution)
data
- MyDataset the datasetactives
- Mask the active entriesdistribution
- double[] the distribution Dpublic void setCr(MyDataset data, Mask positives, Mask negatives, double[] distribution)
data
- MyDataset the datasetpositives
- Mask the positive entriesnegatives
- Mask the negative entriesdistribution
- double[] the distribution D of weightspublic void setCr(double newCr)
newCr
- the new confidence.public double getCr()
public SimpleRule getSimpleRule(int i)
i
- position of the simple rulepublic void grow(int attribute, double value, int operator)
attribute
- int attribute id (position of the attribute)value
- double attribute's valueoperator
- int rule operatorpublic void grow(SimpleRule sr)
sr
- SimpleRule the simple rulepublic void setType(java.lang.String new_class)
new_class
- double new class of the rulepublic java.lang.String getType()
public Rule getCopy()
public void prune(int pos)
pos
- int position of the simple rule of the rulepublic int size()
public boolean isEqual(Rule r)
r
- Rule the given rulepublic java.lang.String toString()
toString
in class java.lang.Object