52 static int wagon_test_main(
int argc,
char **argv);
53 static LISP find_feature_value(
const char *feature,
54 LISP vector, LISP description);
55 static LISP wagon_vector_predict(LISP
tree, LISP vector, LISP description);
58 LISP
tree, LISP description,
int all_info);
60 LISP
tree, LISP description);
62 LISP
tree, LISP description);
65 int main(
int argc,
char **argv)
68 wagon_test_main(argc,argv);
74 static int wagon_test_main(
int argc,
char **argv)
86 "Summary: program to test CART models on data\n"+
87 "-desc <ifile> Field description file\n"+
88 "-data <ifile> Datafile, one vector per line\n"+
89 "-tree <ifile> File containing CART tree\n"+
91 " track for vertex indices\n"+
92 "-predict Predict for each vector returning full vector\n"+
93 "-predict_val Predict for each vector returning just value\n"+
94 "-predictee <string>\n"+
95 " name of field to predict (default is first field)\n"+
96 "-heap <int> {210000}\n"+
97 " Set size of Lisp heap, should not normally need\n"+
98 " to be changed from its default\n"+
99 "-o <ofile> File to save output in\n",
111 cerr << argv[0] <<
": no description file specified" << endl;
121 cerr << argv[0] <<
": no tree found in \"" << al.
val(
"-tree")
128 cerr << argv[0] <<
": no tree file specified" << endl;
134 if (data.
open(al.
val(
"-data")) != 0)
136 cerr << argv[0] <<
": can't open data file \"" <<
137 al.
val(
"-data") <<
"\" for input." << endl;
143 cerr << argv[0] <<
": no data file specified" << endl;
154 if ((wgn_output = fopen(al.
val(
"-o"),
"w")) ==
NULL)
156 cerr << argv[0] <<
": can't open output file \"" <<
157 al.
val(
"-o") <<
"\"" << endl;
168 for (l=description,i=0; l !=
NIL; l=
cdr(l),i++)
177 "\" not in description\n";
180 const char *predict_type =
184 simple_predict(data,wgn_output,tree,description,
FALSE);
185 else if (al.
present(
"-predict_val"))
186 simple_predict(data,wgn_output,tree,description,
TRUE);
187 else if (
streq(predict_type,
"float") ||
188 streq(predict_type,
"int"))
189 test_tree_float(data,wgn_output,tree,description);
191 else if (
streq(predict_type,
"vector"))
192 test_tree_vector(data,wgn_output,tree,description);
195 test_tree_class(data,wgn_output,tree,description);
197 if (wgn_output != stdout)
211 for (d=description; d !=
NIL; d=
cdr(d))
217 cerr <<
"wagon_test: unexpected newline within vector " <<
218 t.
row() <<
" wrong number of features" << endl;
235 LISP
tree, LISP description,
int all_info)
240 for (vector=get_data_vector(data,description);
241 vector !=
NIL; vector=get_data_vector(data,description))
243 predict = wagon_vector_predict(
tree,vector,description);
248 fprintf(output,
"%s\n",(
const char *)val);
253 LISP
tree, LISP description)
256 float predict_val,real_val;
261 for (vector=get_data_vector(data,description);
262 vector !=
NIL; vector=get_data_vector(data,description))
264 predict = wagon_vector_predict(
tree,vector,description);
269 error = predict_val-real_val;
272 xx += predict_val*predict_val;
273 yy += real_val*real_val;
274 xy += predict_val*real_val;
281 fprintf(output,
";; RMSE %1.4f Correlation is %1.4f Mean (abs) Error %1.4f (%1.4f)\n",
289 LISP
tree, LISP description)
295 LISP vector,w,predict;
299 for (vector=get_data_vector(data,description);
300 vector !=
NIL; vector=get_data_vector(data,description))
302 predict = wagon_vector_predict(
tree,vector,description);
312 pairs.
add_item(real_class,predict_class,1);
319 fprintf(stdout,
";; entropy %g perplexity %g\n",
320 (-1*(H/Q)),pow(2.0,(-1*(H/Q))));
325 LISP
tree, LISP description)
333 LISP vector,w,predict;
337 for (vector=get_data_vector(data,description);
338 vector !=
NIL; vector=get_data_vector(data,description))
340 predict = wagon_vector_predict(
tree,vector,description);
350 pairs.
add_item(real_class,predict_class,1);
357 fprintf(stdout,
";; entropy %g perplexity %g\n",
358 (-1*(H/Q)),pow(2.0,(-1*(H/Q))));
362 static LISP wagon_vector_predict(LISP
tree, LISP vector, LISP description)
370 vector, description);
374 return wagon_vector_predict(
car(
cdr(
tree)),vector,description);
377 return wagon_vector_predict(
car(
cdr(
cdr(
tree))),vector,description);
380 static LISP find_feature_value(
const char *feature,
381 LISP vector, LISP description)
385 for (v=vector,d=description; v !=
NIL; v=
cdr(v),d=
cdr(d))
389 cerr <<
"wagon_test: can't find feature \"" << feature <<
390 "\" in description" << endl;
int row(void) const
Line number in original EST_TokenStream.
EST_TokenStream & get(EST_Token &t)
get next token in stream
int main(int argc, char **argv)
int contains(const char *s, ssize_t pos=-1) const
Does it contain this substring?
float get_c_float(LISP x)
double stddev(void) const
standard deviation of currently cummulated values
int ival(const EST_String &rkey, int m=1) const
double mean(void) const
mean of currently cummulated values
void close(void)
Close stream.
LISP strintern(const char *data)
const EST_String & whitespace()
LISP siod_assoc_str(const char *key, LISP alist)
LISP siod_nth(int nth, LISP list)
EST_Track error(EST_Track &ref, EST_Track &test, int relax=0)
int open(const EST_String &filename)
open a EST_TokenStream for a file.
LISP vload(const char *fname, long cflag)
const char * get_c_string(LISP x)
void print_confusion(const EST_FMatrix &a, EST_StrStr_KVL &list, EST_StrList &lex)
EST_read_status load(const EST_String name, float ishift=0.0, float startt=0.0)
EST_String siod_sprint(LISP exp)
LISP cons(LISP x, LISP y)
EST_FMatrix confusion(EST_StrStr_KVL &list, EST_StrList &lex)
const V & val(const K &rkey, bool m=0) const
return value according to key (const)
EST_String wgn_predictee_name
void append(const T &item)
add item onto end of list
int add_item(const K &rkey, const V &rval, int no_search=0)
add key-val pair to list
EST_Track wgn_VertexTrack
const EST_String & string() const
int wagon_ask_question(LISP question, LISP value)
int present(const K &rkey) const
Returns true if key is present.
void gc_protect(LISP *location)
int siod_init(int heap_size=DEFAULT_HEAP_SIZE)
void reverse(EST_Wave &sig)
LISP siod_member_str(const char *key, LISP list)
int parse_command_line(int argc, char *argv[], const EST_String &usage, EST_StrList &files, EST_Option &al, int make_stdio=1)
#define wgn_ques_feature(X)