/* * Test the result for the bic calculator. */ int main(int argc, char** argv) { char** samples = read_lines(argv[1]); int depth = strtod(argv[2], NULL); setup_BIC(samples, depth, prob_root, bic_root); print_tree(prob_root, depth); printf("----------------\n"); // print_tree(bic_root, ""); printf("\nlogN=%f\n\n",logN); // int n = size_of_sample(); get_T(prob_root); print_tree(prob_root, depth); Vec c = get_Tvec(prob_root); print_Vec(c); sort_Vec(c); uniquefy_Vec(c); print_Vec(c); for(int i = 0; i < c->len; i++) c->x[i] /= logN; print_Vec(c); Champion_item champs = champion_set_from_vec(c); ITERA(Champion_item, cs, champs, next) { pprint_Tau(cs->tau); printf("\n"); }
/* * Test the result for the bic calculator. */ int main(int argc, char** argv) { char** samples = read_lines(argv[1]); double c = strtod(argv[2], NULL); setup_BIC(samples, 5); Tau* tao = calculate_BIC(c); Tau_item* item = tao->item; while (item != NULL) { printf("%s ", item->string); item = item->next; } printf("\n"); }
/* * Calculates delta^(tau_i, tau_{i+1})(n,b) */ double delta_tau(char** sample, Tau* current_tree, Tau* next_tree, int depth) { setup_BIC(sample, depth); double l_tau1 = L_tau(current_tree); double l_tau2 = L_tau(next_tree); // both l_tau are really close to 0 (10^-100 ~ 10^-300). So the logs below return -infinity double result = (log10(l_tau1) - log10(l_tau2))/pow(size_of_sample(), 0.9f); /* this code is commented but may be uncommented for debugging purposes printf("l_tau1=%g\n", l_tau1); printf("l_tau2=%g\n", l_tau2); printf("/pow...=%g\n",pow(size_of_sample(), 0.9f)); printf("log(l_tau1)=%g\n",log10(l_tau1)); printf("log(l_tau2)=%g\n",log10(l_tau2)); printf("delta log=%g\n",log10(l_tau1) - log10(l_tau2)); printf("tudo=%g\n", result); */ return result; }
/* * Test the result for the bic calculator. */ int main(int argc, char** argv) { char** samples = read_lines(argv[1]); int depth = strtod(argv[2], NULL); setup_BIC(samples, depth, prob_root, bic_root); print_tree(prob_root, -(depth+1)); printf("\n-----------------\n"); printf("Most: %p\n", most_frequent_leaf(prob_root)); printf("most: %p\n", most_frequent_child(prob_root)); printf("\n-----------------\n"); for(Tree_node t = next_node_depth(prob_root, max_word_size); t; t = next_node_depth(t, max_word_size)) printf("%p\n",t); }
/* * 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"); } }