Class BSplineArray

All Implemented Interfaces:
RealValuedDomainOps, VADomainOps

public class BSplineArray extends VectorValuedFunction
Class implementing vector-valued B-splines.

This class supports both periodic and non-periodic B-splines, and is very similar to the BSpline class: the difference is that the values it computes are arrays of double-precision numbers instead of single numbers. Periodic B-splines can be used to approximate period functions. Additional control points and knots are added for periodic B-splines. (see below).

Constructors differ from those in the BSpline class in two ways: there is an initial argument giving a dimension (the length for the arrays that represent the spline's values), and in some cases, the corresponding argument arrays are larger, scaled up by the dimension, and stored so that the array components representing a given point are adjacent.

A B-spline consists of

  • an increasing finite sequence of real numbers called "knots": u0 ≤ u1 ≤ ... ≤ um
  • a set of basis functions.
  • a set of control points (just numbers for this class) denoted as P0, P1, … Pn.
  • a degree—normally denoted as p. The degree of a B-spline must satisfy p = m - n - 1.

The basis functions are defined as follows: $$\begin{eqnarray} N_{i,0}(u) & = & \left\{\begin{array}{ll} 1 & \mbox {if $u_i \le u < u_{i+1}$} \\ 0 & \mbox{if $u < u_i$ or $u_{i+1} \le u$} \end{array}\right . \\ N_{i,p}(u) & = & \mbox{$N_{i,p-1}(u)\frac{u-u_i}{u_{i+p}-u_i} + N_{i+1,p-1}(u)\frac{u_{i+p+1}-u}{u_{i+p+1}-u_{i+1}}$ for $p > 0$} \end{eqnarray}$$

  • Ni,0(u) = 1 if ui ≤ u < ui+1.
  • Ni,0(u) = 0 if u < ui or ui+1 ≤ u.
  • Ni,p(u) = Ni,p-1(u) (u-ui) ⁄ (ui+p-ui) + Ni+1,p-1(u) (ui+p+1-u) ⁄ (ui+p+1-ui+1) for p > 0.
The value of the function $f$ defined by this spline at a point u is defined by $$f(u) = \sum^n_{i=0} P_iN_{i,p}(u)$$ with a domain [up, um-p] for non-periodic splines and (-∞, ∞) for periodic splines (for a periodic spline, the value of u will be shifted by an appropriate multiple of the period so as to be in the interval [up, um-p]), and at at the end points of this interval, the values will match, as will their derivatives.

The documentation for the constructor BSplineArray(int,int,double[],double[],boolean) describes how periodic and non-periodic B-splines are created.

  • Constructor Summary

    Constructors
    Constructor
    Description
    BSplineArray(int dim, double[] knots, double[] cpoints)
    Constructor for open B-splines.
    BSplineArray(int dim, int degree, double[] knots, boolean periodic, double[] x, double[] y)
    Constructor specifying a B-spline's degree and knots, and fitting the spline to a set of data points.
    BSplineArray(int dim, int degree, double[] knots, boolean periodic, double[] x, double[] y, double[] sigma)
    Constructor specifying a B-spline's degree and knots, and fitting the spline to a set of data points with errors.
    BSplineArray(int dim, int degree, double[] knots, double[] cpoints, boolean periodic)
    Constructor.
    BSplineArray(int dim, int degree, int n, BSpline.Mode mode, double[] x, double[] y)
    Constructor specifying a B-spline's degree, number of control points, mode, and a set of Y values for given X values.
    BSplineArray(int dim, int degree, int n, BSpline.Mode mode, double[] x, double[] y, double[] sigma)
    Constructor specifying a B-spline's degree, number of control points, mode, and a set of Y values and their standard deviations for given X values.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    derivAt(double[] array, int off, double u)
    Evaluate the function's first derivative, storing the results.
    boolean
    Determine if the domain maximum is in the domain.
    boolean
    Determine if the domain minimum is in the domain.
    int
    Get the degree if this B-spline.
    int
    Get the dimension of the vectors returned by a vector-valued function.
    double
    Get the maximum value in the domain of the function.
    double
    Get the minimum value in the domain of the function.
    double
    Get the period.
    double
    Get the ending value for a period.
    double
    Get the starting value for a period.
    boolean
    Determine if the spline is a periodic spline.
    final double
    N(int i, int p, double u)
    Compute the value of a B-Spline's basis function.
    void
    secondDerivAt(double[] array, int off, double u)
    Evaluate the function's second derivative, storing the results.
    void
    valueAt(double[] array, int off, double u)
    Call the function, storing the value in an array.

    Methods inherited from class org.bzdev.math.VectorValuedFunctionVA

    derivAt, maxArgLength, minArgLength, secondDerivAt, valueAt

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BSplineArray

      public BSplineArray(int dim, double[] knots, double[] cpoints) throws IllegalArgumentException
      Constructor for open B-splines. A full description is provided by the constructor BSplineArray(int,int,double[],double[],boolean). The degree of the B-spline is equal to knots.length - cpoints.length - 1.
      Parameters:
      dim - the length of the array of values
      knots - the knots for the B-spline to be constructed
      cpoints - the control points for the B-spline to be constructed
      Throws:
      IllegalArgumentException
      See Also:
    • BSplineArray

      public BSplineArray(int dim, int degree, double[] knots, double[] cpoints, boolean periodic) throws IllegalArgumentException
      Constructor. There are two cases depending on whether the B-spline will be periodic or non-periodic. For the non-periodic case, if m is the length of the knots array, n is the number of control points, and p is the degree if the B-spline, then the following constraint must be satisfied:
           n + p + 1 = m
      or
           m - n - 1 = p.
      or
           m - p - 1 = n.
      The degree matches the highest possible degree of the polynomial representation of the basis functions (some authors start the sequence at 1 instead of 0, in which case the degree the smallest integer larger than the degree of the polynomials). The domain of the spline is [us, ue]. where us=knots[degree] and ue=knots[knots.length-p-1].

      For the periodic case, the values of the spline over a range [us,ue] repeat indefinitely in either direction, and the knots array's initial and ending components will be us and ue respectively. As a result, the period is ue-us. For a periodic spline whose degree is p, the length of the control-points array will either be one less than the length of the knots array, or (p-1) larger than the length of the knots array. The constructor will augment these arrays as follows:

      • p components will be inserted before the initial component of the knots array, and p components will be inserted after the last component of the knots array. The p components before the last original entry will be copied to the start of the array in the same order as in the original array, with values decreased by the period. The first p components past the initial component of the original array array will be copied to the end of the array, with values increased by the period.
      • When the control-points array's length is one less than the length of the knots array, p components will be inserted before the initial component of the control-points array. The last p components of the original array will be copied to the start of the augmented array in the same order as in the original array.
      Note: Copying of control points must be considered when fitting a periodic spline to a function or a set of data points.
      Parameters:
      dim - the dimenions for this vector-valued function
      degree - a non-negative integer giving the degree of the B-spline to be constructed
      knots - the knots for the B-spline to be constructed
      cpoints - the control points for the B-spline to be constructed
      periodic - true if the spline is periodic; false if it is open.
      Throws:
      IllegalArgumentException
    • BSplineArray

      public BSplineArray(int dim, int degree, double[] knots, boolean periodic, double[] x, double[] y)
      Constructor specifying a B-spline's degree and knots, and fitting the spline to a set of data points. The use of knots is the same as that for the constructor BSplineArray(int,int,double[],double[],boolean).
      Parameters:
      dim - the length of the array of values
      degree - the degree of the B-spline that will be created
      knots - the knots the B-spline uses
      periodic - true if the B-spline is periodic, false otherwise
      x - values in the domain of the spline
      y - values in the range of the spline
    • BSplineArray

      public BSplineArray(int dim, int degree, double[] knots, boolean periodic, double[] x, double[] y, double[] sigma)
      Constructor specifying a B-spline's degree and knots, and fitting the spline to a set of data points with errors. The use of knots is the same as that for the constructor BSplineArray(int,int,double[],double[],boolean).
      Parameters:
      dim - the length of the array of values
      degree - the degree of the B-spline that will be created
      knots - the knots the B-spline uses
      periodic - true if the B-spline is periodic, false otherwise
      x - values in the domain of the spline
      y - values in the range of the spline
      sigma - the standard deviations for the values provided by the argument y
    • BSplineArray

      public BSplineArray(int dim, int degree, int n, BSpline.Mode mode, double[] x, double[] y)
      Constructor specifying a B-spline's degree, number of control points, mode, and a set of Y values for given X values. The number of X,Y data points must be larger than the number of control points.
      Parameters:
      dim - the dimenions for this vector-valued function
      degree - the degree of the B-spline that will be created
      n - the number of control points
      mode - the mode for the B-spline (either BSpline.Mode.UNCLAMPED, BSpline.Mode.CLAMPED, BSpline.Mode.CLAMPED_LEFT, BSpline.Mode.CLAMPED_RIGHT, or BSpline.Mode.PERIODIC); null for the default (BSplineMode.UNCLAMPED)
      x - values in the domain of the spline
      y - values in the range of the spline
    • BSplineArray

      public BSplineArray(int dim, int degree, int n, BSpline.Mode mode, double[] x, double[] y, double[] sigma)
      Constructor specifying a B-spline's degree, number of control points, mode, and a set of Y values and their standard deviations for given X values. The number of X,Y data points must be larger than the number of control points.
      Parameters:
      dim - the dimenions for this vector-valued function
      degree - the degree of the B-spline that will be created
      n - the number of control points
      mode - the mode for the B-spline (either BSpline.Mode.UNCLAMPED, BSpline.Mode.CLAMPED, BSpline.Mode.CLAMPED_LEFT, BSpline.Mode.CLAMPED_RIGHT, or BSpline.Mode.PERIODIC); null for the default (BSplineMode.UNCLAMPED)
      x - values in the domain of the spline
      y - values in the range of the spline
      sigma - the standard deviations for the values provided by the argument y
  • Method Details

    • getDimension

      public int getDimension()
      Description copied from class: VectorValuedFunctionVA
      Get the dimension of the vectors returned by a vector-valued function.
      Overrides:
      getDimension in class VectorValuedFunctionVA
      Returns:
      the dimension of the vectors returned by this vector-valued function
    • isPeriodic

      public boolean isPeriodic()
      Determine if the spline is a periodic spline.
      Returns:
      true if the spline is periodic; false otherwise.
    • getPeriodStart

      public double getPeriodStart()
      Get the starting value for a period. A periodic B-spline explicitly handles a range of values of the parameters. For other values of the parameter, the parameter is shifted by the period until it falls within this range. For a non-periodic B-spline, the domain minimum is returned.
      Returns:
      the starting value for a period if the spline is periodic; otherwise the domain minimum
    • getPeriodEnd

      public double getPeriodEnd()
      Get the ending value for a period. A periodic B-spline explicitly handles a range of values of the parameters. For other values of the parameter, the parameter is shifted by the period until it falls within this range. For a non-periodic B-spline, the domain maximum is returned.
      Returns:
      the ending value for a period if the spline is periodic; otherwise the domain maximum
    • getPeriod

      public double getPeriod()
      Get the period. A periodic B-spline explicitly handles a range of values of the parameters. For other values of the parameter, the parameter is shifted by the period until it falls within this range. For a periodic B-spline, the period is numerically equal to getPeriodEnd()-getPeriodStart().
      Returns:
      the period for a periodic spline; 0.0 if the spline is not periodic
    • getDegree

      public int getDegree()
      Get the degree if this B-spline. The smallest degree is zero (some authors use 1, in which case the degree will be larger by 1 than the value returned by this method).
      Returns:
      this B-spline's degree.
    • N

      public final double N(int i, int p, double u)
      Compute the value of a B-Spline's basis function.
      Parameters:
      i - a integer representing a knot span with a value equal to the index of the knot at the start of a span
      p - the degree of the basis function
      u - the value of the B-spline's parameter
      Returns:
      the value of the basis function at point u
    • getDomainMin

      public double getDomainMin()
      Description copied from interface: RealValuedDomainOps
      Get the minimum value in the domain of the function.
      Specified by:
      getDomainMin in interface RealValuedDomainOps
      Overrides:
      getDomainMin in class VectorValuedFunction
      Returns:
      the minimum value
    • domainMinClosed

      public boolean domainMinClosed()
      Description copied from interface: RealValuedDomainOps
      Determine if the domain minimum is in the domain.
      Specified by:
      domainMinClosed in interface RealValuedDomainOps
      Overrides:
      domainMinClosed in class VectorValuedFunction
      Returns:
      true if the domain minimum is in the domain; false if it is the greatest lower bound for the domain
    • getDomainMax

      public double getDomainMax()
      Description copied from interface: RealValuedDomainOps
      Get the maximum value in the domain of the function.
      Specified by:
      getDomainMax in interface RealValuedDomainOps
      Overrides:
      getDomainMax in class VectorValuedFunction
      Returns:
      the maximum value
    • domainMaxClosed

      public boolean domainMaxClosed()
      Description copied from interface: RealValuedDomainOps
      Determine if the domain maximum is in the domain.
      Specified by:
      domainMaxClosed in interface RealValuedDomainOps
      Overrides:
      domainMaxClosed in class VectorValuedFunction
      Returns:
      true if the domain maximum is in the domain; false if it is the least upper bound for the domain
    • valueAt

      public void valueAt(double[] array, int off, double u) throws IllegalArgumentException
      Description copied from class: VectorValuedFunction
      Call the function, storing the value in an array.
      Specified by:
      valueAt in class VectorValuedFunction
      Parameters:
      array - the array used to store the results of the function call.
      off - the offset into the array at which to store the results of the function call.
      u - the function's argument
      Throws:
      IllegalArgumentException - the function's argument was out of range
    • derivAt

      public void derivAt(double[] array, int off, double u) throws IllegalArgumentException
      Description copied from class: VectorValuedFunction
      Evaluate the function's first derivative, storing the results.
      Overrides:
      derivAt in class VectorValuedFunction
      Parameters:
      array - the array used to store the results.
      off - the offset into the array at which to store the results.
      u - the function's argument
      Throws:
      IllegalArgumentException - the function's argument was out of range
    • secondDerivAt

      public void secondDerivAt(double[] array, int off, double u)
      Description copied from class: VectorValuedFunction
      Evaluate the function's second derivative, storing the results.
      Overrides:
      secondDerivAt in class VectorValuedFunction
      Parameters:
      array - the array used to store the results.
      off - the offset into the array at which to store the results.
      u - the function's argument