예제 #1
0
void gammaexpo(){
    printf("gamma/exponential\n");
    apop_model *gamma = apop_model_set_parameters(apop_gamma, 1, 0.4);

    apop_model *drawfrom = apop_model_set_parameters(apop_exponential, 0.4);
    int draw_ct = 120;
    apop_data *draws = apop_model_draws(drawfrom, draw_ct);

    apop_model *gammaup = apop_update(draws, gamma, apop_exponential);
    apop_model_show(gammaup);

    gamma->more = apop_gamma;
    gamma->log_likelihood = fake_ll;
    Apop_settings_add_group(gamma, apop_mcmc, .burnin=.1, .periods=1e5,
            .proposal=apop_model_set_parameters(apop_normal, 1, .001));
    apop_model *upd = apop_update(draws, gamma, apop_exponential);
    apop_model *gammaed = apop_estimate(upd->data, apop_gamma);
    apop_model_show(gammaed);
    deciles(gammaed, gammaup, 3);

    Apop_settings_add_group(gamma, apop_mcmc, .burnin=.1, .periods=1e5,
            .proposal=apop_model_set_parameters(apop_normal, 1, .01));
    gamma->log_likelihood = NULL;
    apop_model *upd_r = apop_update(draws, gamma, apop_exponential);
    apop_model *gammafied2 = apop_estimate(apop_data_pmf_expand(upd_r->data, 2000), apop_gamma);
    deciles(gammafied2, gammaup, 5);
}
예제 #2
0
void betabinom(){
    apop_model *beta = apop_model_set_parameters(apop_beta, 10, 5);

    apop_model *drawfrom = apop_model_copy(apop_multinomial);
    drawfrom->parameters = apop_data_falloc((2), 30, .4);
    drawfrom->dsize = 2;
    int draw_ct = 80;
    apop_data *draws = apop_model_draws(drawfrom, draw_ct);

    apop_model *betaup = apop_update(draws, beta, apop_binomial);
    apop_model_show(betaup);

    beta->more = apop_beta;
    beta->log_likelihood = fake_ll;
    apop_model *bi = apop_model_fix_params(apop_model_set_parameters(apop_binomial, 30, NAN));
    apop_model *upd = apop_update(draws, beta, bi);
    apop_model *betaed = apop_estimate(upd->data, apop_beta);
    deciles(betaed, betaup, 1);

    beta->log_likelihood = NULL;
    apop_model *upd_r = apop_update(draws, beta, bi);
    betaed = apop_estimate(apop_data_pmf_expand(upd_r->data, 2000), apop_beta);
    deciles(betaed, betaup, 1);

    apop_data *d2 = apop_model_draws(upd, draw_ct*2);
    apop_model *d2m = apop_estimate(d2, apop_beta);
    deciles(d2m, betaup, 1);
}
예제 #3
0
void gammafish(){
    printf("gamma/poisson\n");
    apop_model *gamma = apop_model_set_parameters(apop_gamma, 1.5, 2.2);

    apop_model *drawfrom = apop_model_set_parameters(apop_poisson, 3.1);
    int draw_ct = 90;
    apop_data *draws = apop_model_draws(drawfrom, draw_ct);

    apop_model *gammaup = apop_update(draws, gamma, apop_poisson);
    apop_model_show(gammaup);

    gamma->more = apop_gamma;
    gamma->log_likelihood = fake_ll;
    apop_model *proposal = apop_model_fix_params(apop_model_set_parameters(apop_normal, NAN, 1));
    proposal->parameters = apop_data_falloc((1), .9);
    //apop_data_set(apop_settings_get(gamma, apop_mcmc, proposal)->parameters, .val=.9);
    Apop_settings_add_group(gamma, apop_mcmc, .burnin=.1, .periods=1e4, .proposal=proposal);
    apop_model *upd = apop_update(draws, gamma, apop_poisson);
    apop_model *gammafied = apop_estimate(upd->data, apop_gamma);
    deciles(gammafied, gammaup, 5);
    //Apop_settings_add_group(beta, apop_mcmc, .burnin=.4, .periods=1e4);
    gamma->log_likelihood = NULL;
    apop_model *upd_r = apop_update(draws, gamma, apop_poisson);
    apop_model *gammafied2 = apop_estimate(apop_data_pmf_expand(upd_r->data, 2000), apop_gamma);
    deciles(gammafied2, gammaup, 5);
    deciles(gammafied, gammafied2, 5);
}
예제 #4
0
void one_run(int grid_size, int pop_size){
    printf("------ A run with a %i X %i grid and %i agents:\n", grid_size, grid_size, pop_size);
    search_sim.dsize = pop_size;
    apop_data_set(search_sim.parameters, 0, .val=grid_size);
    apop_data_set(search_sim.parameters, 1, .val=pop_size);
    apop_model *model_out = apop_estimate(apop_model_draws(&search_sim, 1000), weibull);
    apop_model_show(model_out);
}
예제 #5
0
int main(){
    apop_data *locations = apop_data_falloc((5, 2),
                            1.1, 2.2,
                            4.8, 7.4,
                            2.9, 8.6,
                            -1.3, 3.7,
                            2.9, 1.1);
    Apop_model_add_group(min_distance, apop_mle, .method= "NM simplex",
                                                  .tolerance=1e-5);
    apop_model *est = apop_estimate(locations, min_distance);
    apop_model_show(est);
}
예제 #6
0
int main(){
    char outfile[] = "scatter.gplot";

    apop_db_open("data-metro.db");
    apop_data *data = apop_query_to_data("select riders, year from riders where station like 'Silver%%' and riders>0");
    apop_db_close();

    //The regression destroys your data, so copy it first.
    apop_data *data_copy = apop_data_copy(data);

    //Run OLS, display results on terminal
    apop_model *est = apop_estimate(data, apop_OLS);
    apop_model_show(est);

    //Prep the file with a header, then call the function.
    FILE *f = fopen(outfile, "w");
    fprintf(f,"set term postscript;\n set output \"scatter.eps\"\n set yrange [0:*]\n");
    apop_plot_line_and_scatter(data_copy, est, .output_pipe=f);
    fclose(f);
}