/* Return an argz string describing the current options. Fill *ARGZ with a pointer to newly malloced storage holding the list and *LEN to the length of that storage. */ error_t netfs_append_args (char **argz, size_t *argz_len) { char buf[80]; error_t err = 0; #define FOPT(opt, default, fmt, args...) \ do { \ if (! err && opt != default) \ { \ snprintf (buf, sizeof buf, fmt, ## args); \ err = argz_add (argz, argz_len, buf); \ } \ } while (0) FOPT (opt_clk_tck, OPT_CLK_TCK, "--clk-tck=%d", opt_clk_tck); FOPT (opt_stat_mode, OPT_STAT_MODE, "--stat-mode=%o", opt_stat_mode); FOPT (opt_fake_self, OPT_FAKE_SELF, "--fake-self=%d", opt_fake_self); FOPT (opt_anon_owner, OPT_ANON_OWNER, "--anonymous-owner=%d", opt_anon_owner); FOPT (opt_kernel_pid, OPT_KERNEL_PID, "--kernel-process=%d", opt_kernel_pid); #undef FOPT if (! err) err = netfs_append_std_options (argz, argz_len); return err; }
/* * Main method. * Read arguments, alphabet and samples. * Starts the BIC calculator. * Runs the champion trees selector. * Then runs the bootstrap method to return the selected Context Tree. */ int main(int argc, char** argv) { /* Parameters and defaults */ char* filename = NULL; unsigned int depth = 5; unsigned int size_resample_small = 30; unsigned int size_resample_large = 90; unsigned int number_resample_small = 10; unsigned int number_resample_large = 10; char *renewalstr = NULL; unsigned int seed = 0; char *c_method = NULL; int print_champs = 0; /* Process options */ int c, e = 0; while (1) { static struct option long_options[] = { {"file", required_argument, 0, 'f'}, {"depth", required_argument, 0, 'd'}, {"small-sample-percentage", required_argument, 0, 'p'}, {"large-sample-percentage", required_argument, 0, 'P'}, {"number-samples", required_argument, 0, 'n'}, {"number-large-samples", required_argument, 0, 'N'}, {"renewal-string", required_argument, 0, 'r'}, {"seed", required_argument, 0, 's'}, {"scale", required_argument, 0, 'k'}, {"champ-method", required_argument, 0, 'c'}, {"print-champs", no_argument, 0, 'C'}, {0, 0, 0, 0} }; int option_index = 0; c = getopt_long (argc, argv, "f:d:p:P:n:N:r:s:c:k:C", long_options, &option_index); if ( c == -1) break; switch ( c ) { SOPT('f', "filename", filename); IOPT('d', "depth", depth); IOPT('p', "small sample percentage", size_resample_small); IOPT('P', "large sample percentage", size_resample_large); IOPT('n', "small resample number", number_resample_small); IOPT('N', "large resample number", number_resample_large); IOPT('s', "seed", seed); FOPT('k', "scale", scale); SOPT('r', "renewal string", renewalstr); SOPT('c', "champ method", c_method); NOPT('C', print_champs); case '?': e = 1; } } DEB("file %s\ndepth %d\nsmall p %d\nlarge p %d\nsmall num %d\nlarge num %d\nseed %d\nren %s\n", filename,depth,size_resample_small,size_resample_large,number_resample_small,number_resample_large,seed,renewalstr); champ_method = !c_method || c_method[0] != 'o'; if(e){ usage(); exit(0); } if (optind < argc && !filename) filename = strdup(argv[optind]); if(!filename) fatal_error(MISSING_FILENAME); Tree_node prob_root = Tree_create(PROB); Tree_node bic_root = Tree_create(BIC); char** sample = read_lines(filename); setup_BIC(sample, depth, prob_root, bic_root); // pre calculations // champions set calculation Champion_item champion_bics = champion_set(bic_root, Max_c(prob_root), Eps(prob_root)); if (print_champs){ ITERA(Champion_item, champion_item, champion_bics, next) { printf("c=%f tree=[ ", champion_item->tau->c); print_Tau(champion_item->tau); printf("]\n"); } }