WeightedLowess
A C++ library for LOWESS with various weighting schemes
Loading...
Searching...
No Matches
Classes | Functions
WeightedLowess Namespace Reference

Namespace for LOWESS functions. More...

Classes

struct  Options
 Options for compute(). More...
 
struct  PrecomputedWindows
 Precomputed windows for LOWESS smoothing. More...
 
struct  Results
 Store the smoothing results. More...
 
class  SortBy
 Utility class for sorting on a covariate. More...
 

Functions

template<typename Data_ >
void compute (size_t num_points, const Data_ *x, const PrecomputedWindows< Data_ > &windows, const Data_ *y, Data_ *fitted, Data_ *robust_weights, const Options< Data_ > &opt)
 
template<typename Data_ >
void compute (size_t num_points, const Data_ *x, const Data_ *y, Data_ *fitted, Data_ *robust_weights, const Options< Data_ > &opt)
 
template<typename Data_ >
Results< Data_ > compute (size_t num_points, const Data_ *x, const Data_ *y, const Options< Data_ > &opt)
 
template<typename Task_ , class Run_ >
void parallelize (int num_workers, Task_ num_tasks, Run_ run_task_range)
 
template<typename Data_ >
PrecomputedWindows< Data_ > define_windows (size_t num_points, const Data_ *x, const Options< Data_ > &opt)
 

Detailed Description

Namespace for LOWESS functions.

Function Documentation

◆ compute() [1/3]

template<typename Data_ >
Results< Data_ > WeightedLowess::compute ( size_t  num_points,
const Data_ *  x,
const Data_ *  y,
const Options< Data_ > &  opt 
)

Run the LOWESS smoother and return a Results object. This avoids the need to instantiate the various output arrays manually.

Template Parameters
Data_Floating-point type for the data.
Parameters
num_pointsNumber of points.
[in]xPointer to an array of num_points x-values, sorted in increasing order. (Consider using SortBy to permute x in-place. Note that the same permutation should be applied to y and, if present, weights in Options::weights.)
[in]yPointer to an array of num_points y-values.
optFurther options.
Returns
A Results object containing the fitted values and robustness weights.

◆ compute() [2/3]

template<typename Data_ >
void WeightedLowess::compute ( size_t  num_points,
const Data_ *  x,
const Data_ *  y,
Data_ *  fitted,
Data_ *  robust_weights,
const Options< Data_ > &  opt 
)

LOWESS is a simple, efficient, general-purpose non-parametric smoothing algorithm. It perform weighted linear regressions on subsets of neighboring points, yielding a smooth curve fit to the data.

Template Parameters
Data_Floating-point type for the data.
Parameters
num_pointsNumber of points.
[in]xPointer to an array of num_points x-values, sorted in increasing order. (Consider using SortBy to permute x in-place. Note that the same permutation should be applied to y and, if present, weights in Options::weights.)
[in]yPointer to an array of num_points y-values.
[out]fittedPointer to an output array of length num_points, in which the fitted values of the smoother can be stored.
[out]robust_weightsPointer to an output array of length num_points, in which the robustness weights can be stored. This may be NULL if the robustness weights are not needed.
optFurther options.

◆ compute() [3/3]

template<typename Data_ >
void WeightedLowess::compute ( size_t  num_points,
const Data_ *  x,
const PrecomputedWindows< Data_ > &  windows,
const Data_ *  y,
Data_ *  fitted,
Data_ *  robust_weights,
const Options< Data_ > &  opt 
)

Run the LOWESS smoother with precomputed windows. This avoids redundant window calculations when re-using the same x-coordinates across multiple y-coordinate vectors.

Template Parameters
Data_Floating-point type for the data.
Parameters
num_pointsNumber of points.
[in]xPointer to an array of num_points x-values, sorted in increasing order. (Consider using SortBy to permute x in-place. Note that the same permutation should be applied to y, if present, and weights in Options::weights.)
windowsPrecomputed windows, created by calling define_windows() with num_points, x and opt.
[in]yPointer to an array of num_points y-values.
[out]fittedPointer to an output array of length num_points, in which the fitted values of the smoother can be stored.
[out]robust_weightsPointer to an output array of length num_points, in which the robustness weights can be stored. This may be NULL if the robustness weights are not needed.
optFurther options. This should be the same object that is used in define_windows(). Note that only a subset of options are actually used in this overload, namely Options::weights and Options::iterations.

◆ define_windows()

template<typename Data_ >
PrecomputedWindows< Data_ > WeightedLowess::define_windows ( size_t  num_points,
const Data_ *  x,
const Options< Data_ > &  opt 
)

Precompute the window locations prior to fitting of different y via the corresponding compute() overload. This avoids wasting time in unnecessarily recomputing the same windows for each compute() call.

Template Parameters
Data_Floating-point type for the data.
Parameters
num_pointsNumber of points.
[in]xPointer to an array of num_points x-values, sorted in increasing order. (Consider using SortBy to permute the array in-place before calling this function.)
optFurther options. Only a subset of options are actually used here, namely Options::delta, Options::anchors, Options::weights, Options::frequency_weights, Options::span, Options::span_as_proportion, and Options::minimum_width.

◆ parallelize()

template<typename Task_ , class Run_ >
void WeightedLowess::parallelize ( int  num_workers,
Task_  num_tasks,
Run_  run_task_range 
)
Template Parameters
Task_Integer type for the number of tasks.
Run_Function to execute a range of tasks.
Parameters
num_workersNumber of workers.
num_tasksNumber of tasks.
run_task_rangeFunction to iterate over a range of tasks within a worker.

By default, this is an alias to subpar::parallelize_range(). However, if the WEIGHTEDLOWESS_CUSTOM_PARALLEL function-like macro is defined, it is called instead. Any user-defined macro should accept the same arguments as subpar::parallelize_range().