ABLE 2.0.0 07/02/2003 10:25:01

com.ibm.able.beans.knn
Class AbleNaiveBayes

java.lang.Object
  |
  +--com.ibm.able.AbleObject
        |
        +--com.ibm.able.beans.knn.AbleNaiveBayes
All Implemented Interfaces:
AbleBean, AbleDataBufferManager, AbleEventListener, AbleEventListenerManager, AbleEventQueueManager, AbleEventQueueProcessor, AblePropertyChangeManager, AbleSerializable, AbleTranslateTemplateProvider, java.io.Serializable

public class AbleNaiveBayes
extends AbleObject
implements AbleTranslateTemplateProvider, java.io.Serializable

See Also:
Serialized Form

Field Summary
static java.lang.String defaultName
          Value assigned to name by default.
 double[] inNum
          The numeric input buffer
static java.lang.String[] MODE_NAMES
          Labels for the train, test and run modes for GUI use.
 double[] outNum
          The numeric output buffer
static java.lang.String PropertyDiscr
           
static int PropertyDiscrId
           
static java.lang.String PropertyM
           
static int PropertyMId
           
static int RUN
          Application or Run mode output is produced
static int TEST
          Test mode performance is tested (errors are computed)
static int TRAIN
          Training mode training data is stored
 
Fields inherited from class com.ibm.able.AbleObject
changed, chgSupport, comment, dataFlowEnabled, destBufferConnections, eventQueue, fileName, inputBuffer, listeners, logger, name, outputBuffer, parent, propertyConnectionMgr, sourceBufferConnections, state, stateChgSupport, trace
 
Constructor Summary
AbleNaiveBayes()
          Default constructor
AbleNaiveBayes(java.lang.String aName)
          Construct a naive bayes bean with specified name
AbleNaiveBayes(java.lang.String aName, int args)
           
 
Method Summary
 void calcPosteriorProb()
          Calculate posterior probability for all the elements of the attribute-value-class table
 double[] calcPriorClassProb()
          Calculate prior class probability from training data Looks at the parent's data source to find the fields Can return null if the parent is null
 void calcPriorProb()
          Calculate prior probability for all the elements of the attribute-value-class table (uniform distribution is assumed)
static java.lang.String Copyright()
          Determine the copyright of this class.
 void generateTranslateTemplates(AbleFilter inFilt, AbleFilter outFilt, java.util.Vector fields)
          The next three methods change the default behaviour of the ABLE filters, making them appropriate for Naive Bayes algorithm.
 double getAccuracy()
          Get the accuracy
 double getClass(double[] x)
          Find to which class the current test example is assigned by Naive Bayes algorithm
 double getCurrentActualClass()
          Get the current actual classes corresponding to the current test example
 double getCurrentLearnedClass()
          Get the current learned classes corresponding to the current test/run example
 double[] getCurrentTestExample()
          Get the current test example
 double[] getCurrentTrainExample()
          Get the current training example
 int getDiscretization()
          Get metric parameter
 AttributeValueClass getElement(java.util.Vector v, int attr, int val, int cl)
          Find an Attribute-Value-Class element in a Vector of Attribute-Value-Class elements and return it.
 double getError()
          Get the error
 double[] getInNum()
           
 int getM()
          Get metric parameter
 int getMaxProbIndex(double[] prob)
          Given an array of class probabilities, get the index corresponding to the class with the largest probability value
 int getNaiveBayesMode()
          Get the current operating mode of the naive bayes bean.
 int getNumAttributes()
          Get numAttr parameter
 int getNumClasses()
          Get numClasses parameter
 long getNumCorrectTestExamples()
          Get the number of correctly classified test examples
 int getNumInstances(int clasS)
          Calculates the number of instances in the training data set belonging to a given class based on information stored in the attribute-value-class table.
 long getNumRecords()
          Get numRecords parameter
 long getNumTestExamples()
          Get the number of test examples seen so far
 double[] getOutNum()
           
 void init()
          Get ready to process - init all the bean members
 void process()
          Performs the main, synchronous, standard processing function performed by this bean.
 void reset()
          reset the naive bayes bean
 java.util.Vector setAllTable()
          Constructs the vector containing all the possible attribute-value-class combinations, not just those found in the training data set (some of them may be found in the test data set and need to be initialized to 0).
