stella.sensor
Class DerivativeSensor

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by util.rmi.RmiPropertyContainer
                  extended by util.rmi.AbstractRmiCaster
                      extended by stella.sensor.AbstractSensor
                          extended by stella.sensor.TimerTaskSensor
                              extended by stella.sensor.DataSensor
                                  extended by stella.sensor.CumulativeSensor
                                      extended by stella.sensor.PredictiveSensor
                                          extended by stella.sensor.SmoothingSensor
                                              extended by stella.sensor.DerivativeSensor
All Implemented Interfaces:
Cloneable, Remote, Caster, DataCaster, RmiDataCaster, RmiErrorCaster, Cumulating, Deriving, Predicting, Smoothing, Telemetering, ExitCleaning, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying, RmiCaster, RmiPropertyBearing
Direct Known Subclasses:
WeatherSensor

public abstract class DerivativeSensor
extends SmoothingSensor
implements Deriving

A derivating sensor adds the capability of calculating the first derivative of the sensor readings. Because it is generally not advisable to allow the calculation of a numerical derivative from noisy data, this class extends a smoothing sensor. Additionally, calcing derivatives is only provided for Savitzky-Golay smoothing. Note that the smoothing coefficients may (and should!) differ from the smoothing used for the plain readings. In particular, consider using higher polynomial degrees in the Savitzky-Golay algorithm for derivatives!

The properties are scanned for the file name to derive a Savitzky-Golay smoothing filter with the KEY_DERIVE. If the property is not set no derivator is registered. This is one exception to the general rule that the use of default constructors guarantees the proper key to be present in the properties after the construction phase. This is necessary because Map do not allow null keys or values.

Implementation note: This routine relies on heavy conversion from Double objects to double primitive types. If this turns out to be unacceptable slow, replace the Shelf with a double array.

This sensor adds the following properties if they are not set already:

See Also:
Shelf

Nested Class Summary
 
Nested classes/interfaces inherited from class stella.sensor.TimerTaskSensor
TimerTaskSensor.SensorRead
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private static boolean DEFDERIVATIVEADVISE
          The default advisory behaviour.
private static String DEFDERIVE
          The default smoother.
(package private) static DecimalFormat DEFRAWDERIVATIVE
          The default format string for the values.
private  SavitzkyGolaySmoothing derivator
          The smoothing algorithm to use.
protected  Shelf<Double> derive
          Stores the first derivatives.
static String KEY_DERIVATIVEADVISE
          The key defining only advisory functionality if set to true.
static String KEY_DERIVE
          The key mapping to the derivative filter file.
static String KEY_PATH
          The key pointing to the derivative filter dir.
static String KEY_RAWDERIVATIVE
          The key to the raw derivative-data format string.
(package private)  double[] z
          A double arrays.
 
Fields inherited from class stella.sensor.SmoothingSensor
f, g, KEY_SMOOTH, KEY_SMOOTHADVISE
 
Fields inherited from class stella.sensor.PredictiveSensor
KEY_BASE, KEY_CHI, KEY_EXTRAPOLATE, KEY_FUTURE, KEY_PREDICTADVISE, predict
 
Fields inherited from class stella.sensor.CumulativeSensor
KEY_AVERAGE, KEY_MEMORY, KEY_PACK
 
Fields inherited from class stella.sensor.DataSensor
DEFRAWFORMAT, DEFREPORT, DEFSIGMAFORMAT, KEY_RAWFORMAT, KEY_REPORT, KEY_SIGMAFORMAT
 
Fields inherited from class stella.sensor.TimerTaskSensor
KEY_RESPAWN
 
Fields inherited from class stella.sensor.AbstractSensor
KEY_BIND, KEY_BINDNAME, KEY_CONVERT, KEY_DESCRIPTION, KEY_SENSORNAME
 
Fields inherited from class util.rmi.AbstractRmiCaster
ALTERNATEHOST, ALTERNATEPORT, KEY_EXPORTPORT, KEY_REGISTRYHOST, KEY_REGISTRYPORT
 
Fields inherited from class util.PropertyBundles
KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_RESOURCEBUNDLES
 
Fields inherited from class util.PropertyResources
KEY_NOINITONCREATE, localurl, locate, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_URL, urlset
 
Fields inherited from class util.PropertyContainer
KEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR
 
