weka.associations
Class Tertius

java.lang.Object
  extended byweka.associations.Associator
      extended byweka.associations.Tertius
All Implemented Interfaces:
java.lang.Cloneable, OptionHandler, java.lang.Runnable, java.io.Serializable

public class Tertius
extends Associator
implements OptionHandler, java.lang.Runnable

Class implementing a Tertius-type algorithm.

References: P. A. Flach, N. Lachiche (1999). Confirmation-Guided Discovery of first-order rules with Tertius. Machine Learning, 42, 61-95.

Valid options are:

-K number of values in result
Set maximum number of confirmation values in the result. (default: 10)

-F frequency threshold
Set frequency threshold for pruning. (default: 0)

-C confirmation threshold
Set confirmation threshold. (default: 0)

-N noise threshold
Set noise threshold : maximum frequency of counter-examples. 0 gives only satisfied rules. (default: 1)

-R
Allow attributes to be repeated in a same rule.

-L number of literals
Set maximum number of literals in a rule. (default: 4)

-G 0=no negation | 1=body | 2=head | 3=body and head
Set the negations in the rule. (default: 0)

-S
Consider only classification rules.

-c class index
Set index of class attribute. (default: last).

-H
Consider only horn clauses.

-E
Keep equivalent rules.

-M
Keep same clauses.

-T
Keep subsumed rules.

-I 0=always match | 1=never match | 2=significant
Set the way to handle missing values. (default: 0)

-O
Use ROC analysis.

-p name of file
Set the file containing the parts of the individual for individual-based learning.

-P 0=no output | 1=on stdout | 2=in separate window
Set output of current values. (default: 0)

Version:
$Revision: 1.1 $
Author:
Amelie Deltour
See Also:
Serialized Form

Field Summary
private static int ALL
           
private static int BODY
           
static int EXPLICIT
          Ways of handling missing values.
private static int HEAD
           
static int IMPLICIT
           
private  int m_best
          Number of best confirmation values to search.
private  boolean m_classification
          Classification bias.
private  int m_classIndex
          Index of class attribute.
private  double m_confirmationThreshold
          Confirmation threshold for the rules.
private  boolean m_equivalent
          Perform test on equivalent rules ?
private  int m_explored
          Number of hypotheses explored.
private  double m_frequencyThreshold
          Frequency threshold for the body and the negation of the head.
private  boolean m_horn
          Horn clauses bias.
private  int m_hypotheses
          Number of hypotheses considered.
private  Instances m_instances
          Instances used for the search.
private  int m_missing
          Way of handling missing values in the search.
private  int m_negation
          Type of negation used in the rules.
private  double m_noiseThreshold
          Maximal number of counter-instances.
private  int m_numLiterals
          Number of literals in a rule.
private  Instances m_parts
          Part instances for individual-based learning.
private  java.lang.String m_partsString
          Name of the file containing the parts for individual-based learning.
private  java.util.ArrayList m_predicates
          Predicates used in the rules.
private  int m_printValues
          Type of values output.
private  boolean m_repeat
          Repeat attributes ?
private  SimpleLinkedList m_results
          The results.
private  boolean m_roc
          Perform ROC analysis ?
private  boolean m_sameClause
          Perform test on same clauses ?
private  int m_status
          Status of the search.
private  boolean m_subsumption
          Perform subsumption test ?
private  java.util.Date m_time
          Time needed for the search.
private  java.awt.TextField m_valuesText
          Field to output the current values.
private static int MEMORY
           
private static int NO
           
private static int NONE
          Types of negation.
private static int NORMAL
           
private static int OUT
           
static int SIGNIFICANT
           
private static int STOP
           
private static Tag[] TAGS_MISSING
           
private static Tag[] TAGS_NEGATION
           
private static Tag[] TAGS_VALUES
           
private static int WINDOW
           
 
Constructor Summary
Tertius()
          Constructor that sets the options to the default values.
 
Method Summary
private  void addResult(Rule rule)
          Add a rule in the appropriate place in the list of the results, according to the confirmation and number of counter-instances of the rule.
private  void beginSearch()
          Begin the search by starting a new thread.
 void buildAssociations(Instances instances)
          Method that launches the search to find the rules with the highest confirmation.
