stella.sensor
Class PredictiveSensor

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
All Implemented Interfaces:
Cloneable, Remote, Caster, DataCaster, RmiDataCaster, RmiErrorCaster, Cumulating, Predicting, Telemetering, ExitCleaning, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying, RmiCaster, RmiPropertyBearing
Direct Known Subclasses:
SmoothingSensor

public abstract class PredictiveSensor
extends CumulativeSensor
implements Predicting

A prediciting sensor adds the capability of predicting future sensor readings. This is in particular interesting for deducing bad weather situations ahead from their occurance. Of cause this is not a straight-forward task, so we do not aim at predicting days ahaed, but merely for times comparable to the closing time of the STELLA roof. This class handles this task by utilizing the extrapolating capabilities of the Extrapolation class and its daugther classes. Three keys are needed to correctly adapt this class.

See Also:
Shelf, Extrapolation

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  List<Integer> bases
          The list of extrapolator bases.
private static String DEFBASE
          The default number of past measurements for predicition.
private static double DEFCHI
          The default reliability measure, meaning always reliable.
private static long DEFFUTURE
          The default prediction time span.
private static boolean DEFPREDICTADVISE
          The default advisory behaviour.
private  Extrapolation[] extrapolate
          The extrapolating algorithms to use.
private  int fut
          The number of steps to extrapolate.
static String KEY_BASE
          The key to the list of number of past datas used for prediction.
static String KEY_CHI
          The key to juding the reliability of the prediction.
static String KEY_EXTRAPOLATE
          The key mapping to the extrapolating class.
static String KEY_FUTURE
          The key to the time span to extrapolate.
static String KEY_PREDICTADVISE
          The key defining only advisory functionality if set to true.
private  int maxbase
          The maximum base size.
private  int minbase
          The minimum base size.
protected  Shelf<Double> predict
          Stores the predicted values, i.e.
 
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 PredictiveSensor(Map<String,String> qualify)
          Constructs a fully-qualified predictive sensor.
 
Method Summary
protected  DataEvent generateDataEvent()
          Takes the last sensor predictions and add it to the CumulativeDataEvent produced by the parental method.
 Extrapolation[] getExtrapolation()
          Returns the extrapolating instance used.
 List<Double> getLastPredict(int nr)
          The interface method for retrieving the last nr predicted raw values.
 String getPredictToggleInfo()
          Returns extra info on a smooth toggle event.
 boolean isPredictAdvise()
          Returns true if the predictive functionality of this sensor is only meant for advisory behaviour.
 boolean isPredicting()
          Returns true if the extrapolate object is non-null and enough measurements are already made.
 boolean isReliable()
          Returns a measure if this prediction is trustable.
protected  void newData(double raw, Date time)
          Conducts a single measure by calling this class's super method.
 void predictFrom(double lastraw)
          Predicts from the actual data point to the near future.
 double regetPredict()
          Returns the most-recently added predicted raw value as a primitive double.
 
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_EXTRAPOLATE

public static final String KEY_EXTRAPOLATE
The key mapping to the extrapolating class.

See Also:
Constant Field Values

KEY_BASE

public static final String KEY_BASE
The key to the list of number of past datas used for prediction.

See Also:
Constant Field Values

KEY_FUTURE

public static final String KEY_FUTURE
The key to the time span to extrapolate.

See Also:
Constant Field Values

KEY_CHI

public static final String KEY_CHI
The key to juding the reliability of the prediction.

See Also:
Constant Field Values

KEY_PREDICTADVISE

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

See Also:
Constant Field Values

DEFFUTURE

private static final long DEFFUTURE
The default prediction time span.

See Also:
Constant Field Values

DEFBASE

private static final String DEFBASE
The default number of past measurements for predicition.

See Also:
Constant Field Values

DEFCHI

private static final double DEFCHI
The default reliability measure, meaning always reliable.

See Also:
Constant Field Values

DEFPREDICTADVISE

private static final boolean DEFPREDICTADVISE
The default advisory behaviour.

See Also:
Constant Field Values

predict

protected Shelf<Double> predict
Stores the predicted values, i.e. the near future of the data.


bases

private List<Integer> bases
The list of extrapolator bases. Consits of Integer objects.


minbase

private int minbase
The minimum base size.


maxbase

private int maxbase
The maximum base size.


extrapolate

private Extrapolation[] extrapolate
The extrapolating algorithms to use.


fut

private int fut
The number of steps to extrapolate. Initialized only if extrapolting.

Constructor Detail

PredictiveSensor

protected PredictiveSensor(Map<String,String> qualify)
Constructs a fully-qualified predictive sensor. Use of this constructor guarantees that the KEY_FUTURE and the KEY_BASE are set. Additionally, the extrapolating instance is constructed, if the KEY_EXTRAPOLATE is present and names a valid Extrapolation class. In the latter case, fut is assigned.

Method Detail

newData

protected void newData(double raw,
                       Date time)
Conducts a single measure by calling this class's super method. Additionally a value is predicted and stored in the predictors shelf as soon as its number of base point is reached.

Overrides:
newData in class CumulativeSensor

predictFrom

public void predictFrom(double lastraw)
Predicts from the actual data point to the near future. In fact, the value returned is the average of all extrapolators used. Note that this method can only predict after the required number of measurements KEY_BASE has been made.

Specified by:
predictFrom in interface Predicting
Parameters:
lastraw - The current raw measurement

regetPredict

public double regetPredict()
Returns the most-recently added predicted raw value as a primitive double. If no prediction is possible, Double.NaN is returned.

Specified by:
regetPredict in interface Predicting
Returns:
The predicted raw value or NaN.

getLastPredict

public List<Double> getLastPredict(int nr)
The interface method for retrieving the last nr predicted raw values.

Specified by:
getLastPredict in interface Predicting
Parameters:
nr - The number of predicted values to be retrieved.
Returns:
A list of Doubles.
See Also:
Predicting

getExtrapolation

public Extrapolation[] getExtrapolation()
Returns the extrapolating instance used.


isPredicting

public boolean isPredicting()
Returns true if the extrapolate object is non-null and enough measurements are already made.

Specified by:
isPredicting in interface Predicting

isPredictAdvise

public boolean isPredictAdvise()
Returns true if the predictive 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.


isReliable

public boolean isReliable()
Returns a measure if this prediction is trustable. In this version, the residuals of all extrapolators of the linear fit are checked if they lie beneath a certain threshold, defined with the KEY_CHI key. If this key points to zero, the sensor is trusted always, otherwise the χ² per data point must lie below this value for trustworthyness.
Note that the data should be set prior to calling this method.

Specified by:
isReliable in interface Predicting

getPredictToggleInfo

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


generateDataEvent

protected DataEvent generateDataEvent()
Takes the last sensor predictions and add it to the CumulativeDataEvent produced by the parental method. If no extrapolators are specified, the undisturbed data event, a CumulativeDataEvent 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 predictions.

Overrides:
generateDataEvent in class CumulativeSensor
Returns:
A PredictiveDataEvent