wpi.filters
Class EventFilter

java.lang.Object
  extended byweka.filters.Filter
      extended bywpi.filters.EventFilter
All Implemented Interfaces:
weka.core.OptionHandler, java.io.Serializable

public class EventFilter
extends weka.filters.Filter
implements weka.core.OptionHandler

Finds time periods during which events occur in time sequence attribute values. Three events are currently supported: increase, decrease and sustain. A new attribute containing the events found is appended after the last attribute. Valid filter-specific options are:
-A attributes
Specify which attributes to find events in. -I
Find increase events. -D
Find decrease events. -S
Find sustain events. -T
Specify the tolerance to use when including values in events. -N
Specify the minimum required number of values in an event

Version:
$Revision: 0.9 $
Author:
Keith A. Pray (kap@wpi.edu)
See Also:
Serialized Form

Field Summary
protected  java.lang.String attributeString
          The original string for attributes to look for events in
static java.lang.String DECREASE_EVENTS
          The string to append to an attribute's name for decrease events.
private static int DECREASE_INT
           
protected  boolean decreaseEvents
          find decrease events?
static java.lang.String INCREASE_EVENTS
          The string to append to an attribute's name for increase events.
private static int INCREASE_INT
           
protected  boolean increaseEvents
          find increase events?
static int MIN_NUM_VALUES_DEFAULT
          The default min number of values in an event
protected  int minNumValues
          minimum required number of values for events
static char SETBEGIN
           
static char SETDELIMITER
          The delimiters to use for sets of events
static char SETEND
           
static java.lang.String SUSTAIN_EVENTS
          The string to append to an attribute's name for decrease events.
private static int SUSTAIN_INT
           
protected  boolean sustainEvents
          find sustain events?
private  java.util.Vector timeSequenceAttributeVector
          list of time sequence attributes to find events in
protected  double tolerance
          tolerance for events
static double TOLERANCE_DEFAULT
          The default tolerance
 
Fields inherited from class weka.filters.Filter
m_NewBatch
 
Constructor Summary
EventFilter()
           
 
Method Summary
 java.lang.String attributeStringTipText()
           
 boolean batchFinished()
          Signifies that this batch of input to the filter is finished.
 java.lang.String decreaseEventsTipText()
           
protected  void findTimeSequenceAttributes()
          Finds the time sequence attributes in the input format.
 java.util.Vector getAttributes()
          Returns the time sequence attributes to find events in
 java.lang.String getAttributeString()
          Returns the original option for attributes to find events in
 boolean getDecreaseEvents()
          Returns if the filter is set to find decrease events.
private  java.lang.String getEvents(weka.core.Instance instance, java.lang.String attribute, int eventType)
          Finds events of the specified type in the instance for the attribute specified.
 boolean getIncreaseEvents()
          Returns if the filter is set to find increase events.
 int getMinNumValues()
          Returns the minimum required number of values for events
 java.lang.String[] getOptions()
          Gets the current settings of the filter.
 boolean getSustainEvents()
          Returns if the filter is set to find sustain events.
 double getTolerance()
          Returns the tolerance value in use.
 java.lang.String globalInfo()
          Returns a string describing this filter.
 java.lang.String increaseEventsTipText()
           
 boolean input(weka.core.Instance instance)
          Input an instance for filtering.
 java.util.Enumeration listOptions()
          Returns an enumeration describing the available options
static void main(java.lang.String[] argv)
          Main method for testing this class.
 java.lang.String minNumValuesTipText()
           
 void setAttributeString(java.lang.String a)
          Sets the attribute to find events in
 void setDecreaseEvents(boolean b)
          Sets if the filter should find decrease events.
 void setIncreaseEvents(boolean b)
          Sets if the filter should find increase events.
 boolean setInputFormat(weka.core.Instances instanceInfo)
          Sets the format of the input instances.
 void setMinNumValues(int n)
          Sets the minimum required number of values in an event
 void setMinNumValues(java.lang.String n)
          Sets the minimum required number of values in an event
 void setOptions(java.lang.String[] options)
          Parses a list of options for this object.
private  void setOutputFormat()
          Sets the output format.
 void setSustainEvents(boolean b)
          Sets if the filter should find sustain events.
 void setTolerance(double t)
          Sets the event tolerance.
 void setToleranceString(java.lang.String t)
          Sets the event tolerance.
 java.lang.String sustainEventsTipText()
           
 java.lang.String toleranceTipText()
           
 
Methods inherited from class weka.filters.Filter
batchFilterFile, bufferInput, copyStringValues, copyStringValues, filterFile, flushInput, getInputFormat, getInputStringIndex, getOutputFormat, getOutputStringIndex, getStringIndices, inputFormat, isOutputFormatDefined, numPendingOutput, output, outputFormat, outputFormatPeek, outputPeek, push, resetQueue, setOutputFormat, useFilter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INCREASE_EVENTS

public static java.lang.String INCREASE_EVENTS
The string to append to an attribute's name for increase events.


DECREASE_EVENTS

public static java.lang.String DECREASE_EVENTS
The string to append to an attribute's name for decrease events.


SUSTAIN_EVENTS

public static java.lang.String SUSTAIN_EVENTS
The string to append to an attribute's name for decrease events.


INCREASE_INT

private static final int INCREASE_INT
See Also:
Constant Field Values

DECREASE_INT

private static final int DECREASE_INT
See Also:
Constant Field Values

SUSTAIN_INT

private static final int SUSTAIN_INT
See Also:
Constant Field Values

SETDELIMITER

public static char SETDELIMITER
The delimiters to use for sets of events


SETBEGIN

public static char SETBEGIN

