org.openuat.sensors
Class TimeSeries

java.lang.Object
  extended by org.openuat.sensors.TimeSeries
All Implemented Interfaces:
SamplesSink

public class TimeSeries
extends java.lang.Object
implements SamplesSink

This class represents a possibly multi-dimensional time series of a single sensor. It computes simply statistical values, can distinguish active from passive segments, and offers some convenience methods.

Version:
1.0
Author:
Rene Mayrhofer

Nested Class Summary
static interface TimeSeries.Parameters
          This interface represents the parameters that must be reasonably set when initializing a time series that reads from sensors instead of from other time series.
 
Constructor Summary
TimeSeries(int windowSize)
          Initializes the time series circular buffer with the specified window size.
 
Method Summary
 void addNextStageSink(SamplesSink sink)
          Registers a sink, which will receive all new values as they are sampled.
 void addSample(double sample, int sampleNum)
          Adds a new sample to the time series in-memory buffer, updates statistics and may forward to the next stage.
 double getActiveVarianceThreshold()
          Gets the current value of activeVarianceThreshold.
 boolean getDifferencing()
          Gets the current value of differencing.
 double getMultiplicator()
          Gets the current value of multiplicator.
 double getOffset()
          Gets the current value of offset.
 double[] getSamplesInWindow()
          Returns all samples currently contained in the time window.
 boolean getSubtractTotalMean()
          Gets the current value of subtractTotalMean.
 boolean getSubtractWindowMean()
          Gets the current value of subtractWindowMean.
 double getTotalMean()
          Returns the mean over all values added to this time series since its construction.
 double getTotalVariance()
          Returns the variance over all values added to this time series since its construction.
 double getWindowMean()
          Returns the mean over all values in the time series buffer, i.e. the last window size samples.
 double getWindowVariance()
          Returns the variance over all values in the time series buffer, i.e. the last window size samples.
 boolean removeSink(SamplesSink sink)
          Removes a previously registered sink.
 void reset()
          Resets the time series to the state as created when freshly constructing it.
 void segmentEnd(int indexNotUsed)
          Dummy implementation of SamplesSink.segmentEnd.
 void segmentStart(int indexNotUsed)
          Dummy implementation of SamplesSink.segmentStart.
 void setActiveVarianceThreshold(double activeVarianceThreshold)
          Sets the current value of activeVarianceThreshold.
 void setDifferencing(boolean differencing)
          Sets the current value of differencing.
 void setMultiplicator(double multiplicator)
          Sets the current value of multiplicator.
 void setOffset(double offset)
          Sets the current value of offset.
 void setParameters(TimeSeries.Parameters pars)
          Sets both the multiplicator and the offset according to the given parameters object.
 void setSubtractTotalMean(boolean subtractTotalMean)
          Sets the current value of subtractTotalMean.
 void setSubtractWindowMean(boolean subtractWindowMean)
          Sets the current value of subtractWindowMean.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimeSeries

public TimeSeries(int windowSize)
Initializes the time series circular buffer with the specified window size.

Parameters:
windowSize - Specifies the number of past samples kept in memory and used for computing the window mean and variance.
Method Detail

reset

public void reset()
Resets the time series to the state as created when freshly constructing it. However, it does not reset the parameters offset, multiplicator, subtractWindowMean, and subtractTotalMean.


addSample

public void addSample(double sample,
                      int sampleNum)
Adds a new sample to the time series in-memory buffer, updates statistics and may forward to the next stage.

Specified by:
addSample in interface SamplesSink
Parameters:
sample - The sample value to add.
sampleNum - The number of the sample to add. As this class keeps internal count of how many samples have already been added, this is used for checking that all samples are received and no duplicates happen. index is assumed to start at 0.

segmentStart

public void segmentStart(int indexNotUsed)
Dummy implementation of SamplesSink.segmentStart. Does nothing.

Specified by:
segmentStart in interface SamplesSink
Parameters:
indexNotUsed - The index at which the active segment starts.

segmentEnd

public void segmentEnd(int indexNotUsed)
Dummy implementation of SamplesSink.segmentEnd. Does nothing.

