44#include "EST_multistats.h"
45#include "EST_cmd_line.h"
48static int ols_main(
int argc,
char **
argv);
84static int ols_main(
int argc,
char **
argv)
98 "Summary: Linear Regression by ordinary least squares (defaults in {})\n"+
99 "-desc <ifile> Field description file\n"+
100 "-data <ifile> Datafile, one vector per line\n"+
101 "-test <ifile> Datafile, for testing\n"+
102 "-robust Robust, may take longer\n"+
103 "-stepwise Order the features by contribution,\n"+
104 " implies robust.\n"+
105 "-swlimit <float> {0.0}\n"+
106 " Percentage necessary improvement for stepwise\n"+
107 "-quiet No summary\n"+
109 "-output <ofile> Output file for coefficients\n"+
110 "-ignore <string> Filename or bracket list of fields to ignore\n",
114 if (
al.present(
"-output"))
116 if (
al.present(
"-o"))
121 if (
al.present(
"-ignore"))
131 if (!
al.present(
"-desc"))
133 cerr <<
"ols: no description file specified\n";
141 if (!
al.present(
"-data"))
143 cerr <<
"ols: no data file specified\n";
147 wgn_load_dataset(
dataset,
al.val(
"-data"));
148 if (
al.present(
"-test"))
161 if (
al.present(
"-stepwise"))
168 names.
append(
"Intercept");
169 for (i=1; i <
dataset.width(); i++)
177 included.a_no_check(i) = OLS_IGNORE;
184 cerr <<
"OLS: failed stepwise ols" <<
endl;
188 else if (
al.present(
"-robust"))
198 included.a_no_check(i) = OLS_IGNORE;
205 cerr <<
"OLS: failed robust ols" <<
endl;
211 cerr <<
"OLS: failed no pseudo_inverse" <<
endl;
217 cerr <<
"OLS: failed to save coefficients in \"" <<
ofile <<
"\""
222 if (!
al.present(
"-quiet"))
241 X.resize(d.length(),d.width());
242 Y.resize(d.length(),1);
244 for (n=0,p=d.head(); p != 0; p=p->next(),n++)
246 Y.a_no_check(n,0) = d(p)->get_flt_val(0);
247 X.a_no_check(n,0) = 1;
248 for (
m=1;
m < d.width();
m++)
252 X.a_no_check(n,
m) = 0;
255 X.a_no_check(n,
m) = d(p)->get_flt_val(
m);
void append(const T &item)
add item onto end of list