![]() |
|
We've moved the setup documentation to Appendix O of Modeling with Data. Please see that page. This site has a few more notes for Windows users or MinGW users.
Here is another sample program, intended to show how one would integrate Apophenia into an existing program. For example, say that you are running a simulation of two different treatments, or say that two sensors are posting data at regular intervals. You need to gather the data in an organized form, and then ask questions of the resulting data set. Below, a thousand draws are made from the two processes and put into a database. Then, the data is pulled out, some simple statistics are compiled, and the data is written to a text file for inspection outside of the program. This program will compile cleanly with the sample Makefile.
#include <apop.h> //Your processes are probably a bit more complex. double process_one(gsl_rng *r){ return gsl_rng_uniform(r) * gsl_rng_uniform(r) ; } double process_two(gsl_rng *r){ return gsl_rng_uniform(r); } int main(){ apop_data *m; double p1, p2; int i; gsl_rng * r = apop_rng_alloc(); //create the database and the data table. apop_db_open("runs.db"); apop_table_exists("samples",1); //If the table already exists, delete it. apop_query("create table samples(iteration, process, value); begin;"); //populate the data table with runs. for (i=0; i<1000; i++){ p1 = process_one(r); p2 = process_two(r); apop_query("insert into samples values(%i, %i, %g);", i, 1, p1); apop_query("insert into samples values(%i, %i, %g);", i, 2, p2); } apop_query("commit;"); //the begin-commit wrapper saves writes to the drive. //pull the data from the database, converting it into a table along the way. m = apop_db_to_crosstab("samples", "iteration","process", "value"); Apop_col(m, 0, v1); //get vector views of the two table columns. Apop_col(m, 1, v2); //Output a table of means/variances, and t-test results. printf("\t mean\t\t var\n"); printf("process 1: %f\t%f\n", apop_mean(v1), apop_var(v1)); printf("process 2: %f\t%f\n\n", apop_mean(v2), apop_var(v2)); printf("t test\n"); apop_data_show(apop_t_test(v1, v2)); apop_data_print(m, "the_data.txt"); //does not overwrite; appends. return 0; }