50 static int ols_main(
int argc,
char **argv);
52 int main(
int argc,
char **argv)
54 return ols_main(argc,argv);
57 static int ols_main(
int argc,
char **argv)
71 "Summary: Linear Regression by ordinary least squares (defaults in {})\n"+
72 "-desc <ifile> Field description file\n"+
73 "-data <ifile> Datafile, one vector per line\n"+
74 "-test <ifile> Datafile, for testing\n"+
75 "-robust Robust, may take longer\n"+
76 "-stepwise Order the features by contribution,\n"+
78 "-swlimit <float> {0.0}\n"+
79 " Percentage necessary improvement for stepwise\n"+
80 "-quiet No summary\n"+
82 "-output <ofile> Output file for coefficients\n"+
83 "-ignore <string> Filename or bracket list of fields to ignore\n",
88 ofile = al.
val(
"-output");
100 ignores =
vload(ig,1);
106 cerr <<
"ols: no description file specified\n";
116 cerr <<
"ols: no data file specified\n";
126 load_ols_data(Xtest,Ytest,test_dataset);
130 load_ols_data(Xtest,Ytest,dataset);
132 load_ols_data(X,Y,dataset);
137 float swlimit = al.
fval(
"-swlimit");
141 names.
append(
"Intercept");
142 for (i=1; i < dataset.
width(); i++)
147 for (i=1; i<included.
length(); i++)
155 if (!
stepwise_ols(X,Y,names,swlimit,coeffs,Xtest,Ytest,included))
157 cerr <<
"OLS: failed stepwise ols" << endl;
161 else if (al.
present(
"-robust"))
168 for (i=1; i<included.
length(); i++)
178 cerr <<
"OLS: failed robust ols" << endl;
182 else if (!
ols(X,Y,coeffs))
184 cerr <<
"OLS: failed no pseudo_inverse" << endl;
190 cerr <<
"OLS: failed to save coefficients in \"" << ofile <<
"\"" 203 printf(
";; RMSE %f Correlation is %f\n",rmse,cor);
217 for (n=0,p=d.
head(); p != 0; p=p->
next(),n++)
221 for (m=1; m < d.
width(); m++)
int ols_test(const EST_FMatrix &real, const EST_FMatrix &predicted, float &correlation, float &rmse)
int robust_ols(const EST_FMatrix &X, const EST_FMatrix &Y, EST_FMatrix &coeffs)
int ols(const EST_FMatrix &X, const EST_FMatrix &Y, EST_FMatrix &coeffs)
ssize_t num_columns() const
return number of columns
INLINE const T & a_no_check(ssize_t n) const
read-only const access operator: without bounds checking
float fval(const EST_String &rkey, int m=1) const
EST_write_status save(const EST_String &filename, const EST_String &type=EST_FMatrix::default_file_type)
Save in file (ascii or binary)
int main(int argc, char **argv)
LISP vload(const char *fname, long cflag)
INLINE ssize_t length() const
number of items in vector.
int stepwise_ols(const EST_FMatrix &X, const EST_FMatrix &Y, const EST_StrList &feat_names, float limit, EST_FMatrix &coeffs, const EST_FMatrix &Xtest, const EST_FMatrix &Ytest, EST_IVector &included)
The file was written successfully.
LISP read_from_string(const char *)
int ols_apply(const EST_FMatrix &samples, const EST_FMatrix &coeffs, EST_FMatrix &res)
const EST_String & feat_name(const int &i) const
const V & val(const K &rkey, bool m=0) const
return value according to key (const)
void append(const T &item)
add item onto end of list
void ignore_non_numbers()
int present(const K &rkey) const
Returns true if key is present.
void wgn_load_dataset(WDataSet &ds, EST_String fname)
int siod_init(int heap_size=DEFAULT_HEAP_SIZE)
INLINE const T & a_no_check(ssize_t row, ssize_t col) const
const access with no bounds check, care recommend
void resize(int rows, int cols, int set=1)
resize matrix
int parse_command_line(int argc, char *argv[], const EST_String &usage, EST_StrList &files, EST_Option &al, int make_stdio=1)
void load_description(const EST_String &descfname, LISP ignores)
void resize(int n, int set=1)
resize vector