private  Predicate buildPredicate(Instances instances, Attribute attr, boolean isClass)
          Build the predicate corresponding to an attribute.
private  java.util.ArrayList buildPredicates()
           
private  boolean canCalculateConfirmation(Rule rule)
          Test if it is worth calculating the confirmation of a rule.
private  boolean canCalculateOptimistic(Rule rule)
          Test if it is worth calculating the optimistic estimate of a rule.
private  boolean canExplore(Rule rule)
          Test if a rule can be explored (if it is interesting for the results or for refining).
private  boolean canRefine(Rule rule)
          Test if it is worth refining a rule.
private  boolean canStoreInNodes(Rule rule)
          Test if a rule can be stored in the agenda.
private  boolean canStoreInResults(Rule rule)
          Test if a rule can be added to the results.
 java.lang.String classificationTipText()
          Returns the tip text for this property.
 java.lang.String classIndexTipText()
          Returns the tip text for this property.
 java.lang.String confirmationThresholdTipText()
          Returns the tip text for this property.
 java.lang.String confirmationValuesTipText()
          Returns the tip text for this property.
 boolean disabled_getEquivalent()
          Get the value of equivalent.
 java.io.File disabled_getPartFile()
          Get the value of partFile.
 boolean disabled_getSameClause()
          Get the value of sameClause.
 boolean disabled_getSubsumption()
          Get the value of subsumption.
 void disabled_setEquivalent(boolean v)
          Set the value of equivalent.
 void disabled_setPartFile(java.io.File v)
          Set the value of partFile.
 void disabled_setSameClause(boolean v)
          Set the value of sameClause.
 void disabled_setSubsumption(boolean v)
          Set the value of subsumption.
private  void endSearch()
          End the search by notifying to the waiting thread that it is finished.
 java.lang.String equivalentTipText()
          Returns the tip text for this property.
 java.lang.String frequencyThresholdTipText()
          Returns the tip text for this property.
 boolean getClassification()
          Get the value of classification.
 int getClassIndex()
          Get the value of classIndex.
 double getConfirmationThreshold()
          Get the value of confirmationThreshold.
 int getConfirmationValues()
          Get the value of confirmationValues.
 double getFrequencyThreshold()
          Get the value of frequencyThreshold.
 boolean getHornClauses()
          Get the value of hornClauses.
 SelectedTag getMissingValues()
          Get the value of missingValues.
 SelectedTag getNegation()
          Get the value of negation.
 double getNoiseThreshold()
          Get the value of noiseThreshold.
 int getNumberLiterals()
          Get the value of numberLiterals.
 java.lang.String[] getOptions()
          Gets the current settings of the Tertius object.
 boolean getRepeatLiterals()
          Get the value of repeatLiterals.
 boolean getRocAnalysis()
          Get the value of rocAnalysis.
 SelectedTag getValuesOutput()
          Get the value of valuesOutput.
 java.lang.String globalInfo()
          Returns a string describing this associator.
 java.lang.String hornClausesTipText()
          Returns the tip text for this property.
 java.util.Enumeration listOptions()
          Returns an enumeration describing the available options.
static void main(java.lang.String[] options)
          Main method for testing this class.
 java.lang.String missingValuesTipText()
          Returns the tip text for this property.
 java.lang.String negationTipText()
          Returns the tip text for this property.
 java.lang.String noiseThresholdTipText()
          Returns the tip text for this property.
 java.lang.String numberLiteralsTipText()
          Returns the tip text for this property.
private  int numValuesInResult()
          Count the number of distinct confirmation values in the results.
 java.lang.String partFileTipText()
          Returns the tip text for this property.
