Class ChebyshevSlider
- Namespace
- ChebyshevSharp
- Assembly
- ChebyshevSharp.dll
Chebyshev Sliding approximation for high-dimensional functions. Decomposes f(x₁, …, xₙ) into a sum of low-dimensional Chebyshev interpolants (slides) around a pivot point z: f(x) ≈ f(z) + Σᵢ [sᵢ(x_groupᵢ) - f(z)] where each slide sᵢ is a ChebyshevApproximation built on a subset of dimensions with the remaining dimensions fixed at z.
public class ChebyshevSlider
- Inheritance
-
ChebyshevSlider
- Inherited Members
Remarks
This trades accuracy for dramatically reduced build cost: instead of evaluating f at n₁ × n₂ × … × nₐ grid points (exponential), the slider evaluates the pivot once and then evaluates n₁ × n₂ + n₃ × n₄ + … slide-grid points (sum of products within each group). Reference: Ruiz & Zeron (2022), Ch. 7.
Constructors
ChebyshevSlider(Func<double[], object?, double>, int, double[][], int[], int[][], double[], int, object?, int?, IProgress<int>?)
Create a new ChebyshevSlider.
public ChebyshevSlider(Func<double[], object?, double> function, int numDimensions, double[][] domain, int[] nNodes, int[][] partition, double[] pivotPoint, int maxDerivativeOrder = 2, object? additionalData = null, int? nWorkers = null, IProgress<int>? progress = null)
Parameters
functionFunc<double[], object, double>Function to approximate: f(point, data) → double.
numDimensionsintTotal number of input dimensions.
domaindouble[][]Bounds for each dimension as double[ndim][2].
nNodesint[]Number of Chebyshev nodes per dimension.
partitionint[][]Grouping of dimension indices into slides. Each dimension must appear exactly once.
pivotPointdouble[]Reference point z around which slides are built.
maxDerivativeOrderintMaximum derivative order to support (default 2).
additionalDataobjectOptional user data object threaded through every f(point, data) call during Build.
nWorkersint?Number of parallel workers for function evaluation. null = sequential; -1 = ProcessorCount; positive = exact count.
progressIProgress<int>Optional progress reporter; receives cumulative evaluation count across all slides.
Remarks
Thread safety: the user-supplied function must be thread-safe when nWorkers is non-null.
Properties
BuildTime
Wall-clock time (seconds) for the most recent Build() call.
public double BuildTime { get; }
Property Value
Built
Whether Build() has been called.
public bool Built { get; }
Property Value
Domain
Domain bounds for each dimension, as [lo, hi] pairs.
public double[][] Domain { get; }
Property Value
- double[][]
Function
Function used by Build(bool). Null for objects restored from saved numerical state or created by transformation APIs.
public Func<double[], object?, double>? Function { get; }
Property Value
MaxDerivativeOrder
Maximum supported derivative order.
public int MaxDerivativeOrder { get; }
Property Value
NNodes
Number of Chebyshev nodes per dimension.
public int[] NNodes { get; }
Property Value
- int[]
NumDimensions
Number of input dimensions.
public int NumDimensions { get; }
Property Value
Partition
Grouping of dimension indices into slides.
public int[][] Partition { get; }
Property Value
- int[][]
PivotPoint
Reference point z around which slides are built.
public double[] PivotPoint { get; }
Property Value
- double[]
PivotValue
Function value at the pivot point: f(z).
public double PivotValue { get; }
Property Value
TotalBuildEvals
Total slide-grid evaluations used during build. Build(bool) also evaluates the pivot once.
public int TotalBuildEvals { get; }
Property Value
Methods
Build(bool)
Build all slides by evaluating the function at slide-specific grids. For each slide, dimensions outside the group are fixed at pivot values.
public void Build(bool verbose = true)
Parameters
verboseboolIf true, print build progress.
Exceptions
- InvalidOperationException
If this object has no callable Function.
- ArgumentException
If the function returns NaN or Infinity at the pivot or a slide grid point.
Clone()
Returns a deep copy of this slider. The source Function callable is not duplicated; clones cannot be rebuilt without re-supplying the function. All precomputed slides and state are deep-copied.
public ChebyshevSlider Clone()
Returns
- ChebyshevSlider
A fully independent ChebyshevSlider with Function set to null.
ErrorEstimate()
Estimate the sliding approximation error. Returns the sum of per-slide Chebyshev error estimates. Note: this captures per-slide interpolation error only; cross-group interaction error inherent to the sliding decomposition is not included.
public double ErrorEstimate()
Returns
- double
Estimated interpolation error (per-slide sum).
Eval(double[], int)
Evaluate at point using a previously-registered derivative id.
public double Eval(double[] point, int derivativeId)
Parameters
pointdouble[]Evaluation point.
derivativeIdintId returned by GetDerivativeId(int[]).
Returns
- double
Interpolated value at the given derivative order.
Exceptions
- ArgumentOutOfRangeException
Thrown when
derivativeIdhas not been registered.
Eval(double[], int[])
Evaluate the slider approximation at a point. Uses Equation 7.5: f(x) ≈ f(z) + Σᵢ [sᵢ(x_groupᵢ) - f(z)]. For derivatives, only the slide containing that dimension contributes. Cross-group mixed partials are exactly zero.
public double Eval(double[] point, int[] derivativeOrder)
Parameters
pointdouble[]Evaluation point inside the full declared domain.
derivativeOrderint[]Derivative order for each dimension (0 = function value).
Returns
- double
Approximated function value or derivative.
Exceptions
- InvalidOperationException
If Build(bool) has not been called.
- ArgumentException
If
pointorderivativeOrderhas the wrong length.- ArgumentOutOfRangeException
If a point coordinate is outside the declared domain or a derivative order exceeds MaxDerivativeOrder.
EvalMulti(double[], int[][])
Evaluate slider at multiple derivative orders for the same point.
public double[] EvalMulti(double[] point, int[][] derivativeOrders)
Parameters
pointdouble[]Evaluation point inside the declared domain.
derivativeOrdersint[][]Each inner array specifies derivative order per dimension.
Returns
- double[]
Results for each derivative order.
Exceptions
- InvalidOperationException
If Build(bool) has not been called.
- ArgumentException
If
pointor any derivative-order row has the wrong length.- ArgumentOutOfRangeException
If a point coordinate is outside the declared domain or a derivative order exceeds MaxDerivativeOrder.
Extrude(params (int dimIndex, double[] bounds, int nNodes)[])
Add new dimensions where the function is constant. Each new dimension becomes its own single-dim slide group with constant tensor values equal to PivotValue, so it contributes nothing to the sliding sum.
public ChebyshevSlider Extrude(params (int dimIndex, double[] bounds, int nNodes)[] extrudeParams)
Parameters
Returns
- ChebyshevSlider
A new, higher-dimensional slider (already built).
GetAdditionalData()
Returns the user-supplied additionalData object passed to the constructor,
or null if none was provided. Same value is threaded through every f(point, data)
call during Build(bool).
public object? GetAdditionalData()
Returns
GetConstructorType()
Returns one of: "function" (Build), "load" (Load), or "clone" (Clone).
public string GetConstructorType()
Returns
GetDerivativeId(int[])
Register or look up a derivative-orders tuple. Returns a stable
session-local int id for the same orders. Used in conjunction with
the Eval(point, derivativeId) overload.
public int GetDerivativeId(int[] orders)
Parameters
ordersint[]Derivative order per dimension.
Returns
- int
A stable int id for this orders tuple (0-based, assigned in registration order).
GetDescriptor()
Get the descriptor previously set via SetDescriptor(string); null if unset.
public string? GetDescriptor()
Returns
GetEvaluationPoints()
Flat row-major array of all slider evaluation points, expanded to full ndim using PivotPoint. Each slide's local coordinates are mapped to full-ndim space via the Partition and PivotPoint. Length is GetNumEvaluationPoints() * NumDimensions. Result is lazily built and cached internally.
public double[] GetEvaluationPoints()
Returns
- double[]
A snapshot of full-ndim node coordinates, flattened in row-major order.
GetMaxDerivativeOrder()
Maximum derivative order this slider supports.
public int GetMaxDerivativeOrder()
Returns
GetNumEvaluationPoints()
Total number of evaluation points across all slides.
public int GetNumEvaluationPoints()
Returns
- int
The sum of GetNumEvaluationPoints() from each slide.
GetUsedNs()
Per-dimension Chebyshev node counts actually used.
public int[] GetUsedNs()
Returns
- int[]
Integrate(int[]?, (double lo, double hi)[]?)
Integrate the slider approximation over one or more dimensions. Uses the closed-form decomposition of the sliding sum: f(x) ≈ pv + Σ_i [s_i(x_{G_i}) - pv] Each slide's integral is computed via Integrate(int[]?, (double lo, double hi)[]?).
public object Integrate(int[]? dims = null, (double lo, double hi)[]? bounds = null)
Parameters
dimsint[]Dimensions to integrate out. Null = all (full integration → scalar).
bounds(double lo, double hi)[]Sub-interval bounds per dim (positional with sorted dims). Null = full domain.
Returns
- object
A boxed
doublewhen every dim is integrated; otherwise a new ChebyshevSlider over surviving dims.
Exceptions
- InvalidOperationException
If Build(bool) has not been called.
- ArgumentException
If
dimscontains out-of-range indices, orboundsare invalid. Duplicatedimsentries are silently deduplicated (matches Integrate(int[]?, (double lo, double hi)[]?)).
IsConstructionFinished()
True if Build(bool)/Load(string) completed.
public bool IsConstructionFinished()
Returns
Load(string)
Load a previously saved slider from a JSON file.
public static ChebyshevSlider Load(string path)
Parameters
pathstringPath to the saved file.
Returns
- ChebyshevSlider
A fully functional slider with no callable source function attached.
Exceptions
- InvalidDataException
If the file contains a malformed ChebyshevSlider state.
Maximize(int?, Dictionary<int, double>?)
Find the maximum value of the slider along a specified dimension. See Minimize(int?, Dictionary<int, double>?) for parameter details.
public (double value, double location) Maximize(int? dim = null, Dictionary<int, double>? fixedDims = null)
Parameters
dimint?fixedDimsDictionary<int, double>
Returns
Minimize(int?, Dictionary<int, double>?)
Find the minimum value of the slider along a specified dimension. Reduces to a 1-D problem by slicing all other dimensions to their fixed values, then delegates to Minimize(int?, Dictionary<int, double>?).
public (double value, double location) Minimize(int? dim = null, Dictionary<int, double>? fixedDims = null)
Parameters
dimint?Target dimension. For 1-D sliders, defaults to 0.
fixedDimsDictionary<int, double>For multi-D,
{dim_index: value}for all dims exceptdim.
Returns
- (double lo, double hi)
Tuple
(value, location)where value is the minimum and location is its coordinate in the target dimension.
Exceptions
- InvalidOperationException
If Build(bool) has not been called.
- ArgumentException
If validation fails.
Roots(int?, Dictionary<int, double>?)
Find all real roots of the slider along a specified dimension. Reduces to a 1-D problem by slicing all other dimensions to their fixed values, then delegates to Roots(int?, Dictionary<int, double>?).
public double[] Roots(int? dim = null, Dictionary<int, double>? fixedDims = null)
Parameters
dimint?Target dimension. For 1-D sliders, defaults to 0.
fixedDimsDictionary<int, double>For multi-D sliders,
{dim_index: value}for all dimensions exceptdim.
Returns
- double[]
Sorted real root locations in the physical domain. Empty if no roots.
Exceptions
- InvalidOperationException
If Build(bool) has not been called.
- ArgumentException
If
dimorfixedDimsvalidation fails.
Save(string)
Save the built slider to a JSON file.
public void Save(string path)
Parameters
pathstringDestination file path.
Exceptions
- InvalidOperationException
If Build(bool) has not been called.
SetDescriptor(string)
Set a free-form descriptor string for this slider.
public void SetDescriptor(string descriptor)
Parameters
descriptorstring
Slice(params (int dimIndex, double value)[])
Fix one or more dimensions at given values, reducing dimensionality.
public ChebyshevSlider Slice(params (int dimIndex, double value)[] sliceParams)
Parameters
Returns
- ChebyshevSlider
A new, lower-dimensional slider (already built).
ToReprString()
Compact repr string.
public string ToReprString()
Returns
ToString()
Multi-line display string.
public override string ToString()
Returns
Operators
operator +(ChebyshevSlider, ChebyshevSlider)
Pointwise addition of two sliders on the same grid.
public static ChebyshevSlider operator +(ChebyshevSlider a, ChebyshevSlider b)
Parameters
Returns
operator /(ChebyshevSlider, double)
Scalar division.
public static ChebyshevSlider operator /(ChebyshevSlider a, double scalar)
Parameters
aChebyshevSliderscalardouble
Returns
operator *(ChebyshevSlider, double)
Scalar multiplication.
public static ChebyshevSlider operator *(ChebyshevSlider a, double scalar)
Parameters
aChebyshevSliderscalardouble
Returns
operator *(double, ChebyshevSlider)
Scalar multiplication (scalar on left).
public static ChebyshevSlider operator *(double scalar, ChebyshevSlider a)
Parameters
scalardoubleaChebyshevSlider
Returns
operator -(ChebyshevSlider, ChebyshevSlider)
Pointwise subtraction of two sliders on the same grid.
public static ChebyshevSlider operator -(ChebyshevSlider a, ChebyshevSlider b)
Parameters
Returns
operator -(ChebyshevSlider)
Unary negation.
public static ChebyshevSlider operator -(ChebyshevSlider a)