Class TimeGraph

java.lang.Object
  |
  +--TimeGraph

class TimeGraph
extends java.lang.Object
implements Solvable

Implements a circular buffer, intended to be used where there is a constant stream of data (such as observations over time).


Field Summary
protected  double max
          The largest data value seen so far.
protected  int maxIndex
          The index of the largest data value seen so far.
protected  double[] observations
          The buffer of observations
protected  int pos
          The current position in the buffer.
protected  int skip
          The number of observations to ignore before an observation is used.
protected  int skipRatio
          The number of observations that will be ignored for every one used.
 
Constructor Summary
TimeGraph(int obsCount)
          Creates a new TimeGraph
 
Method Summary
 void addObservation(double value)
          Adds a value to the list of observations.
 double getCurrentPos(double x0, double step)
          Returns the current "time".
 double[] getObservations()
          Returns all observations.
 int getSkipRatio()
          Returns the number of observations that will be ignored for every one used.
 double indexToX(int index, double min, double max)
          Converts an array index to an x coordinate, given the size of the interval into which all coordinates should fall.
 void reset()
          Clears all observations, and returns the position marker to the start of the buffer.
 void setSkipRatio(int i)
          Sets the number of observations that will be ignored for every one used.
 void solve(double x0, double step, double[] vals)
          The x0 and step parameters are ignored; this method will always return the array of observations.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

maxIndex

protected int maxIndex
The index of the largest data value seen so far. This index will still point to the position where the observation occurred, even if the actual data has been replaced by newer observations.

max

protected double max
The largest data value seen so far. There is no guarantee that this value is still in the buffer, and has not been replaced by a newer observation.

skipRatio

protected int skipRatio
The number of observations that will be ignored for every one used. This is useful as a simple control for the sampling rate.

pos

protected int pos
The current position in the buffer.

skip

protected int skip
The number of observations to ignore before an observation is used. This value will be decrement as observations are discarded, and reset to skipRatio when a value is used.

observations

protected double[] observations
The buffer of observations
Constructor Detail

TimeGraph

public TimeGraph(int obsCount)
Creates a new TimeGraph
Parameters:
obsCount - The size of the "history" of observations
Method Detail

addObservation

public void addObservation(double value)
Adds a value to the list of observations. If the buffer is full, the oldest observation will be replaced by this one.

solve

public void solve(double x0,
                  double step,
                  double[] vals)
The x0 and step parameters are ignored; this method will always return the array of observations.
Specified by:
solve in interface Solvable
Throws:
java.lang.RuntimeException - If the size of the supplied array does not match that of the buffer

getCurrentPos

public double getCurrentPos(double x0,
                            double step)
Returns the current "time".
Parameters:
x0 - The "time" of the first observation
step - The "time" between observations
Returns:
x0 + step*pos

reset

public void reset()
Clears all observations, and returns the position marker to the start of the buffer.

indexToX

public double indexToX(int index,
                       double min,
                       double max)
Converts an array index to an x coordinate, given the size of the interval into which all coordinates should fall.
Parameters:
index - The array index
min - The minimum bound of the interval
max - The maximum bound of the interval

getObservations

public double[] getObservations()
Returns all observations. The observations will be in sequence, save for a discontinuity at the "now" position.

getSkipRatio

public int getSkipRatio()
Returns the number of observations that will be ignored for every one used. This is useful as a simple control for the sampling rate.

setSkipRatio

public void setSkipRatio(int i)
Sets the number of observations that will be ignored for every one used. This is useful as a simple control for the sampling rate.