Overview | Package | Class | Use | Tree | Serialized | Deprecated | Index | Help
| ABLE 2.3.0 07/13/2005 14:21:00
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.ibm.able.beans.knn
Class AbleKnn

    java.lang.Object
      com.ibm.able.AbleObject
          com.ibm.able.beans.knn.AbleKnn

All Implemented Interfaces:
  AbleBean, AbleDataBufferManager, AbleEventListener, AbleEventListenerManager, AbleEventQueueManager, AbleEventQueueProcessor, AblePropertyChangeManager, AbleSerializable, AbleTranslateTemplateProvider, java.io.Serializable

public class AbleKnn
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` | `PropertyK`
`static int` | `PropertyKId`
`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, properties, propertyConnectionMgr, sourceBufferConnections, state, stateChgSupport, trace`

Constructor Summary
`AbleKnn()` Default constructor.
`AbleKnn(java.lang.String aName)` Construct a knn bean with specified name.
`AbleKnn(java.lang.String aName, int k)` Construct a network with specified name and architecture.

Method Summary
`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 k-NN algorithm.
`double` | `getAccuracy()` Get the accuracy.
`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.
`double` | `getError()` Get the error.
`double[]` | `getInNum()`
`int` | `getK()` Get k parameter.
`int` | `getKnnMode()` Get the current operating mode of the network.
`double` | `getMajorityClass(java.util.Hashtable kClosestClasses)` Given a Hashtable having all the class values as keys and the number of the nearest neighbors falling in each class as values, get the majority class (the class containing most of those k nearest neighbors).
`int` | `getNumAttributes()` Get numAttr parameter.
`int` | `getNumClasses()` Get numClasses parameter.
`long` | `getNumCorrectTestExamples()` Get the number of correctly classified test examples.
`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 knn bean.
`protected void` | `setDefaults()` Set up the event queue behavior.
`void` | `setK(int newK)` Set the k parameter for k-NN bean.
`void` | `setKnnMode(int mode)` Set the operating mode of the network.
`void` | `setModelParameters(long newRec, int newAttr, int newCl)` Set numRecords, numAttributes, numClasses parameters.

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, getInputBufferAsString, getInputBufferAsStringArray, getInputBufferContents, getLogger, getName, getOutputBuffer, getOutputBuffer, getOutputBufferAsString, getOutputBufferAsStringArray, getOutputBufferContents, getParent, getProperties, getProperty, getPropertyChangeListeners, 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, removeProperty, 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, setProperties, setProperty, 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.

### PropertyKId

    public static final int PropertyKId

See Also:
  Constant Field Values

### PropertyK

    public static final java.lang.String PropertyK

See Also:
  Constant Field Values

### 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.

  See Also:
    Constant Field Values

### TEST

    public static final int TEST

  Test mode performance is tested (errors are computed).

  See Also:
    Constant Field Values

### RUN

    public static final int RUN

  Application or Run mode output is produced.

  See Also:
    Constant Field Values

### MODE_NAMES

    public static final java.lang.String[] MODE_NAMES

  Labels for the train, test and run modes for GUI use.

Constructor Detail

### AbleKnn

    public AbleKnn()
            throws AbleException

  Default constructor.

### AbleKnn

    public AbleKnn(java.lang.String aName)
            throws AbleException

  Construct a knn bean with specified name.

Parameters:
  `aName` - The object name .

### AbleKnn

    public AbleKnn(java.lang.String aName,
                   int k)
            throws AbleException

  Construct a network with specified name and architecture.

Parameters:
  `aName` - The object name

  `k` - The k-NN parameter .

Method Detail

### setDefaults

    protected void setDefaults()
                        throws AbleException

  Set up the event queue behavior. No timer processing and no asynch event processing.

  Throws:
    `AbleException`

### getInNum

    public double[] getInNum()

### getOutNum

    public double[] getOutNum()

### getKnnMode

    public int getKnnMode()

  Get the current operating mode of the network.

  Returns:
    int.

### setKnnMode

    public void setKnnMode(int mode)

  Set the operating mode of the network.

  Parameters:
    `mode` - The current operating mode, train/test/run

### setModelParameters

    public void setModelParameters(long newRec,
                                   int newAttr,
                                   int newCl)

  Set numRecords, numAttributes, numClasses parameters.

### setK

    public void setK(int newK)
              throws AbleException

  Set the k parameter for k-NN bean. Also fire a propertyChange event to notify any propertyChange listeners

  Parameters:
    `newK` - int that defines the k-NN parameter
  Throws:
    `AbleException`

### getK

    public int getK()

  Get k 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.

  Specified by:
    `init` in interface `AbleBean`
  Overrides:
    `init` in class `AbleObject`
  Throws:
    `AbleException` - If an error occurs.
  See Also:
    `AbleObject.startEnabledEventProcessing()`

### reset

    public void reset()
               throws AbleException

  Reset the knn bean.

  Specified by:
    `reset` in interface `AbleBean`
  Overrides:
    `reset` in class `AbleObject`
  Throws:
    `AbleException` - If an error occurs.
  See Also:
    `AbleBean.reset()`

### getMajorityClass

    public double getMajorityClass(java.util.Hashtable kClosestClasses)

  Given a Hashtable having all the class values as keys and the number of the nearest neighbors falling in each class as values, get the majority class (the class containing most of those k nearest neighbors).

### 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.

  Specified by:
    `process` in interface `AbleBean`
  Overrides:
    `process` in class `AbleObject`
  Throws:
    `AbleException`
  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 k-NN 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 scaled to take values into [0,1] interval. The class attribute is always discrete or categorical.

  Specified by:
    `generateTranslateTemplates` in interface `AbleTranslateTemplateProvider`
  Parameters:
    `inFilt` - The AbleFilter used to convert incoming data.
    `outFilt` - 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.
  Throws:
    `AbleException`

Overview | Package | Class | Use | Tree | Serialized | Deprecated | Index | Help
| ABLE 2.3.0 07/13/2005 14:21:00
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

(C) Copyright IBM Corporation 1999, 2005