1# $Id: t_dgt.conf 5330 2011-04-19 10:50:18Z leydold $ 2############################################################################# 3 4[main] 5 6[main - data:] 7 8# method (for information only: the program scans the file name) 9method: DGT 10 11[main - header:] 12 13/* prototypes */ 14 15\#define COMPARE_SAMPLE_SIZE (15000) 16\#define VIOLATE_SAMPLE_SIZE (20) 17 18double *make_geometric_vector(double q, int len); 19double *make_random_vector(int len); 20UNUR_DISTR *get_distr_with_invalid_pv( void ); 21UNUR_DISTR *get_distr_with_pv( void ); 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 - data missing in distribution object: 40 distr = unur_distr_discr_new(); /* no probability vector */ ] 41 42~( distr ); 43 --> expected_NULL --> UNUR_ERR_DISTR_REQUIRED 44 45############################################################################# 46 47[set] 48 49[set - invalid NULL ptr: 50 par = NULL; ] 51 52~_variant(par,1); 53 --> expected_setfailed --> UNUR_ERR_NULL 54 55~_guidefactor(par,-1.); 56 --> expected_setfailed --> UNUR_ERR_NULL 57 58[set - invalid parameter object: 59 distr = get_distr_with_pv(); 60 par = unur_dau_new(distr); ] 61 62~_variant(par,10); 63 --> expected_setfailed --> UNUR_ERR_PAR_INVALID 64 65~_guidefactor(par,-1.); 66 --> expected_setfailed --> UNUR_ERR_PAR_INVALID 67 68unur_par_free(par); 69 70[set - invalid parameters: 71 distr = get_distr_with_pv(); 72 par = unur_dgt_new(distr); ] 73 74~_variant(par,10); 75 --> expected_setfailed --> UNUR_ERR_PAR_VARIANT 76 77~_guidefactor(par,-1.); 78 --> expected_setfailed --> UNUR_ERR_PAR_SET 79 80unur_par_free(par); 81 82############################################################################# 83 84# [get] 85 86############################################################################# 87 88# [chg] 89 90############################################################################# 91 92[init] 93 94[init - invalid NULL ptr: 95 par = NULL; ] 96 97unur_init( par ); 98 --> expected_NULL --> UNUR_ERR_NULL 99 100 101[init - invalid data: 102 distr = get_distr_with_invalid_pv(); 103 par = unur_dgt_new(distr); ] 104 105unur_init( par ); 106 --> expected_NULL --> UNUR_ERR_GEN_DATA 107 108############################################################################# 109 110[reinit] 111 112[reinit - exist: 113 double fpar[2] = {10.,0.63}; 114 distr = unur_distr_binomial(fpar,2); 115 par = unur_dgt_new(distr); 116 gen = unur_init( par ); <-- ! NULL ] 117 118unur_reinit( gen ); 119 --> expected_reinit 120 121############################################################################# 122 123[sample] 124 125[sample - invalid NULL ptr: 126 gen = NULL; ] 127 128unur_dgt_eval_invcdf_recycle(gen,0.5,NULL); 129 --> expected_INTMAX --> UNUR_ERR_NULL 130 131unur_dgt_eval_invcdf(gen,0.5); 132 --> expected_INTMAX --> UNUR_ERR_NULL 133 134#..................................................................... 135 136[sample - invalid generator object: 137 distr = unur_distr_normal(NULL,0); 138 par = unur_srou_new(distr); 139 gen = unur_init(par); <-- ! NULL ] 140 141unur_dgt_eval_invcdf_recycle(gen,0.5,NULL); 142 --> expected_INTMAX --> UNUR_ERR_GEN_INVALID 143 144unur_dgt_eval_invcdf(gen,0.5); 145 --> expected_INTMAX --> UNUR_ERR_GEN_INVALID 146 147[sample - invalid domain: 148 double fpar[] = {10,0.3}; 149 distr = unur_distr_binomial(fpar,2); 150 par = unur_dgt_new(distr); 151 unur_set_debug(par,0); 152 gen = unur_init( par ); <-- ! NULL ] 153 154unur_dgt_eval_invcdf_recycle(gen,1.5,NULL); 155 --> none --> UNUR_ERR_DOMAIN 156 157unur_dgt_eval_invcdf_recycle(gen,-0.5,NULL); 158 --> expected_zero --> UNUR_ERR_DOMAIN 159 160unur_dgt_eval_invcdf(gen,1.5); 161 --> none --> UNUR_ERR_DOMAIN 162 163unur_dgt_eval_invcdf(gen,-0.5); 164 --> expected_zero --> UNUR_ERR_DOMAIN 165 166#..................................................................... 167 168[sample - compare: 169 distr = get_distr_with_pv(); 170 par = NULL; ] 171 172/* default algorithm */ 173par = unur_dgt_new(distr); 174 -->compare_sequence_par_start 175 176/* variant 1 */ 177par = unur_dgt_new(distr); 178unur_dgt_set_variant(par,1); 179 -->compare_sequence_par 180 181/* variant 2 */ 182par = unur_dgt_new(distr); 183unur_dgt_set_variant(par,2); 184 -->compare_sequence_par 185 186/* larger guide table size */ 187par = unur_dgt_new(distr); 188unur_dgt_set_guidefactor(par,10.); 189 -->compare_sequence_par 190 191/* smaller guide table size */ 192par = unur_dgt_new(distr); 193unur_dgt_set_guidefactor(par,0.1); 194 -->compare_sequence_par 195 196/* sequential search */ 197par = unur_dgt_new(distr); 198unur_dgt_set_guidefactor(par,0.); 199 -->compare_sequence_par 200 201#..................................................................... 202 203[sample - compare clone: 204 UNUR_GEN *clone; 205 double fpar[] = {10,0.3}; 206 distr = unur_distr_binomial(fpar,2); 207 par = NULL; 208 gen = NULL; ] 209 210/* original generator object */ 211par = unur_dgt_new(distr); 212gen = unur_init(par); 213 -->compare_sequence_gen_start 214 215/* clone */ 216clone = unur_gen_clone(gen); 217unur_free(gen); 218gen = clone; 219 -->compare_sequence_gen 220 221#..................................................................... 222 223[sample - compare reinit: 224 double fpar[] = {10,0.3}; 225 distr = unur_distr_binomial(fpar,2); 226 par = NULL; 227 gen = NULL; ] 228 229/* original generator object */ 230par = unur_dgt_new(distr); 231gen = unur_init(par); 232 -->compare_sequence_gen_start 233 234/* reinit */ 235unur_reinit(gen); 236 -->compare_sequence_gen 237 238#..................................................................... 239 240[sample - compare stringparser: 241 double pv[] = {.1, .2, .3, .4, .5, .6, .7, .8, .9, 1.}; 242 double fpar[] = {0.8}; 243 distr = NULL; 244 par = NULL; 245 gen = NULL; ] 246 247distr = unur_distr_discr_new(); 248unur_distr_discr_set_pv(distr,pv,10); 249par = unur_dgt_new(distr); 250unur_dgt_set_guidefactor(par,3.); 251gen = unur_init(par); 252 -->compare_sequence_gen_start 253 254unur_free(gen); gen = NULL; 255unur_distr_free(distr); distr = NULL; 256gen = unur_str2gen( "discr; pv = (.1, .2, .3, .4, .5, .6, .7, .8, .9, 1.) & \ 257 method = dgt; guidefactor = 3." ); 258 -->compare_sequence_gen 259 260 261unur_free(gen); gen = NULL; 262distr = unur_distr_discr_new(); 263unur_distr_discr_set_pv(distr,pv,10); 264par = unur_dgt_new(distr); 265unur_dgt_set_variant(par,1); 266unur_dgt_set_guidefactor(par,3.); 267gen = unur_init(par); 268 -->compare_sequence_gen_start 269 270unur_free(gen); gen = NULL; 271unur_distr_free(distr); distr = NULL; 272gen = unur_str2gen( "discr; pv = (.1, .2, .3, .4, .5, .6, .7, .8, .9, 1.) & \ 273 method = dgt; guidefactor = 3.; variant = 1" ); 274 -->compare_sequence_gen 275 276 277unur_free(gen); gen = NULL; 278unur_free(gen); gen = NULL; 279distr = unur_distr_discr_new(); 280unur_distr_discr_set_pv(distr,pv,10); 281par = unur_dgt_new(distr); 282unur_dgt_set_variant(par,2); 283unur_dgt_set_guidefactor(par,3.); 284gen = unur_init(par); 285 -->compare_sequence_gen_start 286 287unur_free(gen); gen = NULL; 288unur_distr_free(distr); distr = NULL; 289gen = unur_str2gen( "discr; pv = (.1, .2, .3, .4, .5, .6, .7, .8, .9, 1.) & \ 290 method = dgt; guidefactor = 3.; variant = 2" ); 291 -->compare_sequence_gen 292 293 294unur_free(gen); gen = NULL; 295distr = unur_distr_geometric(fpar,1); 296par = unur_dgt_new(distr); 297unur_dgt_set_guidefactor(par,3.); 298gen = unur_init(par); 299 -->compare_sequence_gen_start 300 301unur_free(gen); gen = NULL; 302unur_distr_free(distr); distr = NULL; 303gen = unur_str2gen( "geometric(0.8) & method = dgt; guidefactor = 3." ); 304 -->compare_sequence_gen 305 306 307############################################################################# 308 309[validate] 310 311[validate - generators:] 312 313# default program 314par[0] = unur_dgt_new(@distr@); 315unur_set_debug(par, 1u); 316 317# variant 1 318par[1] = unur_dgt_new(@distr@); 319unur_dgt_set_variant(par,1); 320unur_set_debug(par, 1u); 321 322# variant 2 323par[2] = unur_dgt_new(@distr@); 324unur_dgt_set_variant(par,2); 325unur_set_debug(par, 1u); 326 327# larger guide table size 328par[3] = unur_dgt_new(@distr@); 329unur_dgt_set_guidefactor(par,10.); 330unur_set_debug(par, 1u); 331 332# smaller guide table size 333par[4] = unur_dgt_new(@distr@); 334unur_dgt_set_guidefactor(par,0.1); 335unur_set_debug(par, 1u); 336 337 338# default variant but reinitialized with changed domain 339{ UNUR_DISTR *dg =NULL; 340par[5] = unur_dgt_new(@distr@); 341dg = unur_get_distr(gen); 342unur_distr_discr_set_domain(dg,2,7); 343unur_distr_discr_upd_pmfsum(dg); 344unur_reinit(gen); } 345 346# default variant but reinitialized with changed pdf parameters 347{ UNUR_DISTR *dg =NULL; 348par[6] = unur_dgt_new(@distr@); 349fpm[0] = 10.; 350fpm[1] = 0.63; 351dg = unur_get_distr(gen); 352unur_distr_discr_set_pmfparams(dg,fpm,2); 353unur_distr_discr_upd_pmfsum(dg); 354unur_reinit(gen); } 355 356 357[validate - distributions:] 358 359# probability vector with random entries 360distr[0] = unur_distr_discr_new(); 361darray = make_random_vector(10); 362unur_distr_discr_set_pv(distr[0],darray,10); 363free(darray); 364unur_distr_set_name(distr[0],"pv(random)"); 365 366distr[1] = unur_distr_discr_new(); 367darray = make_random_vector(100); 368unur_distr_discr_set_pv(distr[1],darray,100); 369free(darray); 370unur_distr_set_name(distr[1],"pv(random)"); 371 372distr[2] = unur_distr_discr_new(); 373darray = make_random_vector(1000); 374unur_distr_discr_set_pv(distr[2],darray,1000); 375free(darray); 376unur_distr_set_name(distr[2],"pv(random)"); 377 378distr[3] = unur_distr_discr_new(); 379darray = make_random_vector(10000); 380unur_distr_discr_set_pv(distr[3],darray,10000); 381free(darray); 382unur_distr_set_name(distr[3],"pv(random)"); 383 384# probability vector with geometrically distributed entries 385distr[4] = unur_distr_discr_new(); 386darray = make_geometric_vector(1.,1000); 387unur_distr_discr_set_pv(distr[4],darray,1000); 388free(darray); 389unur_distr_set_name(distr[4],"pv(geometric)"); 390 391distr[5] = unur_distr_discr_new(); 392darray = make_geometric_vector(0.99,1000); 393unur_distr_discr_set_pv(distr[5],darray,1000); 394free(darray); 395unur_distr_set_name(distr[5],"pv(geometric)"); 396 397distr[6] = unur_distr_discr_new(); 398darray = make_geometric_vector(0.9,1000); 399unur_distr_discr_set_pv(distr[6],darray,1000); 400free(darray); 401unur_distr_set_name(distr[6],"pv(geometric)"); 402 403distr[7] = unur_distr_discr_new(); 404darray = make_geometric_vector(0.5,1000); 405unur_distr_discr_set_pv(distr[7],darray,1000); 406free(darray); 407unur_distr_set_name(distr[7],"pv(geometric)"); 408 409distr[8] = unur_distr_discr_new(); 410darray = make_geometric_vector(0.1,1000); 411unur_distr_discr_set_pv(distr[8],darray,1000); 412free(darray); 413unur_distr_set_name(distr[8],"pv(geometric)"); 414 415# probability vector with geometrically distributed entries and shifted domain 416distr[9] = unur_distr_discr_new(); 417darray = make_geometric_vector(0.5,100); 418unur_distr_discr_set_pv(distr[9],darray,100); 419unur_distr_discr_set_domain(distr[9],10,209); 420free(darray); 421unur_distr_set_name(distr[9],"pv(geometric) - shifted domain"); 422 423distr[10] = unur_distr_discr_new(); 424darray = make_geometric_vector(0.9,100); 425unur_distr_discr_set_pv(distr[10],darray,100); 426unur_distr_discr_set_domain(distr[10],-10,209); 427free(darray); 428unur_distr_set_name(distr[10],"pv(geometric) - shifted domain"); 429 430# PMF instead of PV 431 432# geometric disctribution 433fpm[0] = 0.5; 434distr[11] = unur_distr_geometric(fpm,1); 435 436fpm[0] = 0.001; 437distr[12] = unur_distr_geometric(fpm,1); 438 439# logarithmic distribution 440fpm[0] = 0.1; 441distr[13] = unur_distr_logarithmic(fpm,1); 442 443fpm[0] = 0.999; 444distr[14] = unur_distr_logarithmic(fpm,1); 445 446# negative binomial distribution 447fpm[0] = 0.5; 448fpm[1] = 10.; 449distr[15] = unur_distr_negativebinomial(fpm,2); 450 451fpm[0] = 0.8; 452fpm[1] = 10.; 453distr[21] = unur_distr_negativebinomial(fpm,2); 454 455fpm[0] = 0.01; 456fpm[1] = 20.; 457distr[16] = unur_distr_negativebinomial(fpm,2); 458 459# poisson distribution 460fpm[0] = 0.1; 461distr[17] = unur_distr_poisson(fpm,1); 462 463fpm[0] = 0.999; 464distr[18] = unur_distr_poisson(fpm,1); 465 466# zipf distribution 467fpm[0] = 2.; 468fpm[1] = 1.; 469distr[19] = unur_distr_zipf(fpm,2); 470unur_distr_discr_set_domain(distr[19],1,1000); 471 472fpm[0] = 0.001; 473fpm[1] = 1.; 474distr[20] = unur_distr_zipf(fpm,2); 475unur_distr_discr_set_domain(distr[20],1,1000); 476 477# binomial distribution 478fpm[0] = 20.; 479fpm[1] = 0.8; 480distr[22] = unur_distr_binomial(fpm,2); 481 482fpm[0] = 2000.; 483fpm[1] = 0.0013; 484distr[23] = unur_distr_binomial(fpm,2); 485 486 487# number of distributions: 24 488 489 490[validate - test chi2:] 491 492# + ... pass test 493# 0 ... fail to initialize generator 494# - ... fail test 495# . ... do not run test 496# # ... comment 497# 498# [0] ... default program 499# [1] ... variant 1 500# [2] ... variant 2 501# [3] ... larger guide table size 502# [4] ... smaller guide table size 503# [5] ... default variant but reinitialized with changed domain 504# [6] ... default variant but reinitialized with changed pdf parameters 505# 506#gen 0 1 2 3 4 5 6 # distribution 507#------------------------------------------------------------- 508 <0> + + + + + . . # PV with random entries 509 <1> + + + + + . . 510 <2> + + + + + . . 511x <3> + + + + + . . 512 513x <4> + + + + + . . # PV with geometrically distributed entries 514 <5> + + + + + . . 515x <6> + + + + + . . 516 <7> + + + + + . . 517x <8> + + + + + . . 518 519 <9> + + + + + . . # PV with geom. distr. entries and shifted domain 520 <10> + + + + + . . 521 522# PMF instead of PV 523 524 <11> + + + + + + . # geometric (0.5) 525 <12> + + + + + + . # geometric (0.001) 526 <13> + + + + + + . # logarithmic (0.1) 527 <14> + + + + + + . # logarithmic (0.999) 528 <15> + + + + + + . # negativebinomial (0.5, 10) 529x<21> + + + + + + . # negativebinomial (0.8, 10) 530 <16> + + + + + + . # negativebinomial (0.01, 20) 531x<17> + + + + + + . # poisson (0.1) 532 <18> + + + + + + . # poisson (0.999) 533 <19> + + + + + + . # zipf (2, 1) 534x<20> + + + + + + . # zipf (0.001, 1) 535 <22> + + + + + + + # binomial (20, 0.8) 536 <23> + + + + + + + # binomial (2000, 0.0013) 537 538############################################################################# 539############################################################################# 540 541[verbatim] 542 543/*---------------------------------------------------------------------------*/ 544 545/* make a probability vector (need not sum to one) 546 (use random entries) */ 547double *make_random_vector(int len) 548{ 549 double *pv; 550 int i; 551 552 /* allocate memory */ 553 pv = malloc(len*sizeof(double)); 554 if (!pv) abort(); 555 556 /* main part of geometric distribution */ 557 for( i=0; i<len; i++ ) 558 pv[i] = unur_urng_fish(NULL); 559 560 return pv; 561 562} /* end of make_random_vector() */ 563 564/*---------------------------------------------------------------------------*/ 565 566/* make a probability vector (need not sum to one) 567 (use geometric distribution) */ 568double *make_geometric_vector(double q, int len) 569{ 570 double *pv; 571 int i; 572 573 /* allocate memory */ 574 pv = malloc(len * sizeof(double)); 575 if (!pv) abort(); 576 577 /* main part of geometric distribution */ 578 pv[0] = 1.; 579 for( i=1; i<len; i++ ) 580 pv[i] = pv[i-1] * q; 581 582 return pv; 583 584} /* end of make_geometric_vector() */ 585 586/*---------------------------------------------------------------------------*/ 587 588UNUR_DISTR *get_distr_with_pv( void ) 589{ 590\#define PV_SIZE 200 591 double pv[PV_SIZE]; 592 UNUR_DISTR *distr; 593 int i; 594 595 for (i=0; i<PV_SIZE; i++) 596 pv[i] = unur_urng_fish(NULL); 597 598 distr = unur_distr_discr_new(); 599 unur_distr_discr_set_pv(distr,pv,PV_SIZE); 600 601 return distr; 602 603\#undef PV_SIZE 604} /* end of get_distr_with_pv() */ 605 606/*---------------------------------------------------------------------------*/ 607 608UNUR_DISTR *get_distr_with_invalid_pv( void ) 609{ 610\#define PV_SIZE 10 611 double pv[PV_SIZE]; 612 UNUR_DISTR *distr; 613 int i; 614 615 pv[0] = -1.; /* invalid ! */ 616 617 for (i=1; i<PV_SIZE; i++) 618 pv[i] = unur_urng_fish(NULL); 619 620 distr = unur_distr_discr_new(); 621 unur_distr_discr_set_pv(distr,pv,PV_SIZE); 622 623 return distr; 624 625\#undef PV_SIZE 626} /* end of get_distr_with_invalid_pv() */ 627 628/*---------------------------------------------------------------------------*/ 629 630############################################################################# 631