Here are a few pieces of sample code, gathered from elsewhere in the documentation, for testing your installation or to give you a sense of what code with Apophenia's tools looks like. If you'd like more context or explanation, please click through to the page from which the example was taken.
In the documentation for the apop_ols model, a program to read in data and run a regression. You'll need to go to that page for the sample data and further discussion.
From the Setting up page, an example of gathering data from two processes, saving the input to a database, then doing a later analysis:
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(){
double p1, p2;
int i;
apop_query(
"create table samples(iteration, process, value); begin;");
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);
}
printf("\t mean\t\t var\n");
printf("t test\n");
}
In the An outline of the library section on map/apply, a new
-test on every row, with all operations acting on entire rows rather than individual data points:
double row_offset;
gsl_rng *r;
void offset_rng(double *v){*v = gsl_rng_uniform(r) + row_offset;}
double conf(double in, void *df){ return gsl_cdf_tdist_P(in, *(int *)df);}
int main(){
for (int i=0; i< 10; i++){
row_offset = gsl_rng_uniform(r)*2 -1;
Apop_row_v(d, i, onerow);
}
size_t df = d->matrix->size2-1;
#ifndef Testing
#endif
for (int i=0; i< 10; i++){
assert(fabs(gsl_cdf_tdist_Pinv(
apop_data_get(confidences, i, -1),100)
}
}
In the documentation for apop_query_to_text, a program to list all the tables in an SQLite database.
void print_table_list(char *db_file){
"from sqlite_master where type=='table'");
for(int i=0; i< tab_list->textsize[0]; i++)
printf("%s\n", tab_list->text[i][0]);
}
int main(int argc, char **argv){
if (argc == 1){
printf("Give me a database name, and I will print out "
"the list of tables contained therein.\n");
return 0;
}
print_table_list(argv[1]);
}
A demonstration of fixing parameters to create a marginal distribution, via apop_model_fix_params
int main(){
size_t ct = 5e4;
2, 0.5, 1);
gsl_vector_set_all(pvm->
parameters->vector, GSL_NAN);
#ifdef Testing
#else
printf("original params: ");
printf("estimated params: ");
#endif
}
Several uses of the apop_dot function
double eps=1e-3;
#define Diff(L, R) Apop_assert(fabs((L)-(R)<(eps)), "%g is too different from %g (abitrary limit=%g).", (double)(L), (double)(R), eps);
int main(){
int len = 3000;
gsl_vector *v = gsl_vector_alloc(len);
for (double i=0; i< len; i++) gsl_vector_set(v, i, 1./(i+1));
double square;
gsl_blas_ddot(v, v, &square);
#ifndef Testing
printf("1 + (1/2)^2 + (1/3)^2 + ...= %g\n", square);
#endif
double pi_over_six = gsl_pow_2(M_PI)/6.;
Diff(square, pi_over_six);
Diff(gsl_vector_get(vdotv->vector, 0), pi_over_six);
double scalarval = gsl_vector_get(mdotv->vector, 0);
Diff(scalarval, pi_over_six);
assert(mdotv2->error);
gsl_vector_view trace = gsl_matrix_diagonal(product_matrix->matrix);
double tracesum =
apop_sum(&trace.vector);
Diff(tracesum, pi_over_six);
gsl_matrix_free(dmr.matrix);
}