weka.classifiers.rules
Class NNge

java.lang.Object
  extended byweka.classifiers.Classifier
      extended byweka.classifiers.rules.NNge
All Implemented Interfaces:
java.lang.Cloneable, OptionHandler, java.io.Serializable, UpdateableClassifier

public class NNge
extends Classifier
implements UpdateableClassifier, OptionHandler

NNge classifier. Nearest neighbor like algorithm using non-nested generalized exemplars. For more information, see

Brent Martin, (1995) "Instance-Based learning : Nearest Neighbor With Generalization", Master Thesis, University of Waikato, Hamilton, New Zealand

Sylvain Roy (2002) "Nearest Neighbor With Generalization", Unpublished, University of Canterbury, Christchurch, New Zealand

Valid options are:

-I num
Set the number of folder to use in the computing of the mutual information (default 5)

-G num
Set the number of attempts of generalisation (default 5)

Version:
$$
Author:
Brent Martin (bim20@cosc.canterbury.ac.nz), Sylvain Roy (sro33@student.canterbury.ac.nz)
See Also:
Serialized Form

Nested Class Summary
private  class NNge.Exemplar
          Implements Exemplar as used by NNge : parallel axis hyperrectangle.
 
Field Summary
private  NNge.Exemplar m_Exemplars
          The list of Exemplars
private  NNge.Exemplar[] m_ExemplarsByClass
          The lists of Exemplars by class
(package private)  double[] m_MaxArray
          The maximum values for numeric attributes.
private  double[] m_MI
           
private  double[] m_MI_MaxArray
           
private  double[] m_MI_MinArray
           
private  int[][][] m_MI_NumAttrClassInter
          MUTUAL INFORMATION'S DATAS
private  int[][][] m_MI_NumAttrClassValue
           
private  int[][] m_MI_NumAttrInter
           
private  int[][] m_MI_NumAttrValue
           
private  int[] m_MI_NumClass
           
private  int m_MI_NumInst
           
(package private)  double[] m_MinArray
          The minimum values for numeric attributes.
private  double[] m_MissingVector
          Values to use for missing value
private  int m_NumAttemptsOfGene
          The number of try for generalisation
private  int m_NumFoldersMI
          The number of folder for the Mutual Information
private  Instances m_Train
          An empty instances to keep the headers, the classIndex, etc...
 
Fields inherited from class weka.classifiers.Classifier
m_Debug
 
Constructor Summary
NNge()
           
 
Method Summary
private  void addExemplar(NNge.Exemplar ex)
          Adds an Exemplar in NNge's lists Ensure that the exemplar is not already in a list : the links would be broken...
private  void adjust(Instance newInst, NNge.Exemplar predictedExemplar)
          Adjust the NNge.
private  double attrWeight(int index)
          returns the weight of indexth attribute
 void buildClassifier(Instances data)
          Generates a classifier.
 double classifyInstance(Instance instance)
          Classifies a given instance.
private  boolean detectOverlapping(NNge.Exemplar ex)
          Returns true if ex overlaps any of the Exemplars in NNge's lists
private  void generalise(Instance newInst)
          Generalise an Exemplar (not necessarily predictedExemplar) to match instance.
 int getNumAttemptsOfGeneOption()
          Gets the number of attempts for generalisation.
 int getNumFoldersMIOption()
          Gets the number of folder for mutual information.
 java.lang.String[] getOptions()
          Gets the current option settings for the OptionHandler.
 java.lang.String globalInfo()
          Returns a string describing classifier
private  void initWeight(NNge.Exemplar ex)
          Init the weight of ex Watch out !
 java.util.Enumeration listOptions()
          Returns an enumeration of all the available options..
static void main(java.lang.String[] argv)
          Main method for testing this class.
private  NNge.Exemplar nearestExemplar(Instance inst)
          Returns the nearest Exemplar
private  NNge.Exemplar nearestExemplar(Instance inst, double c)
          Returns the nearest Exemplar with class c
private  boolean notEqualFeatures(Instance inst1, Instance inst2)
          Returns true if the instance don't have the same feature values
 java.lang.String numAttemptsOfGeneOptionTipText()
          Returns the tip text for this property
 java.lang.String numFoldersMIOptionTipText()
          Returns the tip text for this property
private  void prune(NNge.Exemplar predictedExemplar, Instance newInst)
          Prunes an Exemplar that matches an Instance
