1# $Id: t_cstd.conf 3267 2006-11-17 20:18:28Z leydold $ 2############################################################################# 3 4[main] 5 6[main - data:] 7 8# method (for information only: the program scans the file name) 9method: MVSTD 10 11[main - header:] 12 13/* prototypes */ 14 15\#define COMPARE_SAMPLE_SIZE (500) 16\#define VIOLATE_SAMPLE_SIZE (20) 17 18/* \#define SEED (298346) */ 19 20/* we need marginal distributions for the chi2 tests */ 21\#define unur_distr_multinormal unur_distr_multinormal_w_marginals 22 23############################################################################# 24 25[new] 26 27[new - invalid NULL ptr: 28 distr = NULL; ] 29 30~( distr ); 31 --> expected_NULL --> UNUR_ERR_NULL 32 33[new - invalid distribution type: 34 distr = unur_distr_cont_new(); ] 35 36~( distr ); 37 --> expected_NULL --> UNUR_ERR_DISTR_INVALID 38 39[new - not a standard distribution: 40 distr = unur_distr_cvec_new(3); ] 41 42~( distr ); 43 --> expected_NULL --> UNUR_ERR_DISTR_INVALID 44 45############################################################################# 46 47# [set] 48 49############################################################################# 50 51# [get] 52 53############################################################################# 54 55# [chg] 56 57############################################################################# 58 59# [init] 60 61############################################################################# 62 63[reinit] 64 65[reinit - exists: 66 distr = unur_distr_multinormal(3,NULL,NULL); 67 par = unur_mvstd_new(distr); 68 gen = unur_init( par ); <-- ! NULL ] 69 70unur_reinit( gen ); 71 --> expected_reinit 72 73############################################################################# 74 75[sample] 76 77[sample - compare clone: 78 const int dim = 3; 79 double mean[] = {1.,2.,3.}; 80 double covar[] = { 2., 2., 1., 2., 4., 3., 1., 3., 3. }; 81 UNUR_GEN *clone; 82 distr = unur_distr_multinormal( dim, mean, covar ); 83 par = NULL; 84 gen = NULL; ] 85 86/* normal distribution */ 87par = unur_mvstd_new(distr); 88gen = unur_init( par ); 89 -->compare_sequence_gen_start 90 91/* clone */ 92clone = unur_gen_clone(gen); 93unur_free(gen); 94gen = clone; 95 -->compare_sequence_gen 96 97 98############################################################################# 99 100[validate] 101 102[validate - generators:] 103 104# default program 105par[0] = unur_mvstd_new(@distr@); 106 107# default variant but reinitialized with changed distribution 108{ UNUR_DISTR *dg =NULL; 109double mean[] = { -1., 2., -3. }; 110double covar[] = { 1., 0.8, 0.64, 0.8, 1., 0.8, 0.64, 0.8, 1. }; 111par[1] = unur_mvstd_new(@distr@); 112dg = unur_get_distr(gen); 113unur_distr_cvec_set_mean(dg,mean); 114unur_distr_cvec_set_covar(dg,covar); 115unur_reinit(gen); } 116 117 118[validate - distributions:] 119 120# standard multinormal distribution 121distr[0] = unur_distr_multinormal(3,NULL,NULL); 122 123# multinormal distribution, dim = 3 124double mean[] = { -1., 2., -3. }; 125double covar[] = { 1., 0.8, 0.64, 0.8, 1., 0.8, 0.64, 0.8, 1. }; 126distr[1] = unur_distr_multinormal(3,mean,covar); 127 128# random multinormal distribution 129\#define dim (2) 130int i; 131double mean[dim], covar[dim*dim]; 132UNUR_DISTR *covar_distr; 133UNUR_GEN *covar_gen; 134UNUR_GEN *mean_gen; 135covar_distr = unur_distr_correlation(dim); 136covar_gen = unur_init(unur_mcorr_new(covar_distr)); 137mean_gen = unur_str2gen("normal(5,1)"); 138for (i=0; i<dim; i++) 139 mean[i] = unur_sample_cont(mean_gen); 140do { 141 unur_sample_matr(covar_gen,covar); 142 distr[2] = unur_distr_multinormal(dim,mean,covar); 143} while (distr[2]==NULL); 144unur_distr_free(covar_distr); 145unur_free(covar_gen); 146unur_free(mean_gen); 147\#undef dim 148 149 150# random multinormal distribution 151\#define dim (3) 152int i; 153double mean[dim], covar[dim*dim]; 154UNUR_DISTR *covar_distr; 155UNUR_GEN *covar_gen; 156UNUR_GEN *mean_gen; 157covar_distr = unur_distr_correlation(dim); 158covar_gen = unur_init(unur_mcorr_new(covar_distr)); 159mean_gen = unur_str2gen("normal(5,1)"); 160for (i=0; i<dim; i++) 161 mean[i] = unur_sample_cont(mean_gen); 162do { 163 unur_sample_matr(covar_gen,covar); 164 distr[3] = unur_distr_multinormal(dim,mean,covar); 165} while (distr[3]==NULL); 166unur_distr_free(covar_distr); 167unur_free(covar_gen); 168unur_free(mean_gen); 169\#undef dim 170 171 172# random multinormal distribution 173\#define dim (4) 174int i; 175double mean[dim], covar[dim*dim]; 176UNUR_DISTR *covar_distr; 177UNUR_GEN *covar_gen; 178UNUR_GEN *mean_gen; 179covar_distr = unur_distr_correlation(dim); 180covar_gen = unur_init(unur_mcorr_new(covar_distr)); 181mean_gen = unur_str2gen("normal(5,1)"); 182for (i=0; i<dim; i++) 183 mean[i] = unur_sample_cont(mean_gen); 184do { 185 unur_sample_matr(covar_gen,covar); 186 distr[4] = unur_distr_multinormal(dim,mean,covar); 187} while (distr[4]==NULL); 188unur_distr_free(covar_distr); 189unur_free(covar_gen); 190unur_free(mean_gen); 191\#undef dim 192 193 194# random multinormal distribution 195\#define dim (5) 196int i; 197double mean[dim], covar[dim*dim]; 198UNUR_DISTR *covar_distr; 199UNUR_GEN *covar_gen; 200UNUR_GEN *mean_gen; 201covar_distr = unur_distr_correlation(dim); 202covar_gen = unur_init(unur_mcorr_new(covar_distr)); 203mean_gen = unur_str2gen("normal(5,1)"); 204for (i=0; i<dim; i++) 205 mean[i] = unur_sample_cont(mean_gen); 206do { 207 unur_sample_matr(covar_gen,covar); 208 distr[5] = unur_distr_multinormal(dim,mean,covar); 209} while (distr[5]==NULL); 210unur_distr_free(covar_distr); 211unur_free(covar_gen); 212unur_free(mean_gen); 213\#undef dim 214 215 216# random multinormal distribution 217\#define dim (7) 218int i; 219double mean[dim], covar[dim*dim]; 220UNUR_DISTR *covar_distr; 221UNUR_GEN *covar_gen; 222UNUR_GEN *mean_gen; 223covar_distr = unur_distr_correlation(dim); 224covar_gen = unur_init(unur_mcorr_new(covar_distr)); 225mean_gen = unur_str2gen("normal(5,1)"); 226for (i=0; i<dim; i++) 227 mean[i] = unur_sample_cont(mean_gen); 228do { 229 unur_sample_matr(covar_gen,covar); 230 distr[6] = unur_distr_multinormal(dim,mean,covar); 231} while (distr[6]==NULL); 232unur_distr_free(covar_distr); 233unur_free(covar_gen); 234unur_free(mean_gen); 235\#undef dim 236 237 238# random multinormal distribution 239\#define dim (10) 240int i; 241double mean[dim], covar[dim*dim]; 242UNUR_DISTR *covar_distr; 243UNUR_GEN *covar_gen; 244UNUR_GEN *mean_gen; 245covar_distr = unur_distr_correlation(dim); 246covar_gen = unur_init(unur_mcorr_new(covar_distr)); 247mean_gen = unur_str2gen("normal(5,1)"); 248for (i=0; i<dim; i++) 249 mean[i] = unur_sample_cont(mean_gen); 250do { 251 unur_sample_matr(covar_gen,covar); 252 distr[7] = unur_distr_multinormal(dim,mean,covar); 253} while (distr[7]==NULL); 254unur_distr_free(covar_distr); 255unur_free(covar_gen); 256unur_free(mean_gen); 257\#undef dim 258 259 260# random multinormal distribution 261\#define dim (15) 262int i; 263double mean[dim], covar[dim*dim]; 264UNUR_DISTR *covar_distr; 265UNUR_GEN *covar_gen; 266UNUR_GEN *mean_gen; 267covar_distr = unur_distr_correlation(dim); 268covar_gen = unur_init(unur_mcorr_new(covar_distr)); 269mean_gen = unur_str2gen("normal(5,1)"); 270for (i=0; i<dim; i++) 271 mean[i] = unur_sample_cont(mean_gen); 272do { 273 unur_sample_matr(covar_gen,covar); 274 distr[8] = unur_distr_multinormal(dim,mean,covar); 275} while (distr[8]==NULL); 276unur_distr_free(covar_distr); 277unur_free(covar_gen); 278unur_free(mean_gen); 279\#undef dim 280 281 282# random multinormal distribution 283\#define dim (20) 284int i; 285double mean[dim], covar[dim*dim]; 286UNUR_DISTR *covar_distr; 287UNUR_GEN *covar_gen; 288UNUR_GEN *mean_gen; 289covar_distr = unur_distr_correlation(dim); 290covar_gen = unur_init(unur_mcorr_new(covar_distr)); 291mean_gen = unur_str2gen("normal(5,1)"); 292for (i=0; i<dim; i++) 293 mean[i] = unur_sample_cont(mean_gen); 294do { 295 unur_sample_matr(covar_gen,covar); 296 distr[9] = unur_distr_multinormal(dim,mean,covar); 297} while (distr[9]==NULL); 298unur_distr_free(covar_distr); 299unur_free(covar_gen); 300unur_free(mean_gen); 301\#undef dim 302 303 304# random multinormal distribution 305\#define dim (100) 306int i; 307double mean[dim], covar[dim*dim]; 308UNUR_DISTR *covar_distr; 309UNUR_GEN *covar_gen; 310UNUR_GEN *mean_gen; 311covar_distr = unur_distr_correlation(dim); 312covar_gen = unur_init(unur_mcorr_new(covar_distr)); 313mean_gen = unur_str2gen("normal(5,1)"); 314for (i=0; i<dim; i++) 315 mean[i] = unur_sample_cont(mean_gen); 316do { 317 unur_sample_matr(covar_gen,covar); 318 distr[10] = unur_distr_multinormal(dim,mean,covar); 319} while (distr[10]==NULL); 320unur_distr_free(covar_distr); 321unur_free(covar_gen); 322unur_free(mean_gen); 323\#undef dim 324 325 326# multinormal distribution with correlation matrix of AR(1) process 327\#define dim (100) 328distr[11] = unur_distr_multinormal_ar1(dim,NULL,0.5); 329\#undef dim 330 331\#define dim (100) 332distr[12] = unur_distr_multinormal_ar1(dim,NULL,0.9); 333\#undef dim 334 335\#define dim (100) 336distr[13] = unur_distr_multinormal_ar1(dim,NULL,0.99); 337\#undef dim 338 339\#define dim (100) 340distr[14] = unur_distr_multinormal_ar1(dim,NULL,0.999); 341\#undef dim 342 343# standard "multinormal" distribution of dimension 1 344distr[15] = unur_distr_multinormal(1,NULL,NULL); 345 346# "multinormal" distribution of dimension 1 347\#define dim (1) 348int i; 349double mean[dim], covar[dim*dim]; 350UNUR_DISTR *covar_distr; 351UNUR_GEN *covar_gen; 352UNUR_GEN *mean_gen; 353covar_distr = unur_distr_correlation(dim); 354covar_gen = unur_init(unur_mcorr_new(covar_distr)); 355mean_gen = unur_str2gen("normal(5,1)"); 356for (i=0; i<dim; i++) 357 mean[i] = unur_sample_cont(mean_gen); 358do { 359 unur_sample_matr(covar_gen,covar); 360 distr[16] = unur_distr_multinormal(dim,mean,covar); 361} while (distr[16]==NULL); 362unur_distr_free(covar_distr); 363unur_free(covar_gen); 364unur_free(mean_gen); 365\#undef dim 366 367# standard multinormal distribution with rectangular domain 368double ll[3] = {0.,0.,0.}; 369double ru[3] = {UNUR_INFINITY,UNUR_INFINITY,UNUR_INFINITY}; 370distr[17] = unur_distr_multinormal(3,NULL,NULL); 371unur_distr_cvec_set_domain_rect(distr[17],ll,ru); 372 373# standard multicauchy distribution 374distr[18] = unur_distr_multicauchy(3,NULL,NULL); 375 376 377# number of distributions: 19 378 379 380[validate - test chi2:] 381 382# + ... pass test 383# 0 ... fail to initialize generator (given variant does not exist) 384# - ... fail test 385# / ... either init fails or test passes 386# . ... do not run test 387# # ... comment 388# 389# generators: 390# [0] ... default variant 391# [1] ... default variant but reinitialized with changed distribution 392# 393#gen 0 1 # distribution 394#--------------------------------------------- 395 <0> + + # standard multinormal (dim=3) 396 <1> + + # multinormal (dim=3) 397 <2> + . # random multinormal (dim=2) 398 <3> + + # random multinormal (dim=3) 399 <4> + . # random multinormal (dim=4) 400 <5> + . # random multinormal (dim=5) 401 <6> + . # random multinormal (dim=7) 402 <7> + . # random multinormal (dim=10) 403 <8> + . # random multinormal (dim=15) 404 <9> + . # random multinormal (dim=20) 405 <10> + . # random multinormal (dim=100) 406x<11> + . # multinormal with AR(1) corr matrix (rho=0.5, dim=100) 407 <12> + . # multinormal with AR(1) corr matrix (rho=0.9, dim=100) 408x<13> + . # multinormal with AR(1) corr matrix (rho=0.99, dim=100) 409x<14> + . # multinormal with AR(1) corr matrix (rho=0.999, dim=100) 410 <15> + . # standard multinormal (dim=1) 411x<16> + . # random multinormal (dim=1) 412 <17> 0 . # standard multinormal distribution with rectangular domain 413 <18> 0 . # invalid distribution (standard multicauchy, dim=3) 414 415 416############################################################################# 417############################################################################# 418 419[verbatim] 420 421############################################################################# 422