WeightedLowess
A C++ library for LOWESS with various weighting schemes
|
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) |
Namespace for LOWESS functions.
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.
Data_ | Floating-point type for the data. |
num_points | Number of points. | |
[in] | x | Pointer 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] | y | Pointer to an array of num_points y-values. |
opt | Further options. |
Results
object containing the fitted values and robustness weights. 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.
Data_ | Floating-point type for the data. |
num_points | Number of points. | |
[in] | x | Pointer 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] | y | Pointer to an array of num_points y-values. |
[out] | fitted | Pointer to an output array of length num_points , in which the fitted values of the smoother can be stored. |
[out] | robust_weights | Pointer 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. |
opt | Further options. |
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.
Data_ | Floating-point type for the data. |
num_points | Number of points. | |
[in] | x | Pointer 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 .) |
windows | Precomputed windows, created by calling define_windows() with num_points , x and opt . | |
[in] | y | Pointer to an array of num_points y-values. |
[out] | fitted | Pointer to an output array of length num_points , in which the fitted values of the smoother can be stored. |
[out] | robust_weights | Pointer 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. |
opt | Further 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 . |
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.
Data_ | Floating-point type for the data. |
num_points | Number of points. | |
[in] | x | Pointer 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.) |
opt | Further 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 . |
void WeightedLowess::parallelize | ( | int | num_workers, |
Task_ | num_tasks, | ||
Run_ | run_task_range | ||
) |
Task_ | Integer type for the number of tasks. |
Run_ | Function to execute a range of tasks. |
num_workers | Number of workers. |
num_tasks | Number of tasks. |
run_task_range | Function 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()
.