ru.sscc.spline.creator
Class SmoothingPreparator

java.lang.Object
  |
  +--ru.sscc.spline.creator.SmoothingPreparator
Direct Known Subclasses:
GSplinePreparator, OddSplinePreparator

public abstract class SmoothingPreparator
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

The basic class for all spline preparators that use smoothing algorithm. It prepares smoothing weight vector and multiples for matrix calculation and contains common algorithm for selection of the smoothing parameter by residual criterion.

The criterion has the form: xwi-1(fi-s(xi))2 = e2. Here wi are weight coefficients, fi are interpolation values, and s(xi) are smoothing spline values at mesh nodes. In general case, any linear functional may be used instead of spline value in mesh node.

See Also:
Serialized Form

Field Summary
protected  double matrixMultiple
          A multiple for interpolating spline matrix
protected  boolean solverPrepared
          The flag is set true when the solver is prepared.
 int sourceSize
          A number of interpolating conditions.
protected  double weightMultiple
          A multiple for smoothing weight vector.
protected  RealVector weights
          A weight vector (null value means identical unit weights).
 
Constructor Summary
protected SmoothingPreparator(int sourceSize)
          Constructor.
 
Method Summary
abstract  double calculationCost()
          Returns a number of arithmetic operations needed for calculation of spline coefficients.
 java.lang.Object clone()
          Returns a nonprepared clone of the preparator.
 void ensureSolverPrepared()
          Ensures that the solver is prepared and throws the IllegalStateException if this is not true.
static double getAccuracy()
          Returns the current accuracy value.
 double getAlpha()
          Returns the current value of the smoothing parameter.
 boolean isSolverPrepared()
          Returns true if the solver is prepared.
protected  void prepareMultiples(double alpha)
          Prepares multiples for construction of smoothing spline matrix (useful in prepareSolver methods).
abstract  void prepareSolver(double alpha)
          An abstract method that prepares a solver for calculations with specified alpha.
 void prepareWeights(java.lang.Object weights)
          Prepares weights by user's weight vector.
 RealVector residual()
          Returns a vector to store the residual.
 double selectAlpha(RealVector values, double epsilon, double alpha, RealVector data, RealVector residual)
          The smoothing parameter selection algorithm.
static double setAccuracy(double accuracy)
          Sets accuracy for solution of residual equation in smoothing parameter selection algorithm and returns the previous accuracy value.
abstract  void solve(RealVector values, RealVector data, RealVector residual)
          An abstract method that calculates spline coefficients and smoothing residual (difference between interpolation data and values of smoothing spline at mesh nodes) by interpolation values.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sourceSize

public final int sourceSize
A number of interpolating conditions.

matrixMultiple

protected double matrixMultiple
A multiple for interpolating spline matrix

weightMultiple

protected double weightMultiple
A multiple for smoothing weight vector.

weights

protected RealVector weights
A weight vector (null value means identical unit weights).

solverPrepared

protected boolean solverPrepared
The flag is set true when the solver is prepared.
Constructor Detail

SmoothingPreparator

protected SmoothingPreparator(int sourceSize)
Constructor.
Parameters:
sourceSize - a number of interpolating conditions
Method Detail

clone

public java.lang.Object clone()
Returns a nonprepared clone of the preparator.
Overrides:
clone in class java.lang.Object

setAccuracy

public static double setAccuracy(double accuracy)
Sets accuracy for solution of residual equation in smoothing parameter selection algorithm and returns the previous accuracy value. The default accuracy is 0.1, eg the residual equation is solved with 10% accuracy. The accuracy should be a real number from the interval (0,1). If this condition is disturbed, the current accuracy leaves unchanged.

getAccuracy

public static double getAccuracy()
Returns the current accuracy value.

prepareWeights

public void prepareWeights(java.lang.Object weights)
Prepares weights by user's weight vector. Tests all weights to be positive and throws IllegalArgumentException if not. Sets the solverPrepared flag to false.
Parameters:
weights - a weight vector (may be the null value or an instance of double[], float[], RealContainer, or RealVector types)

prepareMultiples

protected void prepareMultiples(double alpha)
Prepares multiples for construction of smoothing spline matrix (useful in prepareSolver methods). Matrix and weight multiples are calculated by the following rules: matrixMultiple=1 and weightMultiple=alpha for alpha<1; matrixMultiple=1/alpha and weightMultiple=1 otherwise. The smoothing parameter alpha should be nonnegative. The Double.POSITIVE_INFINITY is permitted.

residual

public RealVector residual()
Returns a vector to store the residual.

getAlpha

public double getAlpha()
Returns the current value of the smoothing parameter.

prepareSolver

public abstract void prepareSolver(double alpha)
                            throws CalculatingException
An abstract method that prepares a solver for calculations with specified alpha. The value alpha = Double.POSITIVE_INFINITY is permitted.

isSolverPrepared

public final boolean isSolverPrepared()
Returns true if the solver is prepared.

ensureSolverPrepared

public final void ensureSolverPrepared()
Ensures that the solver is prepared and throws the IllegalStateException if this is not true.

solve

public abstract void solve(RealVector values,
                           RealVector data,
                           RealVector residual)
An abstract method that calculates spline coefficients and smoothing residual (difference between interpolation data and values of smoothing spline at mesh nodes) by interpolation values.
Parameters:
values - interpolation values at mesh nodes
data - a vector to store spline coefficients
residual - a vector to store residual (if it is equal to null, the residual is not needed)

calculationCost

public abstract double calculationCost()
Returns a number of arithmetic operations needed for calculation of spline coefficients.

selectAlpha

public double selectAlpha(RealVector values,
                          double epsilon,
                          double alpha,
                          RealVector data,
                          RealVector residual)
                   throws CalculatingException
The smoothing parameter selection algorithm. Uses Newton or rational iterations to find a smoothing parameter value that solves the residual equation with accuracy specified. If required residual level e is larger than maximum level corresponding to infinite smoothing parameter, the POSITIVE_INFINITY is returned. Spline coefficients and smoothing residual for selected smoothing parameter are also calculated.
Parameters:
values - interpolation values at mesh nodes
epsilon - a required residual level (should be > 0)
alpha - a smoothing parameter value to start from (should be > 0)
data - a vector to store spline coefficients
residual - a vector to store residual
Returns:
the smoothing parameter value