org.spaceroots.mantissa.functions.vectorial
Class ComputableFunctionSampler

java.lang.Object
  extended byorg.spaceroots.mantissa.functions.vectorial.ComputableFunctionSampler
All Implemented Interfaces:
SampledFunction, Serializable

public class ComputableFunctionSampler
extends Object
implements SampledFunction, Serializable

This class is a wrapper allowing to sample a ComputableFunction.

The sample produced is a regular sample. It can be specified by several means :

In the latter case, the step can optionaly be adjusted in order to have the last point exactly at the upper bound of the range.

The sample points are computed on demand, they are not stored. This allow to use this method for very large sample with little memory overhead. The drawback is that if the same sample points are going to be requested several times, they will be recomputed each time. In this case, the user should consider storing the points by some other means.

Version:
$Id: ComputableFunctionSampler.java 1666 2005-12-15 16:37:55Z luc $
Author:
L. Maisonobe
See Also:
ComputableFunction, Serialized Form

Constructor Summary
ComputableFunctionSampler(ComputableFunction function, double[] range, double step, boolean adjustStep)
          Constructor.
ComputableFunctionSampler(ComputableFunction function, double[] range, int n)
          Constructor.
ComputableFunctionSampler(ComputableFunction function, double begin, double step, int n)
          Constructor.
 
Method Summary
 int getDimension()
          Get the dimension of the vectorial values of the function.
 VectorialValuedPair samplePointAt(int index)
          Get the abscissa and value of the sample at the specified index.
 int size()
          Get the number of points in the sample.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ComputableFunctionSampler

public ComputableFunctionSampler(ComputableFunction function,
                                 double begin,
                                 double step,
                                 int n)
Constructor. Build a sample from an ComputableFunction. Beware of the classical off-by-one problem ! If you want to have a sample like this : 0.0, 0.1, 0.2 ..., 1.0, then you should specify step = 0.1 and n = 11 (not n = 10).

Parameters:
begin - beginning of the range (will be the abscissa of the first point)
step - step between points
n - number of points

ComputableFunctionSampler

public ComputableFunctionSampler(ComputableFunction function,
                                 double[] range,
                                 int n)
Constructor. Build a sample from an ComputableFunction.

Parameters:
range - abscissa range (from range [0] to range [1])
n - number of points

ComputableFunctionSampler

public ComputableFunctionSampler(ComputableFunction function,
                                 double[] range,
                                 double step,
                                 boolean adjustStep)
Constructor. Build a sample from an ComputableFunction.

Parameters:
range - abscissa range (from range [0] to range [1])
step - step between points
adjustStep - if true, the step is reduced in order to have the last point of the sample exactly at range [1], if false the last point will be between range [1] - step and range [1]
Method Detail

size

public int size()
Description copied from interface: SampledFunction
Get the number of points in the sample.

Specified by:
size in interface SampledFunction
Returns:
number of points in the sample

getDimension

public int getDimension()
Description copied from interface: SampledFunction
Get the dimension of the vectorial values of the function.

Specified by:
getDimension in interface SampledFunction
Returns:
dimension

samplePointAt

public VectorialValuedPair samplePointAt(int index)
                                  throws ArrayIndexOutOfBoundsException,
                                         FunctionException
Description copied from interface: SampledFunction
Get the abscissa and value of the sample at the specified index.

Specified by:
samplePointAt in interface SampledFunction
Parameters:
index - index in the sample, should be between 0 and SampledFunction.size() - 1
Returns:
abscissa and value of the sample at the specified index
Throws:
FunctionException - if an eventual underlying function throws one
ArrayIndexOutOfBoundsException - if the index is wrong


Copyright © 2001-2007 Luc Maisonobe. All Rights Reserved.