private  void removeExemplar(NNge.Exemplar ex)
          Removes an Exemplar from NNge's lists Ensure that the Exemplar is actually in NNge's lists.
 void setNumAttemptsOfGeneOption(int newIntParameter)
          Sets the number of attempts for generalisation.
 void setNumFoldersMIOption(int newIntParameter)
          Sets the number of folder for mutual information.
 void setOptions(java.lang.String[] options)
          Sets the OptionHandler's options using the given list.
 java.lang.String toString()
          Returns a description of this classifier.
private  void update(Instance instance)
          Performs the update of the classifier
 void updateClassifier(Instance instance)
          Updates the classifier using the given instance.
private  void updateMI(Instance inst)
          Updates the data for computing the mutual information MUST be called AFTER adding inst in m_Train
private  void updateMinMax(Instance instance)
          Updates the minimum, maximum, sum, sumSquare values for all the attributes
 
Methods inherited from class weka.classifiers.Classifier
debugTipText, distributionForInstance, forName, getDebug, makeCopies, setDebug
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_Train

private Instances m_Train
An empty instances to keep the headers, the classIndex, etc...


m_Exemplars

private NNge.Exemplar m_Exemplars
The list of Exemplars


m_ExemplarsByClass

private NNge.Exemplar[] m_ExemplarsByClass
The lists of Exemplars by class


m_MinArray

double[] m_MinArray
The minimum values for numeric attributes.


m_MaxArray

double[] m_MaxArray
The maximum values for numeric attributes.


m_NumAttemptsOfGene

private int m_NumAttemptsOfGene
The number of try for generalisation


m_NumFoldersMI

private int m_NumFoldersMI
The number of folder for the Mutual Information


m_MissingVector

private double[] m_MissingVector
Values to use for missing value


m_MI_NumAttrClassInter

private int[][][] m_MI_NumAttrClassInter
MUTUAL INFORMATION'S DATAS


m_MI_NumAttrInter

private int[][] m_MI_NumAttrInter

m_MI_MaxArray

private double[] m_MI_MaxArray

m_MI_MinArray

private double[] m_MI_MinArray

m_MI_NumAttrClassValue

private int[][][] m_MI_NumAttrClassValue

m_MI_NumAttrValue

private int[][] m_MI_NumAttrValue

m_MI_NumClass

private int[] m_MI_NumClass

m_MI_NumInst

private int m_MI_NumInst

m_MI

private double[] m_MI
Constructor Detail

NNge

public NNge()
Method Detail

globalInfo

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

Returns:
a description suitable for displaying in the explorer/experimenter gui

buildClassifier

public void buildClassifier(Instances data)
                     throws java.lang.Exception
Generates a classifier. Must initialize all fields of the classifier that are not being set via options (ie. multiple calls of buildClassifier must always lead to the same result). Must not change the dataset in any way.

Specified by:
buildClassifier in class Classifier
Parameters:
data - set of instances serving as training data
Throws:
java.lang.Exception - if the classifier has not been generated successfully

classifyInstance

public double classifyInstance(Instance instance)
                        throws java.lang.Exception
Classifies a given instance.

Overrides:
classifyInstance in class Classifier
Parameters:
instance - the instance to be classified
Returns:
index of the predicted class as a double
Throws:
java.lang.Exception - if instance could not be classified successfully

updateClassifier

public void updateClassifier(Instance instance)
                      throws java.lang.Exception
Updates the classifier using the given instance.

Specified by:
updateClassifier in interface UpdateableClassifier
Parameters:
instance - the instance to include
Throws:
java.lang.Exception - if instance could not be incorporated successfully

update

private void update(Instance instance)
             throws java.lang.Exception
Performs the update of the classifier

Parameters:
instance - the new instance
Throws:
java.lang.Exception - if the update fails

nearestExemplar

private NNge.Exemplar nearestExemplar(Instance inst)
Returns the nearest Exemplar

Parameters:
inst - an Instance
Returns:
the nearest Exemplar to inst, null if no exemplar are found.

nearestExemplar

private NNge.Exemplar nearestExemplar(Instance inst,
                                      double c)
Returns the nearest Exemplar with class c

Parameters:
inst - an Instance
c - the class of the Exemplar to return
Returns:
the nearest Exemplar to inst with class c, null if no exemplar with class c are found.

generalise

private void generalise(Instance newInst)
                 throws java.lang.Exception
Generalise an Exemplar (not necessarily predictedExemplar) to match instance. predictedExemplar must be in NNge's lists

