/*************************************************************************************** * A testing program for multivariate distributions * Using GSL -> www.gnu.org/software/gsl * Copyright (C) 2006 Ralph dos Santos Silva * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * AUTHOR * Ralph dos Santos Silva, address@hidden * March, 2006 ***************************************************************************************/ #include #include #include #include #include /* GSL - GNU Scientific Library */ /* #define GSL_CHECK_RANGE_OFF */ #include #include #include /* ----------------------------- */ #include #include /* ----------------------------- */ #include "rmv.h" int main(){ FILE *f; int k; unsigned long int initime; double result; gsl_vector *x = gsl_vector_calloc(3), *mean = gsl_vector_calloc(3); gsl_matrix *m = gsl_matrix_alloc(3,3), *rm = gsl_matrix_alloc(3,3); gsl_rng *r; time(&initime); r = gsl_rng_alloc(gsl_rng_mt19937); gsl_rng_set(r, initime); printf("The SEED is %li.\n\n",initime); gsl_matrix_set(m,0,0, 1.0); gsl_matrix_set(m,0,1, 0.2); gsl_matrix_set(m,0,2,-0.9); gsl_matrix_set(m,1,0, 0.2); gsl_matrix_set(m,1,1, 1.0); gsl_matrix_set(m,1,2, 0.1); gsl_matrix_set(m,2,0,-0.9); gsl_matrix_set(m,2,1, 0.1); gsl_matrix_set(m,2,2, 1.0); gsl_vector_set(x,0,0.1); gsl_vector_set(x,1,0.1); gsl_vector_set(x,2,0.1); result = dmvnorm(3,x,mean,m); fprintf(stdout,"norm = %g\n", result); gsl_vector_set(x,0,0.1); gsl_vector_set(x,1,0.1); gsl_vector_set(x,2,0.1); result = dmvt(3,x,mean,m,5); fprintf(stdout,"t = %g\n", result); f = fopen("test-n.txt","w"); for(k=0; k<10; k++){ rmvnorm(r,3,mean,m,x); fprintf(f, "%g %g %g\n",gsl_vector_get(x,0),gsl_vector_get(x,1),gsl_vector_get(x,2)); } fclose(f); f = fopen("test-t.txt","w"); for(k=0; k<10; k++){ rmvt(r,3,mean,m,5,x); fprintf(f, "%g %g %g\n",gsl_vector_get(x,0),gsl_vector_get(x,1),gsl_vector_get(x,2)); } fclose(f); f = fopen("test-w.txt","w"); for(k=0; k<1000; k++){ rwishart(r,3,5,m,rm); fprintf(f, "%g %g %g\n",gsl_matrix_get(rm,0,0),gsl_matrix_get(rm,0,1),gsl_matrix_get(rm,0,2)); fprintf(f, "%g %g %g\n",gsl_matrix_get(rm,1,0),gsl_matrix_get(rm,1,1),gsl_matrix_get(rm,1,2)); fprintf(f, "%g %g %g\n",gsl_matrix_get(rm,2,0),gsl_matrix_get(rm,2,1),gsl_matrix_get(rm,2,2)); } fclose(f); return 0; }