SETEND

public static char SETEND

TOLERANCE_DEFAULT

public static double TOLERANCE_DEFAULT
The default tolerance


MIN_NUM_VALUES_DEFAULT

public static int MIN_NUM_VALUES_DEFAULT
The default min number of values in an event


timeSequenceAttributeVector

private java.util.Vector timeSequenceAttributeVector
list of time sequence attributes to find events in


attributeString

protected java.lang.String attributeString
The original string for attributes to look for events in


tolerance

protected double tolerance
tolerance for events


minNumValues

protected int minNumValues
minimum required number of values for events


increaseEvents

protected boolean increaseEvents
find increase events?


decreaseEvents

protected boolean decreaseEvents
find decrease events?


sustainEvents

protected boolean sustainEvents
find sustain events?

Constructor Detail

EventFilter

public EventFilter()
Method Detail

setAttributeString

public void setAttributeString(java.lang.String a)
Sets the attribute to find events in

Parameters:
a - the attribute

getAttributes

public java.util.Vector getAttributes()
Returns the time sequence attributes to find events in

Returns:
a list of the attributes

attributeStringTipText

public java.lang.String attributeStringTipText()

getAttributeString

public java.lang.String getAttributeString()
Returns the original option for attributes to find events in

Returns:
the original option string

setToleranceString

public void setToleranceString(java.lang.String t)
Sets the event tolerance.

Parameters:
t - the percentage by which values can differ and still be included into an event.

setTolerance

public void setTolerance(double t)
Sets the event tolerance.

Parameters:
t - the percentage by which values can differ and still be included into an event.

getTolerance

public double getTolerance()
Returns the tolerance value in use.

Returns:
the tolerance

toleranceTipText

public java.lang.String toleranceTipText()

setMinNumValues

public void setMinNumValues(java.lang.String n)
Sets the minimum required number of values in an event

Parameters:
n - the minimum number of values in an event

setMinNumValues

public void setMinNumValues(int n)
Sets the minimum required number of values in an event

Parameters:
n - the minimum number of values in an event

getMinNumValues

public int getMinNumValues()
Returns the minimum required number of values for events

Returns:
the min number

minNumValuesTipText

public java.lang.String minNumValuesTipText()

setIncreaseEvents

public void setIncreaseEvents(boolean b)
Sets if the filter should find increase events.

Parameters:
b - true to find increase events, false otherwise

getIncreaseEvents

public boolean getIncreaseEvents()
Returns if the filter is set to find increase events.

Returns:
true if increase events are looked for, false otherwise

increaseEventsTipText

public java.lang.String increaseEventsTipText()

setDecreaseEvents

public void setDecreaseEvents(boolean b)
Sets if the filter should find decrease events.

Parameters:
b - true to find decrease events, false otherwise

getDecreaseEvents

public boolean getDecreaseEvents()
Returns if the filter is set to find decrease events.

Returns:
true if decrease events are looked for, false otherwise

decreaseEventsTipText

public java.lang.String decreaseEventsTipText()

setSustainEvents

public void setSustainEvents(boolean b)
Sets if the filter should find sustain events.

Parameters:
b - true to find sustain events, false otherwise

getSustainEvents

public boolean getSustainEvents()
Returns if the filter is set to find sustain events.

Returns:
true if sustain events are looked for, false otherwise

sustainEventsTipText

public java.lang.String sustainEventsTipText()

getEvents

private java.lang.String getEvents(weka.core.Instance instance,
                                   java.lang.String attribute,
                                   int eventType)
Finds events of the specified type in the instance for the attribute specified.

Returns:
  • the events
  • empty string if no events found

setInputFormat

public boolean setInputFormat(weka.core.Instances instanceInfo)
                       throws java.lang.Exception
Sets the format of the input instances.

Parameters:
instanceInfo - an Instances object containing the input instance structure (any values of instances contained in the object are ignored) but in addition to the structure, this filter does require to know the number of instances in the input data set.
Returns:
true if the outputFormat may be collected immediately
Throws:
java.lang.Exception - if the format couldn't be set successfully

setOutputFormat

private void setOutputFormat()
Sets the output format. Takes the buffered input instances and generates valid strings for the new attributes.


findTimeSequenceAttributes

protected void findTimeSequenceAttributes()
Finds the time sequence attributes in the input format. Any string attributes with set delimiters in their value will NOT be interpreted as a time sequence attribute.


input

public boolean input(weka.core.Instance instance)
Input an instance for filtering. Ordinarily the instance is processed and made available for output immediately. Some filters require all instances be read before producing output.

Parameters:
instance - the input instance
Returns:
true if the filtered instance may now be collected with output().
Throws:
java.lang.IllegalStateException - if no input format has been defined.

batchFinished

public boolean batchFinished()
Signifies that this batch of input to the filter is finished.

Returns:
true if there are instances pending output.
Throws:
java.lang.IllegalStateException - if no input structure has been defined.

globalInfo

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

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

listOptions

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

Specified by:
listOptions in interface weka.core.OptionHandler
Returns:
an enumeration of all the available options

setOptions

public void setOptions(java.lang.String[] options)
                throws java.lang.Exception
Parses a list of options for this object. Valid options are:

Specified by:
setOptions in interface weka.core.OptionHandler
Parameters:
options - the list of options as an array of strings -A attributes
Specify the attributes to find events in -I
Find increase events -D
Find decrease events -S
Find sustain events. -T tolerance
The tolerance for event finding -N min number
The minimum required number of values for events
Throws:
java.lang.Exception - if an option is not supported

getOptions

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

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

main

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

Parameters:
argv - should contain arguments to the filter: use -h for help