40 #include "EST_multistats.h" 41 #include "EST_simplestats.h" 43 static void ols_load_selected_feats(
const EST_FMatrix &X,
46 static int ols_stepwise_find_best(
const EST_FMatrix &X,
63 if (!pseudo_inverse(X,Xplus))
66 multiply(Xplus,Y,coeffs);
79 for (i=0; i<included.
length(); i++)
82 return robust_ols(X,Y,included,coeffs);
97 int i,j,singularity=-1;
101 cerr <<
"OLS: less rows than columns, so cannot find solution." 107 cerr <<
"OLS: `included' list wrong size: internal error." 114 ols_load_selected_feats(X,included,Xl);
115 if (pseudo_inverse(Xl,Xplus,singularity))
117 multiply(Xplus,Y,coeffsl);
124 for (s=i=0; i<singularity; i++)
127 while ((included(s) == FALSE) ||
128 (included(s) == OLS_IGNORE))
131 if (included(s) == FALSE)
133 cerr <<
"OLS: found singularity twice, shouldn't happen" 139 cerr <<
"OLS: omitting singularity in column " << s << endl;
161 static void ols_load_selected_feats(
const EST_FMatrix &X,
167 for (width=i=0; i<included.
length(); i++)
168 if (included(i) == TRUE)
175 if (included(j) == TRUE)
192 multiply(samples,coeffs,res);
210 float best_score=0.0,bscore;
216 if (!ols_stepwise_find_best(X,Y,included,coeffsl,
217 bscore,best_feat,Xtest,Ytest,
220 cerr <<
"OLS: stepwise failed" << endl;
223 if ((bscore - (bscore * (limit/100))) <= best_score)
229 included[best_feat] = TRUE;
230 printf(
"FEATURE %d %s: %2.4f\n",
232 (
const char *)feat_names.
nth(best_feat),
242 static int ols_stepwise_find_best(
const EST_FMatrix &X,
258 for (i=0; i < included.
length(); i++)
265 if (!robust_ols(X,Y,included,coeffsl))
267 ols_apply(Xtest,coeffsl,pred);
268 ols_test(Ytest,pred,cor,rmse);
269 printf(
"tested %d %s %f best %f\n",
270 i,(
const char *)feat_names.
nth(i),cor,bscore);
271 if (fabs(cor) > bscore)
314 rmse = sqrt(se.
mean());
328 correlation = (xy.
mean() - (x.
mean()*y.
mean()))/ sqrt(v3);
336 if ((correlation <= 1.0) && (correlation >= -1.0))
int num_rows() const
return number of rows
INLINE const T & a_no_check(int n) const
read-only const access operator: without bounds checking
int num_columns() const
return number of columns
T & nth(int n)
return the Nth value
INLINE const T & a_no_check(int row, int col) const
const access with no bounds check, care recommend
double mean(void) const
mean of currently cummulated values
INLINE int length() const
number of items in vector.
void resize(int rows, int cols, int set=1)
resize matrix
void resize(int n, int set=1)
resize vector