private  void printValues()
          Print the current best and worst values.
 java.lang.String repeatLiteralsTipText()
          Returns the tip text for this property.
 void resetOptions()
          Resets the options to the default values.
 java.lang.String rocAnalysisTipText()
          Returns the tip text for this property.
 void run()
          Run the search.
 java.lang.String sameClauseTipText()
          Returns the tip text for this property.
 void search()
          Search in the space of hypotheses the rules that have the highest confirmation.
 void setClassification(boolean v)
          Set the value of classification.
 void setClassIndex(int v)
          Set the value of classIndex.
 void setConfirmationThreshold(double v)
          Set the value of confirmationThreshold.
 void setConfirmationValues(int v)
          Set the value of confirmationValues.
 void setFrequencyThreshold(double v)
          Set the value of frequencyThreshold.
 void setHornClauses(boolean v)
          Set the value of hornClauses.
 void setMissingValues(SelectedTag v)
          Set the value of missingValues.
 void setNegation(SelectedTag v)
          Set the value of negation.
 void setNoiseThreshold(double v)
          Set the value of noiseThreshold.
 void setNumberLiterals(int v)
          Set the value of numberLiterals.
 void setOptions(java.lang.String[] options)
          Parses a given list of options.
 void setRepeatLiterals(boolean v)
          Set the value of repeatLiterals.
 void setRocAnalysis(boolean v)
          Set the value of rocAnalysis.
 void setValuesOutput(SelectedTag v)
          Set the value of valuesOutput.
 java.lang.String subsumptionTipText()
          Returns the tip text for this property.
 java.lang.String toString()
          Outputs the best rules found with their confirmation value and number of counter-instances.
 java.lang.String valuesOutputTipText()
          Returns the tip text for this property.
 
Methods inherited from class weka.associations.Associator
forName, makeCopies
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_results

private SimpleLinkedList m_results
The results.


m_hypotheses

private int m_hypotheses
Number of hypotheses considered.


m_explored

private int m_explored
Number of hypotheses explored.


m_time

private java.util.Date m_time
Time needed for the search.


m_valuesText

private java.awt.TextField m_valuesText
Field to output the current values.


m_instances

private Instances m_instances
Instances used for the search.


m_predicates

private java.util.ArrayList m_predicates
Predicates used in the rules.


m_status

private int m_status
Status of the search.


NORMAL

private static final int NORMAL
See Also:
Constant Field Values

MEMORY

private static final int MEMORY
See Also:
Constant Field Values

STOP

private static final int STOP
See Also:
Constant Field Values

m_best

private int m_best
Number of best confirmation values to search.


m_frequencyThreshold

private double m_frequencyThreshold
Frequency threshold for the body and the negation of the head.


m_confirmationThreshold

private double m_confirmationThreshold
Confirmation threshold for the rules.


m_noiseThreshold

private double m_noiseThreshold
Maximal number of counter-instances.


m_repeat

private boolean m_repeat
Repeat attributes ?


m_numLiterals

private int m_numLiterals
Number of literals in a rule.


NONE

private static final int NONE
Types of negation.

See Also:
Constant Field Values

BODY

private static final int BODY
See Also:
Constant Field Values

HEAD

private static final int HEAD
See Also:
Constant Field Values

ALL

private static final int ALL
See Also:
Constant Field Values

TAGS_NEGATION

private static final Tag[] TAGS_NEGATION

m_negation

private int m_negation
Type of negation used in the rules.


m_classification

private boolean m_classification
Classification bias.


m_classIndex

private int m_classIndex
Index of class attribute.


m_horn

private boolean m_horn
Horn clauses bias.


m_equivalent

private boolean m_equivalent
Perform test on equivalent rules ?


m_sameClause

private boolean m_sameClause
Perform test on same clauses ?


m_subsumption

private boolean m_subsumption
Perform subsumption test ?


EXPLICIT

public static final int EXPLICIT
Ways of handling missing values.

See Also:
Constant Field Values

IMPLICIT

public static final int IMPLICIT
See Also:
Constant Field Values

SIGNIFICANT

public static final int SIGNIFICANT
See Also:
Constant Field Values

TAGS_MISSING

private static final Tag[] TAGS_MISSING

m_missing

private int m_missing
Way of handling missing values in the search.


m_roc

private boolean m_roc
Perform ROC analysis ?


m_partsString

private java.lang.String m_partsString
Name of the file containing the parts for individual-based learning.


m_parts

private Instances m_parts
Part instances for individual-based learning.


NO

private static final int NO
See Also:
Constant Field Values

OUT

private static final int OUT
See Also:
Constant Field Values

