public class TSLagMaker extends weka.filters.Filter implements weka.filters.SupervisedFilter, Serializable
Modifier and Type | Class and Description |
---|---|
static class |
TSLagMaker.Periodicity
Enum defining periodicity
|
static class |
TSLagMaker.PeriodicityHandler
Helper class to manage time stamp manipulation with respect to various
periodicities.
|
Constructor and Description |
---|
TSLagMaker() |
Modifier and Type | Method and Description |
---|---|
void |
addCustomPeriodic(String customPeriodic)
Add a custom date-derived periodic
|
double |
advanceSuppliedTimeValue(double valueToAdvance)
Utility method to advance a supplied time value by one unit according to
the periodicity set for this LagMaker.
|
boolean |
batchFinished() |
void |
clearCustomPeriodics()
Clear all custom date-derived periodic fields.
|
void |
clearLagHistories()
Clears any history accumulated in the lag creating filters.
|
weka.core.Instances |
createTimeLagCrossProducts(weka.core.Instances insts) |
double |
decrementSuppliedTimeValue(double valueToDecrement) |
static TSLagMaker.PeriodicityHandler |
determinePeriodicity(weka.core.Instances insts,
String timeName,
TSLagMaker.Periodicity userHint)
Utility method that uses heuristics to identify the periodicity of the data
with respect to a time stamp.
|
boolean |
getAddAMIndicator()
Return true if an AM indicator attribute is to be created.
|
boolean |
getAddDayOfMonth()
Return true if a day of the month attribute is to be created.
|
boolean |
getAddDayOfWeek()
Return true if a day of the week attribute is to be created.
|
boolean |
getAddMonthOfYear()
Returns true if a month of the year attribute is to be created.
|
boolean |
getAddNumDaysInMonth()
Return true if a num days in the month attribute is to be created.
|
boolean |
getAddQuarterOfYear()
Returns true if a quarter attribute is to be created.
|
boolean |
getAddWeekendIndicator()
Returns true if a weekend indicator attribute is to be created.
|
boolean |
getAdjustForTrends()
Returns true if we are adjusting for trends via a real or artificial time
stamp.
|
boolean |
getAdjustForVariance()
Returns true if we are adjusting for variance by taking the log of the
target(s).
|
double |
getArtificialTimeStartValue()
Returns the current value of the artificial time stamp.
|
boolean |
getAverageConsecutiveLongLags()
Returns true if consecutive long lagged variables are to be averaged.
|
int |
getAverageLagsAfter()
Return the point after which long lagged variables will be averaged.
|
weka.core.Capabilities |
getCapabilities()
Returns the Capabilities of this filter.
|
double |
getCurrentTimeStampValue()
Returns the current (i.e.
|
Map<String,ArrayList<CustomPeriodicTest>> |
getCustomPeriodics()
Get the date-derived custom periodic attributes in use.
|
double |
getDeltaTime()
Return the difference between time values.
|
List<String> |
getFieldsToLag()
Get the names of the fields to create lagged variables for.
|
String |
getFieldsToLagAsString() |
boolean |
getIncludePowersOfTime()
Get whether to include powers of time in the transformed data
|
boolean |
getIncludeTimeLagProducts()
Get whether to include products between time and the lagged variables
|
String |
getLagRange()
Get the ranges used to fine tune lag selection
|
int |
getMaxLag()
Get the maximum lag to create.
|
int |
getMinLag()
Get the minimum lag to create.
|
int |
getNumConsecutiveLongLagsToAverage()
Get the number of consecutive long lagged variables to average.
|
String[] |
getOptions()
Gets the current settings of the LagMaker.
|
List<String> |
getOverlayFields()
Get overlay fields
|
TSLagMaker.Periodicity |
getPeriodicity()
Gets the Periodicity representing the time stamp in use for this lag maker.
|
String |
getPrimaryPeriodicFieldName()
The name of the primary periodic attribute or null if one hasn't been
specified.
|
boolean |
getRemoveLeadingInstancesWithUnknownLagValues()
Get whether to drop instances at the start of the transformed data where
lag values are unknown/missing
|
String |
getSkipEntries()
Get a list of time units to be 'skipped' - i.e.
|
String |
getTimeStampField()
Get the name of the time stamp field.
|
weka.core.Instances |
getTransformedData(weka.core.Instances insts)
Creates a transformed data set based on the user's settings
|
String |
globalInfo() |
void |
incrementArtificialTimeValue(int increment)
Increment the artificial time value with the supplied incrememt value.
|
boolean |
input(weka.core.Instance instance) |
boolean |
isUsingAnArtificialTimeIndex()
Returns true if an artificial time index is in use.
|
Enumeration<weka.core.Option> |
listOptions()
Returns an enumeration describing the available options.
|
weka.core.Instance |
processInstance(weka.core.Instance source,
boolean incrementTime,
boolean setAnyPeriodic) |
weka.core.Instance |
processInstance(weka.core.Instance source,
boolean incrementTime,
boolean setAnyPeriodic,
boolean temporary)
Process an instance in the original format and produce a transformed
instance as output.
|
weka.core.Instance |
processInstancePreview(weka.core.Instance source,
boolean incrementTime,
boolean setAnyPeriodic) |
void |
reset()
Reset the lag maker.
|
void |
setAddAMIndicator(boolean am)
Set whether to create an AM indicator attribute.
|
void |
setAddDayOfMonth(boolean d)
Set whether to create a day of the month attribute.
|
void |
setAddDayOfWeek(boolean d)
Set whether to create a day of the week attribute.
|
void |
setAddMonthOfYear(boolean m)
Set whether to create a month of the year attribute.
|
void |
setAddNumDaysInMonth(boolean d)
Set whether to create a numeric attribute that holds the number of days in
the month.
|
void |
setAddQuarterOfYear(boolean q)
Set whether to create a quarter attribute.
|
void |
setAddWeekendIndicator(boolean w)
Set whether to create a weekend indicator attribute.
|
void |
setAdjustForTrends(boolean a)
Set whether to adjust for trends or not.
|
void |
setAdjustForVariance(boolean v)
Set whether to adjust for variance in the data by taking the log of the
target(s).
|
void |
setArtificialTimeStartValue(double value)
Set the starting value for the artificial time stamp.
|
void |
setAverageConsecutiveLongLags(boolean avg)
Sets whether to average consecutive long lagged variables.
|
void |
setAverageLagsAfter(int a)
Set at which point consecutive long lagged variables are to be averaged
(default = 2, i.e.
|
void |
setCustomPeriodics(Map<String,ArrayList<CustomPeriodicTest>> custom)
Set the date-derived custom periodic fields to use/compute
|
void |
setFieldsToLag(List<String> names)
Set the names of the fields to create lagged variables for
|
void |
setFieldsToLagAsString(String toLag) |
void |
setIncludePowersOfTime(boolean p)
Set whether to include powers of time in the transformed data
|
void |
setIncludeTimeLagProducts(boolean includeTimeLagProducts)
Set whether to include products between time and the lagged variables
|
boolean |
setInputFormat(weka.core.Instances instanceInfo) |
void |
setLagRange(String lagRange)
Set ranges to fine tune lag selection.
|
void |
setMaxLag(int max)
Set the maximum lag to create (default = 12, i.e.
|
void |
setMinLag(int min)
Set the minimum lag to create (default = 1, i.e.
|
void |
setNumConsecutiveLongLagsToAverage(int c)
Set the number of long lagged variables to average for each averaged
variable created (default = 2, e.g.
|
void |
setOptions(String[] options)
Parses a given list of options.
|
void |
setOverlayFields(List<String> overlayNames)
Set the names of fields in the data that are to be considered "overlay"
fields - i.e.
|
void |
setPeriodicity(TSLagMaker.Periodicity toUse)
Set the periodicity for the data.
|
void |
setPrimaryPeriodicFieldName(String p)
Set the name of a periodic attribute in the data.
|
void |
setRemoveLeadingInstancesWithUnknownLagValues(boolean b)
Set whether to drop instances at the start of the transformed data where
lag values are unknown/missing
|
void |
setSkipEntries(String skipEntries)
Set the list of time units to be 'skipped' - i.e.
|
void |
setTimeStampField(String name)
Set the name of the time stamp field in the data
|
batchFilterFile, debugTipText, doNotCheckCapabilitiesTipText, filterFile, getCapabilities, getCopyOfInputFormat, getDebug, getDoNotCheckCapabilities, getOutputFormat, getRevision, isFirstBatchDone, isNewBatch, isOutputFormatDefined, main, makeCopies, makeCopy, mayRemoveInstanceAfterFirstBatchDone, numPendingOutput, output, outputPeek, postExecution, preExecution, run, runFilter, setDebug, setDoNotCheckCapabilities, toString, useFilter, wekaStaticWrapper
public String globalInfo()
public static TSLagMaker.PeriodicityHandler determinePeriodicity(weka.core.Instances insts, String timeName, TSLagMaker.Periodicity userHint)
insts
- the instances to determine the periodicity fromtimeName
- the name of the time stamp attributeuserHint
- a specific periodicity to defer to. The user should provide
a specific periodicity when the data has non-constant differences
in time between consecutive elements and a skip list will be used
to correct for this. Specifying UNKNOWN as the periodicity here
will result in the heuristic detection routine being applied.public void reset()
public Enumeration<weka.core.Option> listOptions()
listOptions
in interface weka.core.OptionHandler
listOptions
in class weka.filters.Filter
public String[] getOptions()
getOptions
in interface weka.core.OptionHandler
getOptions
in class weka.filters.Filter
public void setOptions(String[] options) throws Exception
setOptions
in interface weka.core.OptionHandler
setOptions
in class weka.filters.Filter
options
- the list of options as an array of stringsException
- if an option is not supportedpublic Map<String,ArrayList<CustomPeriodicTest>> getCustomPeriodics()
public void setCustomPeriodics(Map<String,ArrayList<CustomPeriodicTest>> custom)
custom
- a Map, keyed by field name, of custom date-derived periodic
fields to use.public void addCustomPeriodic(String customPeriodic)
customPeriodic
- the new custom date-derived periodic in textual form.public void clearCustomPeriodics()
public List<String> getFieldsToLag()
@ProgrammaticProperty public void setFieldsToLag(List<String> names) throws Exception
names
- a List of field names for which to create lagged variablesException
- if a problem occurs@OptionMetadata(displayName="Fields to lag", description="1-based index ranges, or, comma-separated list of field names to lag", displayOrder=1) public void setFieldsToLagAsString(String toLag)
public String getFieldsToLagAsString()
public List<String> getOverlayFields()
@ProgrammaticProperty public void setOverlayFields(List<String> overlayNames)
overlayNames
- the names of the fields that are to be considered
"overlay" fieldspublic String getTimeStampField()
@OptionMetadata(displayName="Timestamp field", description="Field (if any) to use as the timestamp", displayOrder=0) public void setTimeStampField(String name)
name
- the name of the time stamp fieldpublic boolean getRemoveLeadingInstancesWithUnknownLagValues()
@OptionMetadata(displayName="Remove instances with unknown lag values", description="Whether to remove leading training instances that contain unknown lag values (ie missing lag values)", displayOrder=7) public void setRemoveLeadingInstancesWithUnknownLagValues(boolean b)
b
- true if leading instances with unknown lag values are to be
removedpublic boolean getAdjustForTrends()
@OptionMetadata(displayName="Adjust for trends", description="Whether to adjust for trends in the data by adding powers of time and time-lag cross-products. If there is no real timestamp in the data then an artificial one will be added.", displayOrder=17) public void setAdjustForTrends(boolean a)
a
- true if we are to adjust for trends via a real or artificial time
stamppublic boolean getIncludeTimeLagProducts()
@OptionMetadata(displayName="Include products of time and lagged variables", description="Include time-lag crossproduct fields", displayOrder=19) public void setIncludeTimeLagProducts(boolean includeTimeLagProducts)
includeTimeLagProducts
- true if the transformed data will include
products of time and lagged variablespublic boolean getIncludePowersOfTime()
@OptionMetadata(displayName="Include powers of time", description="Include fields containing powers of time (^2, ^3)", displayOrder=18) public void setIncludePowersOfTime(boolean p)
p
- true if the transformed data will include powers of timepublic boolean getAdjustForVariance()
@OptionMetadata(displayName="Adjust for variance in lagged variables", description="Adjust for variance in fields being lagged by taking the log", displayOrder=8) public void setAdjustForVariance(boolean v)
v
- true to adjust for variance by taking the log of the target(s).public int getMinLag()
@OptionMetadata(displayName="Minimum lag length", description="The minimum length of lag to create", displayOrder=2) public void setMinLag(int min)
min
- the minimum lag to createpublic int getMaxLag()
@OptionMetadata(displayName="Maximum lag length", description="The maximum length of lag to create", displayOrder=3) public void setMaxLag(int max)
max
- the maximum lag to create.public String getLagRange()
@OptionMetadata(displayName="Lag ranges", description="Optional ranges by which to tune lag selection (eg 2,3,4,7-9)", displayOrder=4) public void setLagRange(String lagRange)
lagRange
- a set of ranges (e.g. 2,3,4,7-9).public boolean getAverageConsecutiveLongLags()
@OptionMetadata(displayName="Average long lags", description="Whether to average consecutive long lagged variables", displayOrder=5) public void setAverageConsecutiveLongLags(boolean avg)
avg
- true if consecutive long lags are to be averaged.public int getAverageLagsAfter()
@OptionMetadata(displayName="Average lags longer than t-x", description="Set at which point consecutive long lagged variables
are to be averaged (default = 2); only has an effect if averaging
of long lagged variables is turned on.", displayOrder=6) public void setAverageLagsAfter(int a)
a
- the point at which to start averaging consecutive long lagged
variables.public int getNumConsecutiveLongLagsToAverage()
@OptionMetadata(displayName="Number of consecutive long lags to average", description="Set the number of long lagged variables to average for each averaged variable created (default = 2)", displayOrder=7) public void setNumConsecutiveLongLagsToAverage(int c)
c
- the number of consecutive long lagged variables to average.public String getPrimaryPeriodicFieldName()
@OptionMetadata(displayName="Primary periodic attribute", description="The name of the primary periodic attribute (if any); this attribute has to be nominal and cyclic", displayOrder=9) public void setPrimaryPeriodicFieldName(String p)
p
- the name of the primary periodic attribute (if any) in the data.public boolean getAddAMIndicator()
@OptionMetadata(displayName="Add AM indicator", description="Add an indicator for AM to the data", displayOrder=10) public void setAddAMIndicator(boolean am)
am
- true if an AM indicator attribute is to be created.public boolean getAddDayOfWeek()
@OptionMetadata(displayName="Add day of the week", description="Add a day of the week field to the data", displayOrder=11) public void setAddDayOfWeek(boolean d)
d
- true if a day of the week attribute is to be created.public boolean getAddDayOfMonth()
@OptionMetadata(displayName="Add day of the month", description="Add a day of the month field to the data", displayOrder=12) public void setAddDayOfMonth(boolean d)
d
- true if a day of the month attribute is to be created.public boolean getAddNumDaysInMonth()
@OptionMetadata(displayName="Add num days in month", description="Add a field that contains the number of days in the month", displayOrder=13) public void setAddNumDaysInMonth(boolean d)
d
- true if a num days in month attribute is to be created.public boolean getAddWeekendIndicator()
@OptionMetadata(displayName="Add weekend indicator", description="Add a weekend indicator to the data", displayOrder=14) public void setAddWeekendIndicator(boolean w)
w
- true if a weekend indicator attribute is to be created.public boolean getAddMonthOfYear()
@OptionMetadata(displayName="Add month of the year", description="Add a month of the year field to the data", displayOrder=15) public void setAddMonthOfYear(boolean m)
m
- true if a month of the year attribute is to be created.public boolean getAddQuarterOfYear()
@OptionMetadata(displayName="Add quarter of the year", description="Add a quarter of the year field to the data", displayOrder=16) public void setAddQuarterOfYear(boolean q)
q
- true if a quarter attribute is to be added.public boolean isUsingAnArtificialTimeIndex()
public double getArtificialTimeStartValue() throws Exception
Exception
- if an artificial time stamp is not being used.@ProgrammaticProperty public void setArtificialTimeStartValue(double value) throws Exception
value
- the value to initialize the artificial time stamp with.Exception
- if an artificial time stamp is not being used.public double getCurrentTimeStampValue() throws Exception
Exception
- if the lag maker is not adjusting for trends or no time
stamp attribute has been specified.public void incrementArtificialTimeValue(int increment)
increment
- the value to increment by.public double getDeltaTime()
public TSLagMaker.Periodicity getPeriodicity()
@OptionMetadata(displayName="Periodicity of the data", description="User hint for the periodicity of the data (ignored when using an artificial time stamp or not adjusting for trends); heuristics are used when set to UNKNOWN", displayOrder=8) public void setPeriodicity(TSLagMaker.Periodicity toUse)
toUse
- the periodicity to usepublic String getSkipEntries()
@OptionMetadata(displayName="Set timestamp skip list", description="Set the list of time units to be \'skipped\' - ie not considered as an increment. E.g. financial markets don\'t trade on the weekend, so the difference between friday closing and the following monday closing is one time unit (and not three). Can accept strings such as \'sat\', \'sunday\', \'jan\', \'august\', or explicit dates (with optional formatting string) such as \'2011-07-04@yyyy-MM-dd\', or integers. Integers are interpretted with respect to the periodicity - e.g. for daily data they are interpreted as the day of the year; for hourly data, hour of the day etc.", displayOrder=20) public void setSkipEntries(String skipEntries)
skipEntries
- a comma separated list of strings, explicit dates and
integers.public weka.core.Instances createTimeLagCrossProducts(weka.core.Instances insts) throws Exception
Exception
public weka.core.Instances getTransformedData(weka.core.Instances insts) throws Exception
insts
- the instances to transformException
- if a problem occurs during the creation of lagged and
auxiliary attributes.public weka.core.Instance processInstance(weka.core.Instance source, boolean incrementTime, boolean setAnyPeriodic) throws Exception
Exception
public weka.core.Instance processInstancePreview(weka.core.Instance source, boolean incrementTime, boolean setAnyPeriodic) throws Exception
Exception
public weka.core.Instance processInstance(weka.core.Instance source, boolean incrementTime, boolean setAnyPeriodic, boolean temporary) throws Exception
source
- an instance in original formatincrementTime
- true if any time stamp value should be incremented
based on the time stamp value from the last instance seen and set
in the outputted instancesetAnyPeriodic
- true if any user-specified periodic value should be
set in the transformed instance based on the value from the last
instance seen.Exception
- if something goes wrong.public void clearLagHistories() throws Exception
Exception
- if something goes wrong.public double advanceSuppliedTimeValue(double valueToAdvance)
valueToAdvance
- the time value to advancepublic double decrementSuppliedTimeValue(double valueToDecrement)
public weka.core.Capabilities getCapabilities()
getCapabilities
in interface weka.core.CapabilitiesHandler
getCapabilities
in class weka.filters.Filter
Capabilities
public boolean setInputFormat(weka.core.Instances instanceInfo) throws Exception
setInputFormat
in class weka.filters.Filter
Exception
public boolean input(weka.core.Instance instance)
input
in class weka.filters.Filter
public boolean batchFinished()
batchFinished
in class weka.filters.Filter
Copyright © 2019 University of Waikato, Hamilton, NZ. All Rights Reserved.