📄 predict-main.c
字号:
/****************************************************************************** predict-main.c - driver program for using a learned hypothesis to predict******************************************************************************/#include <stdio.h>#include <math.h>#include "ripper.h"#include "protos.h"#include "mdb.h"/******************************************************************************/char *Program="predict";char *Help_str[] = { "syntax: predict [options] stem", " predict classes of new instances using a ruleset", "", " output is a 'prediction file' in which each line corresponds to an" " instance and contains: Predicted-Class P N Real-Class", "", "options are:", " -e: echo hypothesis (don't predict)", " -v#: set trace level to #", " -s: predict examples taken from stdin, not stem.test", " -V: output predictions as 'vector', ie for each instance,", " output a line: P1 N1 ... Pk Nk Real-Class", " where pi ni are the counts associated with the ", " best rule predicting class i, and classes are ordered", " as in the names file.", NULL};/*****************************************************************************/int main(argc,argv)int argc;char *argv[];{ char *stem; concept_t *hyp; int o; FILE *cfp; BOOL echo=FALSE; BOOL use_stdin=FALSE; BOOL predict_all_classes=FALSE; example_t *ex; ex_count_t p,n; symbol_t *pred_class,*actual_class; atom_t *tok; int i; symbol_t *classi; while ((o=getopt(argc,argv,"v:teusV"))!=EOF) { switch (o) { case 'V': predict_all_classes = TRUE; break; case 'v': set_trace_level(atoi(optarg)); break; case 'e': echo = TRUE; break; case 's': use_stdin = TRUE; break; case '?': default: give_help(); fatal("option not implemented"); } } if (optind<argc) { stem = argv[optind++]; } else { give_help(); fatal("no file stem specified"); } if (optind<argc) { warning("not all arguments were used: %s ...",argv[optind]); } /* now load the hypothesis */ ld_names(add_ext(stem,".names")); if ((cfp=fopen(add_ext(stem,".hyp"),"r"))==NULL) { fatal("can't open concept file"); } hyp = ld_concept(cfp); if (echo) { printf("Hypothesis has %d rules, %d conditions:\n", vmax(hyp->rules),concept_size(hyp)); print_concept(hyp); exit(0); } if (use_stdin) { lex_open(NULL); /* open stdin */ } else { lex_open(add_ext(stem,".test")); } while ((tok=lex())!=NULL) { if (names_defined()) ex = ld_example(tok); else ex = ld_unconstrained_example(tok); if (verify_infer_names(ex)) { if (predict_all_classes) { for (i=0; i<vmax(Classes); i++) { classi = vref(atom_t,Classes,i)->nom; class_counts(hyp,ex->inst,classi,&p,&n); printf("%g %g ",p,n); } } else { pred_class = classify_counts(hyp,ex->inst,&p,&n); print_symbol(pred_class); printf(" %g %g ",p,n); } actual_class = ex->lab.nom; print_symbol(actual_class); printf("\n"); } } lex_close();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -