org.jscience.mathematics.analysis
Class PrimitiveMappingNDSampler

java.lang.Object
  extended by org.jscience.mathematics.analysis.PrimitiveMappingNDSampler
All Implemented Interfaces:
java.io.Serializable, SampledMapping

public class PrimitiveMappingNDSampler
extends java.lang.Object
implements SampledMapping, java.io.Serializable

This class is a wrapper allowing to sample a PrimitiveMappingND.

Warning: this class is misleading since it provides SamplerMapping implementation only for mappings of 1 parameter to n parameters, although this is what we expect for use in integration package. Perhaps a better name would be PrimitiveMapping1ToNDSampler.

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.

See Also:
PrimitiveMapping, Serialized Form

Constructor Summary
PrimitiveMappingNDSampler(PrimitiveMappingND function, int dim, double[] range, double step, boolean adjustStep)
          Constructor.
PrimitiveMappingNDSampler(PrimitiveMappingND function, int dim, double[] range, int n)
          Constructor.
PrimitiveMappingNDSampler(PrimitiveMappingND function, int dim, double begin, double step, int n)
          Constructor.
 
Method Summary
 int getSampledDimension()
           
 int numInputDimensions()
          Get the dimension of the input values of the function.
 int numOutputDimensions()
          Get the dimension of the output values of the function.
 ValuedPair 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

PrimitiveMappingNDSampler

public PrimitiveMappingNDSampler(PrimitiveMappingND function,
                                 int dim,
                                 double begin,
                                 double step,
                                 int n)
Constructor.

Build a sample from an PrimitiveMapping. 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:
dim - the dimension on which to sample data from (should be between 0 and numInputDimension() - 1
begin - beginning of the range (will be the abscissa of the first point)
step - step between points
n - number of points

PrimitiveMappingNDSampler

public PrimitiveMappingNDSampler(PrimitiveMappingND function,
                                 int dim,
                                 double[] range,
                                 int n)
Constructor. Build a sample from an PrimitiveMapping.

Parameters:
dim - the dimension on which to sample data from (should be between 0 and numInputDimension() - 1
range - abscissa range (from range [0] to range [1])
n - number of points

PrimitiveMappingNDSampler

public PrimitiveMappingNDSampler(PrimitiveMappingND function,
                                 int dim,
                                 double[] range,
                                 double step,
                                 boolean adjustStep)
Constructor. Build a sample from an PrimitiveMapping.

Parameters:
dim - the dimension on which to sample data from (should be between 0 and numInputDimension() - 1
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

getSampledDimension

public int getSampledDimension()

size

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

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

numInputDimensions

public int numInputDimensions()
Get the dimension of the input values of the function.

Specified by:
numInputDimensions in interface SampledMapping
Returns:
dimension

numOutputDimensions

public int numOutputDimensions()
Get the dimension of the output values of the function.

Specified by:
numOutputDimensions in interface SampledMapping
Returns:
dimension

samplePointAt

public ValuedPair samplePointAt(int index)
                         throws java.lang.ArrayIndexOutOfBoundsException
Description copied from interface: SampledMapping
Get the abscissa and value of the sample at the specified index.

Specified by:
samplePointAt in interface SampledMapping
Parameters:
index - index in the sample, should be between 0 and SampledMapping.size() - 1
Returns:
abscissa and value of the sample at the specified index
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index is wrong