mosaic.sim.neuron
Class PLFunction

java.lang.Object
  |
  +--mosaic.sim.neuron.PLFunction

public class PLFunction
extends java.lang.Object

This class represents a piecewise linear mathematical function in a finite timeframe with a finite number of linear segments. The linear segments are described by their gradients and their begin times and the whole function is defined to start at value 0 and time 0 with gradient 0. All gradients[i] are valid between the times gradientTimes[i] and gradientTimes[i+1]. Therefore the whole function is 0 in the interval [0, gradientTimes[0]]. The last segment, starting at time gradientTimes[numGradients] with gradient[numGradients] is defined to end at that time when the function reaches the value 0. This time can be retrieved by using the method getEndTime();


Inner Class Summary
 class PLFunction.FloatIntPair
          Aargh !
 
Field Summary
 double[] gradients
          The gradients of the linear segments.
 double[] gradientTimes
          The begin times of the linear segments.
 
Constructor Summary
PLFunction(int numSegments)
          The default constructor initializes both arrays with the same length.
 
Method Summary
 double getEndTime()
          Calculates and returns the time when the function reaches 0.
 double getEndTime(double startValue, int numSegments)
          Calculates and returns the time when the function, starting with the given startValue as offset and when restricted to the first numSegments segments, reaches 0.
 PLFunction.FloatIntPair getFinishedSegments(double time, boolean untilNow)
           
 PLFunction.FloatIntPair getFinishedSegments(double startValue, int numSegments, double time, boolean untilNow)
          Returns the value of the function at the time of last gradient change before the given simulation time (computing all linear segments that have ended before the current simulation time).
 double getValueAtTime(double startValue, int numSegments, double time)
          Returns the value of the function at the given time, starting with the given startValue and taking numSegments into account.
 java.lang.String toString()
          Returns the function as string.
 java.lang.String toString(int numSegments)
          Returns the first numSegments linear segments of this function as string.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

gradients

public double[] gradients
The gradients of the linear segments.

gradientTimes

public double[] gradientTimes
The begin times of the linear segments.
Constructor Detail

PLFunction

public PLFunction(int numSegments)
The default constructor initializes both arrays with the same length.
Method Detail

getEndTime

public double getEndTime()
Calculates and returns the time when the function reaches 0.

getEndTime

public double getEndTime(double startValue,
                         int numSegments)
Calculates and returns the time when the function, starting with the given startValue as offset and when restricted to the first numSegments segments, reaches 0.

getFinishedSegments

public PLFunction.FloatIntPair getFinishedSegments(double time,
                                                   boolean untilNow)
See Also:
getFinishedSegments(double startValue, int numSegments, double time, boolean untilNow)

getFinishedSegments

public PLFunction.FloatIntPair getFinishedSegments(double startValue,
                                                   int numSegments,
                                                   double time,
                                                   boolean untilNow)
Returns the value of the function at the time of last gradient change before the given simulation time (computing all linear segments that have ended before the current simulation time). Therefore the difference between the value returned by this method and the current function value is only the last, currently valid linear segment of the function. The method will return the index of the last linear segment that has been used in this computation.
Parameters:
startValue - The start value to use.
numSegments - The number of segments that should be used.
time - The simulation time to be used.
untilNow - Specifies if segments that end exactly at the current simulation time should also be taken into account.

getValueAtTime

public double getValueAtTime(double startValue,
                             int numSegments,
                             double time)
Returns the value of the function at the given time, starting with the given startValue and taking numSegments into account.
Parameters:
startValue - The start value to use.
numSegments - The number of segments that should be used.
time - The simulation time to be used.
See Also:
(double, int, double, boolean)

toString

public java.lang.String toString()
Returns the function as string. Only for debugging purposes.
Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(int numSegments)
Returns the first numSegments linear segments of this function as string. Only for debugging purposes.