Exemplo n.º 1
0
int main(){
    apop_data *d = apop_text_alloc(apop_data_alloc(6), 6, 1);
    apop_data_fill(d,   1,   2,   3,   3,   1,   2);
    apop_text_fill(d,  "A", "A", "A", "A", "A", "B");

    asprintf(&d->names->title, "Original data set");
    printdata(d);

        //binned, where bin ends are equidistant but not necessarily in the data
    apop_data *binned = apop_data_to_bins(d, NULL);
    asprintf(&binned->names->title, "Post binning");
    printdata(binned);
    assert(apop_sum(binned->weights)==6);
    assert(fabs(//equal distance between bins
              (apop_data_get(binned, 1, -1) - apop_data_get(binned, 0, -1))
            - (apop_data_get(binned, 2, -1) - apop_data_get(binned, 1, -1))) < 1e-5);

        //compressed, where the data is as in the original, but weights 
        //are redome to accommodate repeated observations.
    apop_data_pmf_compress(d);
    asprintf(&d->names->title, "Post compression");
    printdata(d);
    assert(apop_sum(d->weights)==6);

    apop_model *d_as_pmf = apop_estimate(d, apop_pmf);
    Apop_row(d, 0, firstrow); //1A
    assert(fabs(apop_p(firstrow, d_as_pmf) - 2./6 < 1e-5));
}
Exemplo n.º 2
0
int main(){
    apop_data *d1 = apop_text_alloc(NULL, 5, 1);
    apop_data *d2 = apop_text_alloc(NULL, 5, 1);
    apop_text_fill(d1, "A", "B", "C", "B", "B");
    apop_text_fill(d2, "B", "A", "D", "B", "B");
    apop_data_to_factors(d1);
    apop_data_show(d1);
    d2->more = apop_data_copy(apop_data_get_factor_names(d1, 0, 't'));
    printf("-----\n");
    apop_data_to_dummies(d2, .append='y');
    apop_data_show(d2);


    //some spot checks.
    assert(apop_data_get(d1, 2)==2);
    assert(apop_data_get(d2, 0, 0)==1);
    assert(apop_data_get(d2, 2, 0)==0);
    assert(apop_data_get(d2, 2, 1)==0);
    assert(apop_data_get(d2, 2, 2)==1);
    assert(apop_data_get(d2, 3, 0)==1);
}