int main(int argc, char* argv[]) { corpus* corpus; long t1; (void) time(&t1); seedMT(t1); // seedMT(4357U); if (argc > 1) { if (strcmp(argv[1], "est")==0) { INITIAL_ALPHA = atof(argv[2]); NTOPICS = atoi(argv[3]); read_settings(argv[4]); corpus = read_data(argv[5]); make_directory(argv[7]); run_em(argv[6], argv[7], corpus); } if (strcmp(argv[1], "inf")==0) { read_settings(argv[2]); corpus = read_data(argv[4]); infer(argv[3], argv[5], corpus); } } else { printf("usage : lda est [initial alpha] [k] [settings] [data] [random/seeded/*] [directory]\n"); printf(" lda inf [settings] [model] [data] [name]\n"); } return(0); }
int main(int argc, char **argv) { Optctx ctx; size_t i; FILE *f; localincpath = "."; optinit(&ctx, "sd:hmo:p:l:", argv, argc); while (!optdone(&ctx)) { switch (optnext(&ctx)) { case 'h': usage(argv[0]); exit(0); break; case 'p': pkgname = ctx.optarg; break; case 'o': outfile = ctx.optarg; break; case 'd': while (ctx.optarg && *ctx.optarg) debugopt[*ctx.optarg++ & 0x7f] = 1; break; case 'l': lappend(&extralibs, &nextralibs, ctx.optarg); break; default: usage(argv[0]); exit(0); break; } } if (!outfile && !show) { fprintf(stderr, "output file needed when merging usefiles.\n"); exit(1); } if (!pkgname) { fprintf(stderr, "package needed when merging usefiles.\n"); exit(1); } /* read and parse the file */ initfile(&file, outfile); updatens(file.globls, pkgname); for (i = 0; i < ctx.nargs; i++) mergeuse(ctx.args[i]); loaduses(); infer(); tagexports(1); addextlibs(extralibs, nextralibs); /* generate the usefile */ f = fopen(outfile, "w"); writeuse(f); fclose(f); return 0; }
void mk_quantifier_instantiation::instantiate_quantifier(quantifier* q, expr_ref_vector & conjs) { expr_ref qe(m); qe = q; m_var2cnst(qe); q = to_quantifier(qe); if (q->get_num_patterns() == 0) { proof_ref new_pr(m); pattern_inference_params params; pattern_inference infer(m, params); infer(q, qe, new_pr); q = to_quantifier(qe); } unsigned num_patterns = q->get_num_patterns(); for (unsigned i = 0; i < num_patterns; ++i) { expr * pat = q->get_pattern(i); SASSERT(m.is_pattern(pat)); instantiate_quantifier(q, to_app(pat), conjs); } }
int main(int argc, char **argv) { FILE *f; int opt; int i; while ((opt = getopt(argc, argv, "hud:I:")) != -1) { switch (opt) { case 'h': usage(argv[0]); exit(0); break; case 'u': fromuse = 1; break; case 'd': debug = 1; while (optarg && *optarg) debugopt[*optarg++ & 0x7f] = 1; break; case 'I': lappend(&incpaths, &nincpaths, optarg); break; default: usage(argv[0]); exit(0); break; } } for (i = optind; i < argc; i++) { lappend(&incpaths, &nincpaths, Instroot "/lib/myr"); file = mkfile(argv[i]); file->file.exports = mkstab(); file->file.globls = mkstab(); tyinit(file->file.globls); printf("%s:\n", argv[i]); if (fromuse) { f = fopen(argv[i], "r"); if (!f) die("Unable to open usefile %s\n", argv[i]); loaduse(f, file->file.globls); dumpsyms(file->file.globls, 1); } else { tokinit(argv[i]); yyparse(); infer(file); dumpsyms(file->file.globls, 1); } } return 0; }
beliefs_t *IPFP::calculateBeliefs(){ prev_marginals.resize(0); //Intialise all messages using simple junction tree inference Inference infer( moldata, cfg ); infer.runInferenceDownwardPass( down_msgs, cfg->model_depth ); //Initialise factor transition/persistence probabilities //(these will change on evidence so we need this copy) initialiseFactorProbsAndBeliefs(); //Apply Iterative Proportional Fitting Procedure or similar int num_iter = 0; if( cfg->ipfp_algorithm == IPFP_ALGORITHM ) num_iter = runIPFP(); else if( cfg->ipfp_algorithm == GEMA_ALGORITHM ) num_iter = runGEMA(); else if( cfg->ipfp_algorithm == IPFP_WITH_MOD_ALGORITHM ) num_iter = runIPFPwithOscAdjust(); else throw UnknownIPFPAlgorithmException(); if( status == COMPLETE_CONVERGE ){ // std::cout << "IPFP(GEMA) converged in " << num_iter << " iterations" << std::endl; return &beliefs; } if( status == CONVERGE_AFTER_MOD ){ // std::cout << "IPFP converged after oscillatory modification in " << num_iter << " iterations" << std::endl; return &beliefs; } if( status == NON_CONVERGE ){ std::cout << "Warning: IPFP did not converge: "; for( int i = 0; i < diff_buf.size(); i++ ) std::cout << diff_buf[i] << " "; return &beliefs; } std::cout << "Warning: Unknown return status from IPFP - " << status << std::endl; return &beliefs; }
tactic check_expr_tactic(elaborate_fn const & elab, expr const & e, std::string const & fname, pair<unsigned, unsigned> const & pos) { return tactic01([=](environment const & env, io_state const & ios, proof_state const & s) { goals const & gs = s.get_goals(); if (empty(gs)) { throw_no_goal_if_enabled(s); return none_proof_state(); } goal const & g = head(gs); name_generator ngen = s.get_ngen(); expr new_e = std::get<0>(elab(g, ios.get_options(), ngen.mk_child(), e, none_expr(), s.get_subst(), false)); auto tc = mk_type_checker(env, ngen.mk_child()); expr new_t = tc->infer(new_e).first; auto out = regular(env, ios); flycheck_information info(out); if (info.enabled()) { out << fname << ":" << pos.first << ":" << pos.second << ": information: "; out << "check result:\n"; } out << new_e << " : " << new_t << endl; return some_proof_state(s); }); }
int main(int argc, char **argv) { char buf[1024]; Stab *globls; Optctx ctx; size_t i; outfile = NULL; optinit(&ctx, "cd:?hSo:I:9G:", argv, argc); asmsyntax = Defaultasm; while (!optdone(&ctx)) { switch (optnext(&ctx)) { case 'o': outfile = ctx.optarg; break; case 'S': writeasm = 1; break; case '?': case 'h': usage(argv[0]); exit(0); break; case 'c': extracheck = 1; break; case 'd': while (ctx.optarg && *ctx.optarg) debugopt[*ctx.optarg++ & 0x7f]++; break; case '9': asmsyntax = Plan9; break; case 'G': if (!strcmp(ctx.optarg, "e")) asmsyntax = Gnugaself; else if (!strcmp(ctx.optarg, "m")) asmsyntax = Gnugasmacho; else die("unknown gnu syntax flavor"); break; case 'I': lappend(&incpaths, &nincpaths, ctx.optarg); break; default: usage(argv[0]); exit(0); break; } } lappend(&incpaths, &nincpaths, Instroot "/lib/myr"); if (ctx.nargs == 0) { fprintf(stderr, "No input files given\n"); exit(1); } else if (ctx.nargs > 1) outfile = NULL; for (i = 0; i < ctx.nargs; i++) { globls = mkstab(0); tyinit(globls); tokinit(ctx.args[i]); file = mkfile(ctx.args[i]); file->file.globls = globls; yyparse(); /* before we do anything to the parse */ if (debugopt['T']) dump(file, stdout); infer(file); if (hasmain(file)) geninit(file); tagexports(file, 0); /* after all type inference */ if (debugopt['t']) dump(file, stdout); if (writeasm) { if (outfile != NULL) swapout(buf, sizeof buf, ".s"); else swapsuffix(buf, sizeof buf, ctx.args[i], ".myr", ".s"); } else { gentempfile(buf, sizeof buf, ctx.args[i], ".s"); } genuse(ctx.args[i]); gen(file, buf); assemble(buf, ctx.args[i]); } return 0; }
tactic contradiction_tactic() { auto fn = [=](environment const & env, io_state const & ios, proof_state const & s) { goals const & gs = s.get_goals(); if (empty(gs)) { throw_no_goal_if_enabled(s); return optional<proof_state>(); } goal const & g = head(gs); expr const & t = g.get_type(); substitution subst = s.get_subst(); auto tc = mk_type_checker(env); auto conserv_tc = mk_type_checker(env, UnfoldReducible); buffer<expr> hyps; g.get_hyps(hyps); for (expr const & h : hyps) { expr h_type = mlocal_type(h); h_type = tc->whnf(h_type).first; expr lhs, rhs, arg; if (is_false(env, h_type)) { assign(subst, g, mk_false_rec(*tc, h, t)); return some_proof_state(proof_state(s, tail(gs), subst)); } else if (is_not(env, h_type, arg)) { optional<expr> h_pos; for (expr const & h_prime : hyps) { constraint_seq cs; if (conserv_tc->is_def_eq(arg, mlocal_type(h_prime), justification(), cs) && !cs) { h_pos = h_prime; break; } } if (h_pos) { assign(subst, g, mk_absurd(*tc, t, *h_pos, h)); return some_proof_state(proof_state(s, tail(gs), subst)); } } else if (is_eq(h_type, lhs, rhs)) { lhs = tc->whnf(lhs).first; rhs = tc->whnf(rhs).first; optional<name> lhs_c = is_constructor_app(env, lhs); optional<name> rhs_c = is_constructor_app(env, rhs); if (lhs_c && rhs_c && *lhs_c != *rhs_c) { if (optional<name> I_name = inductive::is_intro_rule(env, *lhs_c)) { name no_confusion(*I_name, "no_confusion"); try { expr I = tc->whnf(tc->infer(lhs).first).first; buffer<expr> args; expr I_fn = get_app_args(I, args); if (is_constant(I_fn)) { level t_lvl = sort_level(tc->ensure_type(t).first); expr V = mk_app(mk_app(mk_constant(no_confusion, cons(t_lvl, const_levels(I_fn))), args), t, lhs, rhs, h); if (auto r = lift_down_if_hott(*tc, V)) { check_term(*tc, *r); assign(subst, g, *r); return some_proof_state(proof_state(s, tail(gs), subst)); } } } catch (kernel_exception & ex) { regular(env, ios) << ex << "\n"; } } } } } return none_proof_state(); }; return tactic01(fn); }