wpi.filters
Class TimeGranularityFilter

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

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

Creates new attributes for the chosen time granularities. Each new attribute specifies as an event set the periods of time during which a granularity exists. For example if the base time unit of a time line was days and the chosen granularity was a weekend the new attribute weekend-granularity would have each Saturday and Sunday noted as an event. Additionally, each granularity can be numbered or unnumbered. That is, each weekend could be specified as an event in the weekend-granularity attribute, or a new attribute can be created for each weekend; weekend-granularity-1, weekend-granularity-2, and so on. Each of these attributes would have at most 1 event for each instance. Hopefully one day this class will be extended to work with time lines that use explicit dates but for now it will work with time lines that use an integer format where the user knows the implicit units of time it represents. Valid filter-specific options are:
-N
Specifies granularities will be numbered. -H
Specify the half granularity. That is the time line for each instance is divided in half. Each instance will contain 2 half granularities. -U
Specify a user defined granularity where a number of units on the time line signifies the granularity. If the user chooses 10 then the granularity is 10 units. The new attribute(s) will be named for this value.

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

Field Summary
private static int debug
          Specifies debug info level 0: no debug info 1: input to methods 2: and output from methods 3: and all sorts of stuff
private  java.util.Vector eventAttributeVector
          list of time sequence attributes to find events in
static java.lang.String HALF_GRANULARITY
          The string for Half granularity attribute name.
private static int HALF_INT
           
protected  boolean halfGranularity
          create half granularity?
private  double maxTime
          For the numbered granularities we need to know the maximum time noted in the dataset.
protected  boolean numberedGranularities
          numbered option
private  java.lang.String[] numberedUserAttributeStringArray
          names for the attributes of the user numbered granularities
static char SETBEGIN
           
static char SETDELIMITER
          The delimiters to use for sets of events
static char SETEND
           
static java.lang.String USER_GRANULARITY
          The string to append for user defined granularity attribute name.
private static int USER_INT
           
protected  int userGranularitySize
          size of user defined granularity
 
Fields inherited from class weka.filters.Filter
m_NewBatch
 
Constructor Summary
TimeGranularityFilter()
           
 
Method Summary
 boolean batchFinished()
          Signifies that this batch of input to the filter is finished.
private  void fillNumberedUserAttributeStringArray()
          Creates a list of attribute names for the user specified granularity when the numbered granularities option is set.
protected  void findEventAttributes()
          Finds the event attributes in the input format.
private  java.lang.String[] getGranularityEvents(weka.core.Instance instance, int granularityType)
          Finds the granularities for the instance specified.
 boolean getHalfGranularity()
          Returns if the filter should create the half granularity.
 boolean getNumberedGranularities()
          Returns if the filter should create numbered granularities.
 java.lang.String[] getOptions()
          Gets the current settings of the filter.
 int getUserGranularitySize()
          Returns the user granularity size
 java.lang.String globalInfo()
          Returns a string describing this filter.
 java.lang.String halfGranularityTipText()
           
 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 numberedGranularitiesTipText()
           
 void setHalfGranularity(boolean b)
          Sets if the filter should create the half granularity.
 boolean setInputFormat(weka.core.Instances instanceInfo)
          Sets the format of the input instances.
 void setNumberedGranularities(boolean b)
          Sets if the filter should create numbered granularities.
 void setOptions(java.lang.String[] options)
          Parses a list of options for this object.
private  void setOutputFormat()
          Sets the output format.
 void setUserGranularitySize(int n)
          Sets the size of the user defined granularity in terms of time line units.
 void setUserGranularitySize(java.lang.String n)
          Sets the size of the user defined granularity in terms of time line units.
 java.lang.String userGranularitySizeTipText()
           
 
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

HALF_GRANULARITY

public static java.lang.String HALF_GRANULARITY
The string for Half granularity attribute name.


USER_GRANULARITY

public static java.lang.String USER_GRANULARITY
The string to append for user defined granularity attribute name.


HALF_INT

private static final int HALF_INT
See Also:
Constant Field Values

USER_INT

private static final int USER_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

maxTime

private double maxTime
For the numbered granularities we need to know the maximum time noted in the dataset.


eventAttributeVector

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


numberedGranularities

protected boolean numberedGranularities
numbered option


halfGranularity

protected boolean halfGranularity
create half granularity?


userGranularitySize

protected int userGranularitySize
size of user defined granularity


numberedUserAttributeStringArray

private java.lang.String[] numberedUserAttributeStringArray
names for the attributes of the user numbered granularities


debug

private static final int debug
Specifies debug info level 0: no debug info 1: input to methods 2: and output from methods 3: and all sorts of stuff

See Also:
Constant Field Values
Constructor Detail

TimeGranularityFilter

public TimeGranularityFilter()
Method Detail

setUserGranularitySize

public void setUserGranularitySize(java.lang.String n)
Sets the size of the user defined granularity in terms of time line units.

Parameters:
n - the number of units

setUserGranularitySize

public void setUserGranularitySize(int n)
Sets the size of the user defined granularity in terms of time line units.

Parameters:
n - the number of units

getUserGranularitySize

public int getUserGranularitySize()
Returns the user granularity size

Returns:
the number of units

userGranularitySizeTipText

public java.lang.String userGranularitySizeTipText()

setHalfGranularity

public void setHalfGranularity(boolean b)
Sets if the filter should create the half granularity.

Parameters:
b - true to define half granularity, false otherwise

getHalfGranularity

public boolean getHalfGranularity()
Returns if the filter should create the half granularity.

Returns:
true to define half granularity, false otherwise

halfGranularityTipText

public java.lang.String halfGranularityTipText()

setNumberedGranularities

public void setNumberedGranularities(boolean b)
Sets if the filter should create numbered granularities.

Parameters:
b - true to create numbered granularities, false otherwise

getNumberedGranularities

public boolean getNumberedGranularities()
Returns if the filter should create numbered granularities.

Returns:
true to define numbered granularities, false otherwise

numberedGranularitiesTipText

public java.lang.String numberedGranularitiesTipText()

getGranularityEvents

private java.lang.String[] getGranularityEvents(weka.core.Instance instance,
                                                int granularityType)
Finds the granularities for the instance specified. If the numbered option is selected a string for each value is returned.

Returns:
  • the granularity events
  • empty array 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.


findEventAttributes

protected void findEventAttributes()
Finds the event attributes in the input format.


fillNumberedUserAttributeStringArray

private void fillNumberedUserAttributeStringArray()
Creates a list of attribute names for the user specified granularity when the numbered granularities option is set.


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 - attributes
Specify the attributes to find events in -N
Specifies granularities will be numbered. -H
Specify the half granularity. That is the time line for each instance is divided in half. Each instance will contain 2 half granularities. -U
Specify a user defined granularity where a number of units on the time line signifies the granularity. If the user chooses 10 then the granularity is 10 units. The new attribute(s) will be named for this value.
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