Class
NumCosmoMathFunctionSampleSet
Description [src]
final class NumCosmoMath.FunctionSampleSet : GObject.Object
{
/* No available fields */
}
Ordered sample set for vector-valued functions $\vec{F}: \mathbb{R} \to \mathbb{R}^n$.
Stores samples $(x_i, \vec{y}_i)$ in ascending $x_i$ order. Each interval
has an interval_ok flag for refinement status.
The intended use is iterative refinement of splines built from vector-valued functions:
- Add initial samples with
ncm_function_sample_set_add()or ncm_function_sample_set_add_func(). - Convert to
NcmSplineVecand test the interpolation error with ncm_function_sample_set_refine(). - Insert new samples where the error exceeds the tolerance, using the iterators.
- Mark an interval as
interval_okonce it passes the error test. - Repeat until
ncm_function_sample_set_all_intervals_ok()returns TRUE.
Iterators provide traversal, interval access, and insertion operations, with O(1) access to sample data once positioned.
// Create iterator and traverse all samples (stack-allocated - no free needed)
NcmFunctionSampleSetIter iter_s;
NcmFunctionSampleSetIter *iter = &iter_s;
ncm_function_sample_set_iter_begin (fss, &iter);
while (ncm_function_sample_set_iter_is_valid (iter))
{
gdouble x = ncm_function_sample_set_iter_get_x (iter);
NcmVector *y = ncm_function_sample_set_iter_get_y (iter);
// Process sample...
ncm_function_sample_set_iter_next (iter);
}
// Iterate over intervals using iter_next_pair (stack-allocated iterators)
NcmFunctionSampleSetIter it_s, next_it_s;
NcmFunctionSampleSetIter *it = &it_s;
NcmFunctionSampleSetIter *next_it = &next_it_s;
ncm_function_sample_set_iter_begin (fss, &it);
ncm_function_sample_set_iter_copy (it, &next_it);
while (ncm_function_sample_set_iter_next_pair (it, next_it))
{
if (ncm_function_sample_set_iter_get_interval_ok (it) < threshold)
{
gdouble x_mid = 0.5 * (ncm_function_sample_set_iter_get_x (it) +
ncm_function_sample_set_iter_get_x (next_it));
NcmFunctionSampleSetIter new_it_s;
NcmFunctionSampleSetIter *new_it = &new_it_s;
ncm_function_sample_set_iter_insert_after_func (fss, it, x_mid, func, NULL, &new_it);
}
ncm_function_sample_set_iter_next (it);
}
Conversion to NcmSplineVec reuses internal arrays and invalidates the
previously returned spline. Duplicate the spline to retain it.
The vector dimension $n$ is fixed at creation and checked on insertion.
Constructors
ncm_function_sample_set_new
Creates a new NcmFunctionSampleSet for storing samples of a vector-valued
function with output dimension len.
Functions
ncm_function_sample_set_clear
Decreases the reference count of fss and sets the pointer fss to NULL.
Instance methods
ncm_function_sample_set_adaptive_midpoint
Refines fss by midpoint insertion, starting from its old samples (see
ncm_function_sample_set_mark_all_old()): the refinement tests each new point against
the spline of the old ones. A set with fewer than 6 samples (the cubic not-a-knot
minimum) first receives midpoints as old points until it has 6; fewer than 2 aborts. Then, on each iteration, every interval with interval_ok below
min_pass_threshold receives its midpoint (evaluated with f), and
ncm_function_sample_set_refine() tests the new points. The process stops when every
interval reaches min_pass_threshold, or after max_iter iterations with a message
if some interval has not. An interval too short to split at machine precision is
marked as passed, and the number of such intervals is reported in a message.
ncm_function_sample_set_adaptive_midpoint_full
Same as ncm_function_sample_set_adaptive_midpoint(), reporting the closure of the settled set. A closure that flagged nothing counts one round with nothing flagged; one whose flagged intervals all passed counts their number with nothing failed.
ncm_function_sample_set_add
Adds a new sample point to fss with position x and vector value y. The sample is
inserted in the correct position to maintain ascending x-order. The vector y is
copied and must have dimension matching the fss:len property. The interval_ok flag
for the new sample is initialized to 0. The sample is marked as a new point.
ncm_function_sample_set_add_func
Evaluates the vector-valued function f at x and adds the result as a new sample
point. The sample is inserted in the correct position to maintain ascending x-order.
The interval_ok flag for the new sample is initialized to 0. The sample is marked as
a new point.
ncm_function_sample_set_add_old
Adds a new sample point to fss with position x and vector value y, marked as OLD.
This function is useful for boundary extensions where the added point should be
considered part of the base spline rather than a refinement target. The sample is
inserted in the correct position to maintain ascending x-order. The vector y is
copied and must have dimension matching the fss:len property. The interval_ok flag
for the new sample is initialized to 0. The sample is marked as an old point
(new_point = FALSE).
ncm_function_sample_set_add_old_func
Evaluates the vector-valued function f at x and adds the result as an old sample
point. This function is useful for boundary extensions where the added point should
be considered part of the base spline rather than a refinement target. The sample is
inserted in the correct position to maintain ascending x-order. The interval_ok flag
for the new sample is initialized to 0. The sample is marked as an old point
(new_point = FALSE).
ncm_function_sample_set_all_intervals_ok
Checks if all intervals have interval_ok >= threshold. This is useful for
determining convergence in refinement algorithms - when all intervals have passed
the refinement test enough times.
ncm_function_sample_set_estimate_residuals
Estimates base_spline‘s interpolation error from the samples already held,
without evaluating the function anywhere: both splines are fitted to the
same data and differenced at each interval’s midpoint, which is where the
samples say least. An embedded pair, in the sense a Runge-Kutta pair is one.
ncm_function_sample_set_expand_domain
Expands the domain of the function sample set by alternating between left and right boundary expansion until convergence or limits are reached. At each step:.
ncm_function_sample_set_free
Decreases the reference count of fss. If the reference count reaches zero,
fss is freed.
ncm_function_sample_set_get_absmaxF
Gets the maximum absolute value observed for component i across all samples. This
is useful for determining appropriate tolerances in refinement algorithms.
ncm_function_sample_set_get_absmaxF_l2_norm
Computes the $L_2$ norm (Euclidean norm) of the maximum absolute values across all components: $$|\vec{F}|2 = \sqrt{\sum{i=0}^{n-1} (\max_x |F_i(x)|)^2}$$.
ncm_function_sample_set_get_absmaxF_linf_norm
Computes the $L_\infty$ norm (maximum norm) of the maximum absolute values across all components: $$|\vec{F}|\infty = \max{i=0}^{n-1} (\max_x |F_i(x)|)$$.
ncm_function_sample_set_get_absmaxF_min
Computes the minimum of the maximum absolute values across all components that are not identically zero: $$\min_{i : \max_x |F_i(x)| > 0} (\max_x |F_i(x)|)$$.
ncm_function_sample_set_get_residuals
Builds the per-interval residuals recorded while
NcmFunctionSampleSet:track-residual was on, as a matrix with one row per
sample, in ascending $x$ order, and one column per component. Row $i$ holds
the residual of the interval $[x_i, x_{i+1}]$, matching the convention
ncm_function_sample_set_iter_get_interval_ok() uses; the last row is the
trailing edge and is always NaN.
ncm_function_sample_set_iter_begin
Positions an iterator at the first sample in fss.
If fss is empty, the iterator will be invalid.
When iter_out points to a NULL pointer the callee allocates a new iterator
that must be freed with ncm_function_sample_set_iter_free().
When iter_out points to an already-allocated iterator (e.g. a stack variable)
no allocation occurs and no free is required.
ncm_function_sample_set_iter_end
Positions an iterator at the last sample in fss.
If fss is empty, the iterator will be invalid.
When iter_out points to a NULL pointer the callee allocates a new iterator
that must be freed with ncm_function_sample_set_iter_free().
When iter_out points to an already-allocated iterator (e.g. a stack variable)
no allocation occurs and no free is required.
ncm_function_sample_set_iter_insert_after
Inserts a new sample after the position of iter. The vector y must have dimension
matching fss:len property. The new sample’s interval_ok is initialized to 0 and
new_point is set to TRUE. When iter_out points to a NULL pointer the callee
allocates a new iterator that must be freed with
ncm_function_sample_set_iter_free(). When iter_out points to an already-allocated
iterator (e.g. a stack variable) no allocation occurs and no free is required.
ncm_function_sample_set_iter_insert_after_func
Evaluates f at x and inserts the result as a new sample after iter. The new
sample’s interval_ok is initialized to 0 and new_point is set to TRUE. When
iter_out points to a NULL pointer the callee allocates a new iterator that must be
freed with ncm_function_sample_set_iter_free(). When iter_out points to an
already-allocated iterator (e.g. a stack variable) no allocation occurs and no free
is required.
ncm_function_sample_set_iter_insert_before
Inserts a new sample before the position of iter. The vector y must have dimension
matching fss:len property. The new sample’s interval_ok is initialized to 0 and
new_point is set to TRUE. When iter_out points to a NULL pointer the callee
allocates a new iterator that must be freed with
ncm_function_sample_set_iter_free(). When iter_out points to an already-allocated
iterator (e.g. a stack variable) no allocation occurs and no free is required.
ncm_function_sample_set_iter_insert_before_func
Evaluates f at x and inserts the result as a new sample before iter. The new
sample’s interval_ok is initialized to 0 and new_point is set to TRUE. When
iter_out points to a NULL pointer the callee allocates a new iterator that must be
freed with ncm_function_sample_set_iter_free(). When iter_out points to an
already-allocated iterator (e.g. a stack variable) no allocation occurs and no free
is required.
ncm_function_sample_set_log_vals
Logs all sample values in fss for debugging purposes. This prints the x position,
vector components, interval_ok flag, and new_point flag for each sample.
ncm_function_sample_set_mark_all_old
Marks all points in fss as old. This is typically called after a refinement pass to
indicate that all current points should be used in the next spline construction.
ncm_function_sample_set_refine
Performs a refinement pass on all NEW points. For each NEW point, this function:.
ncm_function_sample_set_reset_interval_ok
Resets all interval_ok flags to 0. This is useful when starting a new refinement pass.
ncm_function_sample_set_set_track_residual
Sets NcmFunctionSampleSet:track-residual. Set it before refining: only the
passes that run while it is on leave a record behind.
ncm_function_sample_set_to_spline_vec
Converts the sample set to a NcmSplineVec. Its knots and values are views of arrays
cached in fss, not copies. The next call to this function or to
ncm_function_sample_set_to_spline_vec_old() on fss overwrites those arrays, and
reallocates them when the number of points grows, so the returned object must not be
used after such a call. Freeing fss does not affect it.
ncm_function_sample_set_to_spline_vec_old
Converts only the OLD sample points to a NcmSplineVec. Its knots and values share the
cached arrays of fss as in ncm_function_sample_set_to_spline_vec(), with the same
restriction: the returned object must not be used after the next call to either
function on fss.
Properties
NumCosmoMath.FunctionSampleSet:track-residual
Whether ncm_function_sample_set_refine() records the residual it actually
achieved on each interval, instead of only the pass/fail bit counted by
interval_ok. Off by default: the record costs one extra vector of length
NcmFunctionSampleSet:len per sample, and only a caller that reports an
error estimate needs it. See ncm_function_sample_set_get_residuals().
Signals
Signals inherited from GObject (1)
GObject::notify
The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.