WINDOW

private static final int WINDOW
See Also:
Constant Field Values

TAGS_VALUES

private static final Tag[] TAGS_VALUES

m_printValues

private int m_printValues
Type of values output.

Constructor Detail

Tertius

public Tertius()
Constructor that sets the options to the default values.

Method Detail

globalInfo

public java.lang.String globalInfo()
Returns a string describing this associator.

Returns:
A description of the evaluator suitable for displaying in the explorer/experimenter gui.

resetOptions

public void resetOptions()
Resets the options to the default values.


listOptions

public java.util.Enumeration listOptions()
Returns an enumeration describing the available options.

Specified by:
listOptions in interface OptionHandler
Returns:
An enumeration of all the available options.

setOptions

public void setOptions(java.lang.String[] options)
                throws java.lang.Exception
Parses a given list of options.

Specified by:
setOptions in interface OptionHandler
Parameters:
options - The list of options as an array of strings.
Throws:
java.lang.Exception - if an option is not supported.

getOptions

public java.lang.String[] getOptions()
Gets the current settings of the Tertius object.

Specified by:
getOptions in interface OptionHandler
Returns:
An array of strings suitable for passing to setOptions.

confirmationValuesTipText

public java.lang.String confirmationValuesTipText()
Returns the tip text for this property.

Returns:
Tip text for this property suitable for displaying in the explorer/experimenter GUI.

getConfirmationValues

public int getConfirmationValues()
Get the value of confirmationValues.

Returns:
Value of confirmationValues.

setConfirmationValues

public void setConfirmationValues(int v)
                           throws java.lang.Exception
Set the value of confirmationValues.

Parameters:
v - Value to assign to confirmationValues.
Throws:
java.lang.Exception

frequencyThresholdTipText

public java.lang.String frequencyThresholdTipText()
Returns the tip text for this property.

Returns:
Tip text for this property suitable for displaying in the explorer/experimenter GUI.

getFrequencyThreshold

public double getFrequencyThreshold()
Get the value of frequencyThreshold.

Returns:
Value of frequencyThreshold.

setFrequencyThreshold

public void setFrequencyThreshold(double v)
Set the value of frequencyThreshold.

Parameters:
v - Value to assign to frequencyThreshold.

confirmationThresholdTipText

public java.lang.String confirmationThresholdTipText()
Returns the tip text for this property.

Returns:
Tip text for this property suitable for displaying in the explorer/experimenter GUI.

getConfirmationThreshold

public double getConfirmationThreshold()
Get the value of confirmationThreshold.

Returns:
Value of confirmationThreshold.

setConfirmationThreshold

public void setConfirmationThreshold(double v)
Set the value of confirmationThreshold.

Parameters:
v - Value to assign to confirmationThreshold.

noiseThresholdTipText

public java.lang.String noiseThresholdTipText()
Returns the tip text for this property.

Returns:
Tip text for this property suitable for displaying in the explorer/experimenter GUI.

getNoiseThreshold

public double getNoiseThreshold()
Get the value of noiseThreshold.

Returns:
Value of noiseThreshold.

setNoiseThreshold

public void setNoiseThreshold(double v)
Set the value of noiseThreshold.

Parameters:
v - Value to assign to noiseThreshold.

repeatLiteralsTipText

public java.lang.String repeatLiteralsTipText()
Returns the tip text for this property.

Returns:
Tip text for this property suitable for displaying in the explorer/experimenter GUI.

getRepeatLiterals

public boolean getRepeatLiterals()
Get the value of repeatLiterals.

Returns:
Value of repeatLiterals.

setRepeatLiterals

public void setRepeatLiterals(boolean v)
Set the value of repeatLiterals.

Parameters:
v - Value to assign to repeatLiterals.

numberLiteralsTipText

public java.lang.String numberLiteralsTipText()
Returns the tip text for this property.

Returns:
Tip text for this property suitable for displaying in the explorer/experimenter GUI.

getNumberLiterals

public int getNumberLiterals()
Get the value of numberLiterals.

Returns:
Value of numberLiterals.

setNumberLiterals

public void setNumberLiterals(int v)
Set the value of numberLiterals.

