-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiple-lin-reg-fn.h
52 lines (52 loc) · 2.74 KB
/
multiple-lin-reg-fn.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
/* =================================================================
multiple-lin-reg.h
Note you must include "matrix.h" before using this code
multiple variable linear regression
Based on an idea in "Programming Classic, Implementing the World's Best Algorithms" chapeter 12.4
by Ian Oliver.
*/
/*----------------------------------------------------------------------------
* Copyright (c) 2014,2022 Peter Miller
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*--------------------------------------------------------------------------*/
#ifndef _multiple_lin_reg_fn_h
#define _multiple_lin_reg_fn_h
#include "matrix.h" /* as matrix_ld used below */
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
enum reg_types {reg_poly,reg_sqrt,reg_rat}; /* types of linear regression supported */
void multi_regression(float *x_arr,float *y_arr,enum reg_types r, int N ,size_t SampleSize, matrix_ld S, long double Mean[], bool Used[],long double Fraction,void (*filter_callback)(size_t i, size_t imax)) ;
// do full regression
// float *x_arr,float *y_arr,enum reg_types r - input: x values, y values and a function to calculate other params
// reg_types is one from enum above.
// N is number of variables to be fitted
// SampleSize is size of x_arr &y_arr (both are indexed from 0 to SampleSize-1 )
// S is long double[N+1][N+1] - output
// Mean is long double[N+1] - output
// used is bool[N+1] - output
// Fraction is 0..1 with 0 giving the most accurate fit (used to drop variables that only make a small change to accuracy of fit) - input
void test_multiregression(int mode); // test program , mode is 0,1,2,3
#ifdef __cplusplus
}
#endif
#endif