protected  void setDefaults()
          Set up the event queue behavior No timer processing and no asynch event processing
 void setDiscretization(int newDiscr)
          Set discretization parameter
 void setM(int newM)
          Set m parameter - weight given to prior
 void setNaiveBayesMode(int mode)
          Set the operating mode of the naive bayes bean.
 void setNaiveBayesParameters(int newAttr, int newCl, long newRec)
          Set the number records, number attributes and number classes for naive bayes bean
 
Methods inherited from class com.ibm.able.AbleObject
addAbleEventListener, addDestBufferConnection, addPropertyChangeListener, addPropertyConnection, addSourceBufferConnection, addStateChangeListener, dataChanged, firePropertyChange, flushAbleEventQueue, getAbleEventListeners, getAbleEventProcessingEnabled, getAbleEventQueueSize, getComment, getDestBufferConnections, getFileName, getInputBuffer, getInputBuffer, getInputBufferAsStringArray, getInputBufferContents, getLogger, getName, getOutputBuffer, getOutputBuffer, getOutputBufferAsStringArray, getOutputBufferContents, getParent, getPropertyConnectionManager, getSleepTime, getSourceBufferConnections, getState, getTraceLogger, handleAbleEvent, hasInputBuffer, hasOutputBuffer, init, isAbleEventPostingEnabled, isAbleEventProcessingEnabled, isChanged, isConnectable, isDataFlowEnabled, isTimerEventProcessingEnabled, notifyAbleEventListeners, process, processAbleEvent, processBufferConnections, processNoEventProcessingEnabledSituation, processTimerEvent, quitAll, quitEnabledEventProcessing, removeAbleEventListener, removeAllAbleEventListeners, removeAllBufferConnections, removeAllConnections, removeAllPropertyConnections, removeDestBufferConnection, removePropertyChangeListener, removePropertyConnection, removeSourceBufferConnection, removeStateChangeListener, restartEnabledEventProcessing, restoreFromFile, restoreFromFile, restoreFromSerializedFile, restoreFromStream, resumeAll, resumeEnabledEventProcessing, saveToFile, saveToFile, setAbleEventProcessingEnabled, setChanged, setComment, setDataFlowEnabled, setFileName, setInputBuffer, setInputBuffer, setLogger, setName, setOutputBuffer, setOutputBuffer, setParent, setSleepTime, setState, setTimerEventProcessingEnabled, setTraceLogger, sourceConnectionsOK, startEnabledEventProcessing, suspendAll, suspendEnabledEventProcessing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultName

public static final java.lang.String defaultName
Value assigned to name by default.

PropertyMId

public static final int PropertyMId

PropertyM

public static final java.lang.String PropertyM

PropertyDiscrId

public static final int PropertyDiscrId

PropertyDiscr

public static final java.lang.String PropertyDiscr

inNum

public double[] inNum
The numeric input buffer

outNum

public double[] outNum
The numeric output buffer

TRAIN

public static final int TRAIN
Training mode training data is stored

TEST

public static final int TEST
Test mode performance is tested (errors are computed)

RUN

public static final int RUN
Application or Run mode output is produced

MODE_NAMES

public static final java.lang.String[] MODE_NAMES
Labels for the train, test and run modes for GUI use.
Constructor Detail

AbleNaiveBayes

public AbleNaiveBayes()
               throws AbleException
Default constructor

AbleNaiveBayes

public AbleNaiveBayes(java.lang.String aName)
               throws AbleException
Construct a naive bayes bean with specified name
Parameters:
Name - The object name


AbleNaiveBayes

public AbleNaiveBayes(java.lang.String aName,
                      int args)
               throws AbleException
Method Detail

getInNum

public double[] getInNum()

getOutNum

public double[] getOutNum()

setDefaults

protected void setDefaults()
                    throws AbleException
Set up the event queue behavior No timer processing and no asynch event processing

getNaiveBayesMode

public int getNaiveBayesMode()
Get the current operating mode of the naive bayes bean.
Returns:
int.

setNaiveBayesMode

public void setNaiveBayesMode(int mode)
Set the operating mode of the naive bayes bean.
Parameters:
Mode - The current operating mode, train/test/run

Returns:
void.

setNaiveBayesParameters

public void setNaiveBayesParameters(int newAttr,
                                    int newCl,
                                    long newRec)
Set the number records, number attributes and number classes for naive bayes bean
Parameters:
parameter - newRec that defines the number of records
parameter - newAttr that defines the number of attributes
parameter - newCl that defines the number of classes

setM

public void setM(int newM)
          throws AbleException
Set m parameter - weight given to prior
Parameters:
parameter - m

getM

public int getM()
Get metric parameter

setDiscretization

public void setDiscretization(int newDiscr)
                       throws AbleException