Parameters:
v - Value to assign to numberLiterals.

negationTipText

public java.lang.String negationTipText()
Returns the tip text for this property.

Returns:
Tip text for this property suitable for displaying in the explorer/experimenter GUI.

getNegation

public SelectedTag getNegation()
Get the value of negation.

Returns:
Value of negation.

setNegation

public void setNegation(SelectedTag v)
Set the value of negation.

Parameters:
v - Value to assign to negation.

classificationTipText

public java.lang.String classificationTipText()
Returns the tip text for this property.

Returns:
Tip text for this property suitable for displaying in the explorer/experimenter GUI.

getClassification

public boolean getClassification()
Get the value of classification.

Returns:
Value of classification.

setClassification

public void setClassification(boolean v)
Set the value of classification.

Parameters:
v - Value to assign to classification.

classIndexTipText

public java.lang.String classIndexTipText()
Returns the tip text for this property.

Returns:
Tip text for this property suitable for displaying in the explorer/experimenter GUI.

getClassIndex

public int getClassIndex()
Get the value of classIndex.

Returns:
Value of classIndex.

setClassIndex

public void setClassIndex(int v)
Set the value of classIndex.

Parameters:
v - Value to assign to classIndex.

hornClausesTipText

public java.lang.String hornClausesTipText()
Returns the tip text for this property.

Returns:
Tip text for this property suitable for displaying in the explorer/experimenter GUI.

getHornClauses

public boolean getHornClauses()
Get the value of hornClauses.

Returns:
Value of hornClauses.

setHornClauses

public void setHornClauses(boolean v)
Set the value of hornClauses.

Parameters:
v - Value to assign to hornClauses.

equivalentTipText

public java.lang.String equivalentTipText()
Returns the tip text for this property.

Returns:
Tip text for this property suitable for displaying in the explorer/experimenter GUI.

disabled_getEquivalent

public boolean disabled_getEquivalent()
Get the value of equivalent.

Returns:
Value of equivalent.

disabled_setEquivalent

public void disabled_setEquivalent(boolean v)
Set the value of equivalent.

Parameters:
v - Value to assign to equivalent.

sameClauseTipText

public java.lang.String sameClauseTipText()
Returns the tip text for this property.

Returns:
Tip text for this property suitable for displaying in the explorer/experimenter GUI.

disabled_getSameClause

public boolean disabled_getSameClause()
Get the value of sameClause.

Returns:
Value of sameClause.

disabled_setSameClause

public void disabled_setSameClause(boolean v)
Set the value of sameClause.

Parameters:
v - Value to assign to sameClause.

subsumptionTipText

public java.lang.String subsumptionTipText()
Returns the tip text for this property.

Returns:
Tip text for this property suitable for displaying in the explorer/experimenter GUI.

disabled_getSubsumption

public boolean disabled_getSubsumption()
Get the value of subsumption.

Returns:
Value of subsumption.

disabled_setSubsumption

public void disabled_setSubsumption(boolean v)
Set the value of subsumption.

Parameters:
v - Value to assign to subsumption.

missingValuesTipText

public java.lang.String missingValuesTipText()
Returns the tip text for this property.

Returns:
Tip text for this property suitable for displaying in the explorer/experimenter GUI.

getMissingValues

public SelectedTag getMissingValues()
Get the value of missingValues.

Returns:
Value of missingValues.

setMissingValues

public void setMissingValues(SelectedTag v)
Set the value of missingValues.

Parameters:
v - Value to assign to missingValues.

rocAnalysisTipText

public java.lang.String rocAnalysisTipText()
Returns the tip text for this property.

Returns:
Tip text for this property suitable for displaying in the explorer/experimenter GUI.

getRocAnalysis

public boolean getRocAnalysis()
Get the value of rocAnalysis.

Returns:
Value of rocAnalysis.

setRocAnalysis

public void setRocAnalysis(boolean v)
Set the value of rocAnalysis.

Parameters:
v - Value to assign to rocAnalysis.

partFileTipText

public java.lang.String partFileTipText()
Returns the tip text for this property.

Returns:
Tip text for this property suitable for displaying in the explorer/experimenter GUI.