Parameters:
newInst - the new instance
Throws:
java.lang.Exception - in case of inconsitent situation

adjust

private void adjust(Instance newInst,
                    NNge.Exemplar predictedExemplar)
             throws java.lang.Exception
Adjust the NNge.

Parameters:
newInst - the instance to classify
predictedExemplar - the Exemplar that matches newInst
Throws:
java.lang.Exception - in case of inconsistent situation

prune

private void prune(NNge.Exemplar predictedExemplar,
                   Instance newInst)
            throws java.lang.Exception
Prunes an Exemplar that matches an Instance

Parameters:
predictedExemplar - an Exemplar
newInst - an Instance matched by predictedExemplar
Throws:
java.lang.Exception - in case of inconsistent situation. (shouldn't happen.)

notEqualFeatures

private boolean notEqualFeatures(Instance inst1,
                                 Instance inst2)
Returns true if the instance don't have the same feature values

Parameters:
inst1 - an instance
inst2 - an instance
Returns:
true if the instance don't have the same feature values

detectOverlapping

private boolean detectOverlapping(NNge.Exemplar ex)
Returns true if ex overlaps any of the Exemplars in NNge's lists

Parameters:
ex - an Exemplars
Returns:
true if ex overlaps any of the Exemplars in NNge's lists

updateMinMax

private void updateMinMax(Instance instance)
Updates the minimum, maximum, sum, sumSquare values for all the attributes

Parameters:
instance - the new instance

updateMI

private void updateMI(Instance inst)
               throws java.lang.Exception
Updates the data for computing the mutual information MUST be called AFTER adding inst in m_Train

Throws:
java.lang.Exception - is thrown if an inconsistent situation is met

initWeight

private void initWeight(NNge.Exemplar ex)
Init the weight of ex Watch out ! ex shouldn't be in NNge's lists when initialized

Parameters:
ex - the Exemplar to initialise

addExemplar

private void addExemplar(NNge.Exemplar ex)
Adds an Exemplar in NNge's lists Ensure that the exemplar is not already in a list : the links would be broken...

Parameters:
ex - a new Exemplar to add

removeExemplar

private void removeExemplar(NNge.Exemplar ex)
Removes an Exemplar from NNge's lists Ensure that the Exemplar is actually in NNge's lists. Likely to do something wrong if this condition is not respected. Due to the list implementation, the Exemplar can appear only once in the lists : once removed, the exemplar is not in the lists anymore.

Parameters:
ex - a new Exemplar to add

attrWeight

private double attrWeight(int index)
returns the weight of indexth attribute

Parameters:
index - attribute's index
Returns:
the weight of indexth attribute

toString

public java.lang.String toString()
Returns a description of this classifier.

Returns:
a description of this classifier as a string.

listOptions

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

Specified by:
listOptions in interface OptionHandler
Overrides:
listOptions in class Classifier
Returns:
an enumeration of all available options.

setOptions

public void setOptions(java.lang.String[] options)
                throws java.lang.Exception
Sets the OptionHandler's options using the given list. All options will be set (or reset) during this call (i.e. incremental setting of options is not possible).

Specified by:
setOptions in interface OptionHandler
Overrides:
setOptions in class Classifier
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 option settings for the OptionHandler.

Specified by:
getOptions in interface OptionHandler
Overrides:
getOptions in class Classifier
Returns:
the list of current option settings as an array of strings

numAttemptsOfGeneOptionTipText

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

Returns:
tip text for this property suitable for displaying in the explorer/experimenter gui

getNumAttemptsOfGeneOption

public int getNumAttemptsOfGeneOption()
Gets the number of attempts for generalisation.

Returns:
the value of the option G

setNumAttemptsOfGeneOption

public void setNumAttemptsOfGeneOption(int newIntParameter)
Sets the number of attempts for generalisation.

Parameters:
newIntParameter - the new value.

numFoldersMIOptionTipText

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

Returns:
tip text for this property suitable for displaying in the explorer/experimenter gui

getNumFoldersMIOption

public int getNumFoldersMIOption()
Gets the number of folder for mutual information.

Returns:
the value of the option I

setNumFoldersMIOption

public void setNumFoldersMIOption(int newIntParameter)
Sets the number of folder for mutual information.

Parameters:
newIntParameter - the new value.

main

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

Parameters:
argv - should contain command line arguments for evaluation (see Evaluation).