-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathllsp.h
65 lines (55 loc) · 2.52 KB
/
llsp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* Copyright (C) 2006-2015 Michael Roitzsch <[email protected]>
* economic rights: Technische Universitaet Dresden (Germany)
*/
#include <stddef.h>
/* An online updating solver for Linear Least Squares Problems.
* Uses automatic stabilization by dropping columns to prevent overfitting.
*
* Typical use:
*
* setup:
* llsp_t *solver = llsp_new(count);
* add knowledge:
* llsp_add(solver, metrics, target_value);
* (void)llsp_solve(solver);
* obtain a prediction:
* prediction = llsp_predict(solver, metrics);
* tear down:
* llsp_dispose(solver);
*/
/* The running solution can be made to age out previously acquired knowledge
* over time. When this aging factor is set to 0, no aging is performed. This
* means the solution will be equivalent to a LLS-solution over all previous
* metrics and target values. With an aging factor above zero, the solution will
* slightly lean towards newly added metrics/targets, exhibting properties of a
* sliding average. */
#ifndef AGING_FACTOR
#define AGING_FACTOR 0.01
#endif
/* During the column dropping check, each column's contribution to the accuracy
* of the result is analyzed. An individual column must improve the accuracy by
* at least this factor, otherwise it is considered a rank-deficiency and is
* dropped. Values above 1.0 enable dropping. Higher values drop more, leading
* to more stable, but less precise predictions. Set this to 0 to reliably
* prevent dropping entirely. */
#ifndef COLUMN_CONTRIBUTION
#define COLUMN_CONTRIBUTION 1.1
#endif
/* an opaque handle for the LLSP solver/predictor */
typedef struct llsp_s llsp_t;
/* Allocates a new LLSP handle with the given number of metrics. */
llsp_t *llsp_new(size_t count);
/* This function adds another tuple of (metrics, measured target value) to the
* LLSP solution. The metrics array must have as many values as stated in count
* passed to llsp_new(). */
void llsp_add(llsp_t *restrict llsp, const double *restrict metrics, double target);
/* Solves the LLSP and returns a pointer to the resulting coefficients or NULL
* if the training phase could not be successfully finalized. The pointer
* remains valid until the LLSP context is freed. */
const double *llsp_solve(llsp_t *restrict llsp);
/* Predicts the target value from the given metrics. The context has to be
* populated with a set of prediction coefficients by running llsp_solve(). */
double llsp_predict(llsp_t *restrict llsp, const double *restrict metrics);
/* Frees the LLSP context. */
void llsp_dispose(llsp_t *restrict llsp);