examples/test_random/test_random.c

Go to the documentation of this file.
00001 /*
00002    libit - Library for basic source and channel coding functions
00003    Copyright (C) 2005-2006 
00004    Francois Cayre Vivien Chappelier, Herve Jegou
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public
00017    License along with this library; if not, write to the Free
00018    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 */
00020 
00021 /** @file test_random.c Test program for random generator */
00022 
00023 #include <it/random.h>
00024 #include <it/vec.h>
00025 
00026 #define N 1000000
00027 
00028 int main ()
00029 {
00030   vec  v_z;
00031   double mu, s = 0, k = 0;
00032   int  i;
00033 
00034   v_z = vec_new (N);
00035 
00036   for (i = 0; i < N; i++)
00037     v_z[i] = it_randn ();
00038 
00039 
00040   mu = vec_mean (v_z);
00041 
00042   for (i = 0; i < N; i++) {
00043     s += pow (v_z[i] - mu, 3.);
00044     k += pow (v_z[i] - mu, 4.);
00045   }
00046 
00047   s /= (double) vec_length (v_z) - 1;
00048   k /= (double) vec_length (v_z) - 1;
00049 
00050   printf ("mu=%f\t sigma^2=%f\t skew=%f\t kurt=%f\n",
00051     vec_mean (v_z), vec_variance (v_z), s, k);
00052 
00053   printf ("JB=%e\n", (double) vec_length (v_z) / 6. * (s * s +
00054                    ((k - 3) * (k - 3))) / 4.);
00055 
00056   vec_delete (v_z);
00057   return 0;
00058 }

Hosted by
Copyright (C) 2005-2006 Hervé Jégou
Vivien Chappelier
Francois Cayre
libit logo courtesy of Jonathan Delhumeau