1 #include "a/regress_simple.h"
3 void a_regress_simple_init(a_regress_simple
*ctx
, a_float coef
, a_float bias
)
9 a_float
a_regress_simple_eval(a_regress_simple
const *ctx
, a_float val
)
11 return ctx
->coef
* val
+ ctx
->bias
;
14 a_float
a_regress_simple_evar(a_regress_simple
const *ctx
, a_float val
)
16 return (val
- ctx
->bias
) / ctx
->coef
;
19 void a_regress_simple_olsm_(a_regress_simple
*ctx
, a_size n
, a_float
const *x
, a_float
const *y
, a_float x_mean
, a_float y_mean
)
21 a_float num
= 0, den
= 0;
24 a_float dy
= *y
++ - y_mean
;
25 a_float dx
= *x
++ - x_mean
;
29 ctx
->coef
= num
/ den
;
30 ctx
->bias
= y_mean
- ctx
->coef
* x_mean
;
33 void a_regress_simple_olsm(a_regress_simple
*ctx
, a_size n
, a_float
const *x
, a_float
const *y
)
35 a_float
const x_mean
= a_float_mean(x
, n
);
36 a_float
const y_mean
= a_float_mean(y
, n
);
37 a_regress_simple_olsm_(ctx
, n
, x
, y
, x_mean
, y_mean
);
40 void a_regress_simple_zero(a_regress_simple
*ctx
)