Set discretization parameter

getDiscretization

public int getDiscretization()
Get metric parameter

getNumRecords

public long getNumRecords()
Get numRecords parameter

getNumAttributes

public int getNumAttributes()
Get numAttr parameter

getNumClasses

public int getNumClasses()
Get numClasses parameter

getNumTestExamples

public long getNumTestExamples()
Get the number of test examples seen so far

getNumCorrectTestExamples

public long getNumCorrectTestExamples()
Get the number of correctly classified test examples

getAccuracy

public double getAccuracy()
Get the accuracy

getError

public double getError()
Get the error

getCurrentTrainExample

public double[] getCurrentTrainExample()
Get the current training example

getCurrentTestExample

public double[] getCurrentTestExample()
Get the current test example

getCurrentLearnedClass

public double getCurrentLearnedClass()
Get the current learned classes corresponding to the current test/run example

getCurrentActualClass

public double getCurrentActualClass()
Get the current actual classes corresponding to the current test example

init

public void init()
          throws AbleException
Get ready to process - init all the bean members
Overrides:
init in class AbleObject
Following copied from class: com.ibm.able.AbleObject
Throws:
AbleException - If an error occurs.
See Also:
AbleObject.startEnabledEventProcessing()

reset

public void reset()
           throws AbleException
reset the naive bayes bean
Overrides:
reset in class AbleObject
Following copied from class: com.ibm.able.AbleObject
Throws:
AbleException - If an error occurs.
See Also:
AbleBean.reset()

getMaxProbIndex

public int getMaxProbIndex(double[] prob)
Given an array of class probabilities, get the index corresponding to the class with the largest probability value

getElement

public AttributeValueClass getElement(java.util.Vector v,
                                      int attr,
                                      int val,
                                      int cl)
Find an Attribute-Value-Class element in a Vector of Attribute-Value-Class elements and return it. Returns null if the searched element is not in the Vector already.

getClass

public double getClass(double[] x)
                throws AbleException
Find to which class the current test example is assigned by Naive Bayes algorithm

calcPriorClassProb

public double[] calcPriorClassProb()
                            throws AbleException
Calculate prior class probability from training data Looks at the parent's data source to find the fields Can return null if the parent is null

setAllTable

public java.util.Vector setAllTable()
                             throws AbleException
Constructs the vector containing all the possible attribute-value-class combinations, not just those found in the training data set (some of them may be found in the test data set and need to be initialized to 0). Looks at the parent's data source to find the fields Can return null if the parent is null

calcPriorProb

public void calcPriorProb()
                   throws AbleException
Calculate prior probability for all the elements of the attribute-value-class table (uniform distribution is assumed)

getNumInstances

public int getNumInstances(int clasS)
Calculates the number of instances in the training data set belonging to a given class based on information stored in the attribute-value-class table.

calcPosteriorProb

public void calcPosteriorProb()
                       throws AbleException
Calculate posterior probability for all the elements of the attribute-value-class table

process

public void process()
             throws AbleException
Description copied from class: AbleObject
Performs the main, synchronous, standard processing function performed by this bean.

This base method implementation provides tracing only.

Overrides:
process in class AbleObject
Following copied from class: com.ibm.able.AbleObject
See Also:
AbleObject.inputBuffer, AbleObject.outputBuffer, AbleBean.process()

generateTranslateTemplates

public void generateTranslateTemplates(AbleFilter inFilt,
                                       AbleFilter outFilt,
                                       java.util.Vector fields)
                                throws AbleException
The next three methods change the default behaviour of the ABLE filters, making them appropriate for Naive Bayes algorithm. Thus, for discrete and categorical attributes, the possible values are converted to consecutive numbers starting from 1 till the number of values. For continuous attributes, the values are discretized, so that they take values from 1 to the number of intervals used for discretization. The class attribute is always discrete or categorical.
Specified by:
generateTranslateTemplates in interface AbleTranslateTemplateProvider
Following copied from interface: com.ibm.able.beans.filter.AbleTranslateTemplateProvider
Parameters:
inFilter - The AbleFilter used to convert incoming data.
outFilter - The AbleFilter used to convert outgoing data.
fields - A vector of AbleFields from which to derive the translation template.
Returns:
An array containing two AbleFilter objectshe translation template.

Copyright

public static java.lang.String Copyright()
Determine the copyright of this class.
Returns:
A String containing this class's copyright statement.


ABLE 2.0.0 07/02/2003 10:25:01

(C) Copyright IBM Corporation 1999, 2003