Specified by:
segmentEnd in interface SamplesSink
Parameters:
indexNotUsed - The index at which the active segment ends.

addNextStageSink

public void addNextStageSink(SamplesSink sink)
Registers a sink, which will receive all new values as they are sampled.

Parameters:
sink - The sink to push new pre-processed samples to.

removeSink

public boolean removeSink(SamplesSink sink)
Removes a previously registered sink.

Parameters:
sink - The sink to stop pushing samples to.
Returns:
true if removed, false if not (i.e. if it has not been added previously).

getTotalMean

public double getTotalMean()
Returns the mean over all values added to this time series since its construction.


getTotalVariance

public double getTotalVariance()
Returns the variance over all values added to this time series since its construction.


getWindowMean

public double getWindowMean()
Returns the mean over all values in the time series buffer, i.e. the last window size samples.


getWindowVariance

public double getWindowVariance()
Returns the variance over all values in the time series buffer, i.e. the last window size samples.


getSamplesInWindow

public double[] getSamplesInWindow()
Returns all samples currently contained in the time window. These are already normalized.


getOffset

public double getOffset()
Gets the current value of offset. This will be applied to all incoming values before they are stored in the buffer, i.e. all consecutive processing steps.

Returns:
The current value of offset.
See Also:
offset

setOffset

public void setOffset(double offset)
Sets the current value of offset. This will be applied to all incoming values before they are stored in the buffer, i.e. all consecutive processing steps.

Parameters:
offset - The current value of offset.
See Also:
offset

getMultiplicator

public double getMultiplicator()
Gets the current value of multiplicator. This will be applied to all incoming values before they are stored in the buffer, i.e. all consecutive processing steps.

Returns:
The current value of multiplicator.
See Also:
multiplicator

setMultiplicator

public void setMultiplicator(double multiplicator)
Sets the current value of multiplicator. This will be applied to all incoming values before they are stored in the buffer, i.e. all consecutive processing steps.

Parameters:
multiplicator - The current value of multiplicator.
See Also:
multiplicator

getSubtractWindowMean

public boolean getSubtractWindowMean()
Gets the current value of subtractWindowMean.

Returns:
The current value of subtractWindowMean.
See Also:
subtractWindowMean

setSubtractWindowMean

public void setSubtractWindowMean(boolean subtractWindowMean)
Sets the current value of subtractWindowMean.

Parameters:
subtractWindowMean - The current value of subtractWindowMean.
See Also:
subtractWindowMean

getSubtractTotalMean

public boolean getSubtractTotalMean()
Gets the current value of subtractTotalMean.

Returns:
The current value of subtractTotalMean.
See Also:
subtractTotalMean

setSubtractTotalMean

public void setSubtractTotalMean(boolean subtractTotalMean)
Sets the current value of subtractTotalMean.

Parameters:
subtractTotalMean - The current value of subtractTotalMean.
See Also:
subtractTotalMean

getDifferencing

public boolean getDifferencing()
Gets the current value of differencing.

Returns:
The current value of differencing.
See Also:
differencing

setDifferencing

public void setDifferencing(boolean differencing)
Sets the current value of differencing.

Parameters:
differencing - The current value of differencing.
See Also:
differencing

getActiveVarianceThreshold

public double getActiveVarianceThreshold()
Gets the current value of activeVarianceThreshold. Note that this threshold applies to the normalized, not the original value range.

Returns:
The current value of activeVarianceThreshold.
See Also:
activeVarianceThreshold

setActiveVarianceThreshold

public void setActiveVarianceThreshold(double activeVarianceThreshold)
Sets the current value of activeVarianceThreshold. Note that this threshold applies to the normalized, not the original value range.

Parameters:
activeVarianceThreshold - The current value of activeVarianceThreshold.
See Also:
activeVarianceThreshold

setParameters

public void setParameters(TimeSeries.Parameters pars)
Sets both the multiplicator and the offset according to the given parameters object.

Parameters:
pars - An object that can be queried for the values to be set.


2005-2009, Rene Mayrhofer.