Fields inherited from interface stella.rmi.RmiDataCaster
NAMING_EXTENSION
 
Fields inherited from interface util.PropertySupplying
CONFIG, KEY_CLASS
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Constructor Summary
protected DerivativeSensor(Map<String,String> qualify)
          Constructs a fully-qualified derivative sensor, with a given size of measurements to keep.
Use of this constructor guarantees that the Map keys name and respawn are always set.
 
Method Summary
 void deriveAt(double raw)
          The implementation of the deriving interface.
protected  DataEvent generateDataEvent()
          Takes the last sensor derivative data and adds it to the SmoothDataEvent produced by the parental method.
 NumberFormat getDerivativeFormat()
          Returns the decimal format of the raw derivative value.
 String getDerivativeToggleInfo()
          Returns extra info on a derivative toggle event.
 SavitzkyGolaySmoothing getDerivator()
          Returns the derivator used.
 List<Double> getLastDerivative(int nr)
          The interface method for retrieving the last nr derivatives.
 boolean isDerivativeAdvise()
          Returns true if the derivative functionality of this sensor is only meant for advisory behaviour.
 boolean isDeriving()
          Return true if the derivator object is non-null.
protected  void newData(double raw, Date time)
          Conducts a single measure by calling this class's super method.
 double regetDerive()
          Returns the most-recently added first derivative as a primitive double.
 void registerDerivator(SavitzkyGolaySmoothing deriver)
          This method registers a linear smoothing algorithm for use with this sensor.
 
Methods inherited from class stella.sensor.SmoothingSensor
getLastSmooth, getSmoother, getSmoothToggleInfo, isSmoothAdvise, isSmoothing, regetSmooth, registerSmoother, smoothOne
 
Methods inherited from class stella.sensor.PredictiveSensor
getExtrapolation, getLastPredict, getPredictToggleInfo, isPredictAdvise, isPredicting, isReliable, predictFrom, regetPredict
 
Methods inherited from class stella.sensor.CumulativeSensor
cumulateOne, getLastRaw, getLastTime, getMaxSize, getMemory, getSize
 
Methods inherited from class stella.sensor.DataSensor
addDataListener, addRmiDataListener, conductOneMeasure, exit, getRawFormat, getSigmaFormat, removeDataListener, removeRmiDataListener, report
 
Methods inherited from class stella.sensor.TimerTaskSensor
cancel, equals, getRawToggleInfo, getReading, getRespawn, getTimeOfRead, hashCode, initSensorTimerTask, isReady, readSensor, regetRaw, setTimeOfRead, validReading
 
Methods inherited from class stella.sensor.AbstractSensor
addRmiErrorListener, createSensor, getBindName, getConvert, getSensorDescription, getSensorInitInfo, getSensorName, init, notifyErrorListener, removeRmiErrorListener, setConvert, status, toString
 
Methods inherited from class util.rmi.AbstractRmiCaster
bindAlternate, bindToRegistry, bindToRegistry, bindToRegistry, casterExit, casterExit, getBindName, isValid, unbindFromRegistry, unbindFromRegistry
 
Methods inherited from class util.rmi.RmiPropertyContainer
containsRemoteProperty, getRemoteProperties, getRemoteProperty, setRemoteProperty
 
Methods inherited from class util.PropertyBundles
clone, getLocalized, getLocalized, getLocalizedString, getLocalizedString, loadResource
 
Methods inherited from class util.PropertyResources
createFrom, createFrom, createFrom, getApplet, getAsResources, getLocalClassLoader, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, keyCreate, keyCreate, reload, setApplet
 
Methods inherited from class util.PropertyContainer
augment, augment, augment, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, isNew, parseObject, reload, removeProperty, rescanned, setObject, setProperties, setProperty, stringProperties
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface stella.sensor.Cumulating
cumulateOne, getLastRaw, getLastTime, getMaxSize, getSize, getTimeOfRead, regetRaw
 
Methods inherited from interface util.rmi.RmiCaster
bindToRegistry, isValid, unbindFromRegistry
 
Methods inherited from interface stella.sensor.Telemetering
validReading
 
Methods inherited from interface util.PropertySupplying
defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, parseObject, removeProperty, setObject, setProperty, stringProperties
 
