~ubuntu-branches/debian/sid/apophenia/sid

« back to all changes in this revision

Viewing changes to eg/test_kl_divergence.c

  • Committer: Package Import Robot
  • Author(s): Jerome Benoit
  • Date: 2014-09-11 12:36:28 UTC
  • Revision ID: package-import@ubuntu.com-20140911123628-mhyqci1xk9tjicph
Tags: upstream-0.999b+ds1
ImportĀ upstreamĀ versionĀ 0.999b+ds1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <apop.h>
 
2
int main(){
 
3
    gsl_rng *r = apop_rng_alloc(2312311);
 
4
    int empirical_size = 5e3;
 
5
    apop_model *expo = apop_model_set_parameters(apop_exponential, 1.7);
 
6
    assert (apop_kl_divergence(expo, expo) < 1e-4);
 
7
    apop_data *empirical = apop_data_alloc(empirical_size, 1);
 
8
    for (int i=0; i<empirical_size; i++)
 
9
        apop_draw(apop_data_ptr(empirical, i, 0), r, expo);
 
10
    apop_model *pmf = apop_estimate(empirical, apop_pmf);
 
11
    assert(apop_kl_divergence(pmf,expo) < 1e-4);
 
12
    apop_data_free(empirical);
 
13
}