disabled_getPartFile

public java.io.File disabled_getPartFile()
Get the value of partFile.

Returns:
Value of partFile.

disabled_setPartFile

public void disabled_setPartFile(java.io.File v)
                          throws java.lang.Exception
Set the value of partFile.

Parameters:
v - Value to assign to partFile.
Throws:
java.lang.Exception

valuesOutputTipText

public java.lang.String valuesOutputTipText()
Returns the tip text for this property.

Returns:
Tip text for this property suitable for displaying in the explorer/experimenter GUI.

getValuesOutput

public SelectedTag getValuesOutput()
Get the value of valuesOutput.

Returns:
Value of valuesOutput.

setValuesOutput

public void setValuesOutput(SelectedTag v)
Set the value of valuesOutput.

Parameters:
v - Value to assign to valuesOutput.

buildPredicate

private Predicate buildPredicate(Instances instances,
                                 Attribute attr,
                                 boolean isClass)
                          throws java.lang.Exception
Build the predicate corresponding to an attribute.

Parameters:
instances - The instances this predicates comes from.
attr - The attribute this predicate corresponds to.
isClass - Saying if the attribute is the class attribute.
Returns:
The corresponding Predicate.
Throws:
java.lang.Exception - if the predicate could not be build (the attribute is numeric).

buildPredicates

private java.util.ArrayList buildPredicates()
                                     throws java.lang.Exception
Throws:
java.lang.Exception

numValuesInResult

private int numValuesInResult()
Count the number of distinct confirmation values in the results.

Returns:
Number of confirmation values in the results.

canRefine

private boolean canRefine(Rule rule)
Test if it is worth refining a rule.

Parameters:
rule - The rule to consider.
Returns:
True if the rule can be refined, false otherwise.

canCalculateOptimistic

private boolean canCalculateOptimistic(Rule rule)
Test if it is worth calculating the optimistic estimate of a rule.

Parameters:
rule - The rule to consider.
Returns:
True if the optimistic estimate can be calculated, false otherwise.

canExplore

private boolean canExplore(Rule rule)
Test if a rule can be explored (if it is interesting for the results or for refining).

Parameters:
rule - The rule to consider.
Returns:
True if the rule can be explored, false otherwise.

canStoreInNodes

private boolean canStoreInNodes(Rule rule)
Test if a rule can be stored in the agenda.

Parameters:
rule - The rule to consider.
Returns:
True if the rule can be stored, false otherwise.

canCalculateConfirmation

private boolean canCalculateConfirmation(Rule rule)
Test if it is worth calculating the confirmation of a rule.

Parameters:
rule - The rule to consider.
Returns:
True if the confirmation can be calculated, false otherwise.

canStoreInResults

private boolean canStoreInResults(Rule rule)
Test if a rule can be added to the results.

Parameters:
rule - The rule to consider.
Returns:
True if the rule can be stored, false otherwise.

addResult

private void addResult(Rule rule)
Add a rule in the appropriate place in the list of the results, according to the confirmation and number of counter-instances of the rule.

Subsumption tests are performed and the rule may not be added.

Previous results may also be removed because of sumption.


buildAssociations

public void buildAssociations(Instances instances)
                       throws java.lang.Exception
Method that launches the search to find the rules with the highest confirmation.

Specified by:
buildAssociations in class Associator
Parameters:
instances - The instances to be used for generating the rules.
Throws:
java.lang.Exception - if rules can't be built successfully.

run

public void run()
Run the search.

Specified by:
run in interface java.lang.Runnable

beginSearch

private void beginSearch()
                  throws java.lang.Exception
Begin the search by starting a new thread.

Throws:
java.lang.Exception

endSearch

private void endSearch()
End the search by notifying to the waiting thread that it is finished.


search

public void search()
Search in the space of hypotheses the rules that have the highest confirmation. The search starts with the empty rule, other rules are generated by refinement.


printValues

private void printValues()
Print the current best and worst values.


toString

public java.lang.String toString()
Outputs the best rules found with their confirmation value and number of counter-instances. Also gives the number of hypotheses considered and explored, and the time needed.


main

public static void main(java.lang.String[] options)
Main method for testing this class.