org.spaceroots.mantissa.functions.scalar
Class ComputableFunctionSampler
- java.lang.Object
-
- org.spaceroots.mantissa.functions.scalar.ComputableFunctionSampler
-
- All Implemented Interfaces:
- java.io.Serializable, SampledFunction
public class ComputableFunctionSampler extends java.lang.Object implements SampledFunction, java.io.Serializable
This class is a wrapper allowing to sample aComputableFunction.The sample produced is a regular sample. It can be specified by several means :
- from an initial point a step and a number of points
- from a range and a number of points
- from a range and a step between points.
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:
ComputableFunction, Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description ScalarValuedPairsamplePointAt(int index)Get the abscissa and value of the sample at the specified index.intsize()Get the number of points in the sample.
-
-
-
Constructor Detail
-
ComputableFunctionSampler
public ComputableFunctionSampler(ComputableFunction function, double begin, double step, int n)
Constructor. Build a sample from anComputableFunction. 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 pointsn- number of points
-
ComputableFunctionSampler
public ComputableFunctionSampler(ComputableFunction function, double[] range, int n)
Constructor. Build a sample from anComputableFunction.- Parameters:
range- abscissa range (fromrange [0]torange [1])n- number of points
-
ComputableFunctionSampler
public ComputableFunctionSampler(ComputableFunction function, double[] range, double step, boolean adjustStep)
Constructor. Build a sample from anComputableFunction.- Parameters:
range- abscissa range (fromrange [0]torange [1])step- step between pointsadjustStep- if true, the step is reduced in order to have the last point of the sample exactly atrange [1], if false the last point will be betweenrange [1] - stepandrange [1]
-
-
Method Detail
-
size
public int size()
Description copied from interface:SampledFunctionGet the number of points in the sample.- Specified by:
sizein interfaceSampledFunction- Returns:
- number of points in the sample
-
samplePointAt
public ScalarValuedPair samplePointAt(int index) throws java.lang.ArrayIndexOutOfBoundsException, FunctionException
Description copied from interface:SampledFunctionGet the abscissa and value of the sample at the specified index.- Specified by:
samplePointAtin interfaceSampledFunction- Parameters:
index- index in the sample, should be between 0 andSampledFunction.size()- 1- Returns:
- abscissa and value of the sample at the specified index
- Throws:
java.lang.ArrayIndexOutOfBoundsException- if the index is wrongFunctionException- if an eventual underlying function throws one
-
-
DataMelt 3.0 © DataMelt by jWork.ORG