Methods inherited from interface util.ResourceSupplying
getResource, getResourceAsStream, getResources
 

Field Detail

KEY_PATH

public static final String KEY_PATH
The key pointing to the derivative filter dir.

See Also:
Constant Field Values

KEY_DERIVE

public static final String KEY_DERIVE
The key mapping to the derivative filter file.

See Also:
Constant Field Values

KEY_RAWDERIVATIVE

public static final String KEY_RAWDERIVATIVE
The key to the raw derivative-data format string.

See Also:
Constant Field Values

KEY_DERIVATIVEADVISE

public static final String KEY_DERIVATIVEADVISE
The key defining only advisory functionality if set to true.

See Also:
Constant Field Values

DEFDERIVE

private static final String DEFDERIVE
The default smoother. If null no smoother is used as default.


DEFDERIVATIVEADVISE

private static final boolean DEFDERIVATIVEADVISE
The default advisory behaviour.

See Also:
Constant Field Values

DEFRAWDERIVATIVE

static final DecimalFormat DEFRAWDERIVATIVE
The default format string for the values.


derive

protected Shelf<Double> derive
Stores the first derivatives.


derivator

private SavitzkyGolaySmoothing derivator
The smoothing algorithm to use.


z

double[] z
A double arrays. Initialize once, use often.

Constructor Detail

DerivativeSensor

protected DerivativeSensor(Map<String,String> qualify)
Constructs a fully-qualified derivative sensor, with a given size of measurements to keep.
Use of this constructor guarantees that the Map keys name and respawn are always set.

Parameters:
size - The maximum number of measurements to keep.
group - The ThreadGroup this thread belongs to.
name - The name of this thread (sensor).
qualify - The Map object describing this sensor.
Method Detail

newData

protected void newData(double raw,
                       Date time)
Conducts a single measure by calling this class's super method. If no deriving algorithm is specified, the derivative is set to zero. Additionally, as long as the data shelf does not contain enough points to allow deriving, zero is stored the derivator Shelf.

Overrides:
newData in class SmoothingSensor

deriveAt

public void deriveAt(double raw)
The implementation of the deriving interface. This class uses a Savitzky-Golay filter for a first derivative to approximate the derivative. An appropriate filter may be registerd using the registerDerivator(vec_math.SavitzkyGolaySmoothing) method.

Specified by:
deriveAt in interface Deriving
Parameters:
raw - The actual raw reading of the sensor.

regetDerive

public double regetDerive()
Returns the most-recently added first derivative as a primitive double. If no derivative value has been added to the shelf, Double.NaN is returned

Specified by:
regetDerive in interface Deriving

getLastDerivative

public List<Double> getLastDerivative(int nr)
The interface method for retrieving the last nr derivatives.

Specified by:
getLastDerivative in interface Deriving
See Also:
Deriving

registerDerivator

public void registerDerivator(SavitzkyGolaySmoothing deriver)
This method registers a linear smoothing algorithm for use with this sensor. If this algorithm is not causal, or the Shelf sizes are too small, an IndexOutOfBoundsException is thrown.

Parameters:
smoother - The linear smoothing algorithm to use.

getDerivator

public SavitzkyGolaySmoothing getDerivator()
Returns the derivator used.


isDeriving

public boolean isDeriving()
Return true if the derivator object is non-null.

Specified by:
isDeriving in interface Deriving

isDerivativeAdvise

public boolean isDerivativeAdvise()
Returns true if the derivative functionality of this sensor is only meant for advisory behaviour. In this case, bad weather events will only show up in the syslog, but will never produce bad weather events.


getDerivativeFormat

public NumberFormat getDerivativeFormat()
Returns the decimal format of the raw derivative value. Required by Deriving.

Specified by:
getDerivativeFormat in interface Deriving

getDerivativeToggleInfo

public String getDerivativeToggleInfo()
Returns extra info on a derivative toggle event. If no additional info is required, return null.


generateDataEvent

protected DataEvent generateDataEvent()
Takes the last sensor derivative data and adds it to the SmoothDataEvent produced by the parental method. If no derivator is specified, the undisturbed data event is returned. If the CumulativeSensor.KEY_PACK property points to a value greater than one, the data event produced carries the average of the last derivative data.

Overrides:
generateDataEvent in class SmoothingSensor
Returns:
A DerivativeDataEvent