Hawaii Hybrid
Loading...
Searching...
No Matches
loess.hpp
Go to the documentation of this file.
1#ifndef LOESS_H_
2#define LOESS_H_
3
55
56typedef struct {
57 size_t *items;
58 size_t count;
59 size_t capacity;
60} Window;
61
62extern bool loess_debug;
63
64/*
65 * This enum defines the types of weight functions available for assigning weights to data points.
66 * The choice of weight function determines how influence is assigned to observations based on their
67 * proximity to the central point at which smoothing is performed.
68 */
69typedef enum {
70 WEIGHT_TRICUBE, // defined as $(1 - |x|^3)^3$ for $|x| < 1$
71 WEIGHT_BISQUARE, // defined as $(1 - |x|^2)^2$ for $|x| < 1$
73
74/*
75 * Enumeration of numerical methods for solving linear least squares problem:
76 * (X^T W X) beta = X^T W Y
77 */
78typedef enum {
79 // Uses complete orthogonal decomposition to compute the pseudo-inverse of the matrix (X^T W X)
81 // fastest out of variants of QR decompositions, but maybe unstable if the matrix is not rull rank
83 // is usually the fastest. However, if the matrix is even mildly ill-conditioned, this is not a good method. It loses roughly twice as many digits of accuracy using the normal equation, compared to the more stable methods mentioned above.
85} LS_METHOD;
86
87typedef struct {
88 size_t degree; // degree of local polynomial [recommended: 2-3]
89 size_t ws_min; // minimum window size
90 double ws_step; // window size step
91 size_t ws_delay; // optional: the index at which the window is starting to increase
92 size_t ws_cap; // optional: cap on window size [not found useful in most cases]
94
96
97#ifdef __cplusplus
98extern "C" {
99#endif // __cplusplus
100
101void loess_init(double *x, double *y, size_t len);
102double loess_estimate(double x, size_t window_size, size_t degree);
103double *loess_create_grid(double xmin, double xmax, size_t npoints);
105void loess_free();
106
107#ifdef __cplusplus
108}
109#endif // __cplusplus
110
111#endif // LOESS_H_
WEIGHT_FUNC loess_weight
Definition loess.cpp:32
bool loess_debug
Definition loess.cpp:31
WEIGHT_FUNC
Definition loess.hpp:69
@ WEIGHT_TRICUBE
Definition loess.hpp:70
@ WEIGHT_BISQUARE
Definition loess.hpp:71
double loess_estimate(double x, size_t window_size, size_t degree)
Definition loess.cpp:213
void loess_free()
Definition loess.cpp:113
void loess_init(double *x, double *y, size_t len)
Definition loess.cpp:79
double * loess_create_grid(double xmin, double xmax, size_t npoints)
Definition loess.cpp:353
LS_METHOD
Definition loess.hpp:78
@ LS_COMPLETE_ORTHOGONAL_DECOMPOSITION
Definition loess.hpp:80
@ LS_CHOLESKY_SOLVER
Definition loess.hpp:84
@ LS_QR_NO_PIVOTING
Definition loess.hpp:82
double * loess_apply_smoothing(Smoothing_Config *config)
Definition loess.cpp:394
Definition loess.hpp:87
size_t ws_cap
Definition loess.hpp:92
double ws_step
Definition loess.hpp:90
size_t degree
Definition loess.hpp:88
size_t ws_delay
Definition loess.hpp:91
size_t ws_min
Definition loess.hpp:89
Definition loess.hpp:56
size_t * items
Definition loess.hpp:57
size_t count
Definition loess.hpp:58
size_t capacity
Definition loess.hpp:59