#############################################################################

[main]

[main - data:]

# method (for information only: the program scans the file name)
method: GIBBS

[main - header:]

/* prototypes */

int unur_gibbs_set_pedantic( UNUR_PAR *par, int pedantic );

\#define COMPARE_SAMPLE_SIZE   (9999)
\#define VIOLATE_SAMPLE_SIZE   (20)

/* For running chi2 tests we use a thinning of dimension * THINNING */
\#define THINNING (2)

/* GIBBS is a Markov Chain Monte Carlo method and thus it is likely to   */
/* fail the chi-square goodness-of-fit test with the used sample size.   */
/* Thus we accept one "hard" failer and more "soft" failures then usual. */
\#define CHI2_FAILURES_TOLERATED (1010)


/* we need marginal distributions for the chi2 tests */
\#define unur_distr_multicauchy   unur_distr_multicauchy_w_marginals
\#define unur_distr_multinormal   unur_distr_multinormal_w_marginals
\#define unur_distr_multistudent  unur_distr_multistudent_w_marginals


#############################################################################

[new]

[new - invalid NULL ptr: 
   distr = NULL; ]

~( distr );
        --> expected_NULL --> UNUR_ERR_NULL


[new - invalid distribution type:
   distr = unur_distr_discr_new(); ]

~( distr );
         --> expected_NULL --> UNUR_ERR_DISTR_INVALID


#############################################################################

[set]

[set - invalid NULL ptr: 
   double x0[] = {1., 2., 3.};
   par = NULL; ]

~_variant_coordinate( par );
	--> expected_setfailed --> UNUR_ERR_NULL

~_variant_random_direction( par );
	--> expected_setfailed --> UNUR_ERR_NULL

~_startingpoint( par, x0);
	--> expected_setfailed --> UNUR_ERR_NULL

~_thinning( par, 3 );
	--> expected_setfailed --> UNUR_ERR_NULL

~_burnin( par, 100 );
	--> expected_setfailed --> UNUR_ERR_NULL

[set - invalid parameter object:
   double x0[] = {1., 2., 3.};
   double fpar[2] = {0.,1.};
   distr = unur_distr_normal(fpar,2);
   par = unur_arou_new(distr); ]

~_variant_coordinate( par );
	--> expected_setfailed --> UNUR_ERR_PAR_INVALID

~_variant_random_direction( par );
	--> expected_setfailed --> UNUR_ERR_PAR_INVALID

~_startingpoint( par, x0);
	--> expected_setfailed --> UNUR_ERR_PAR_INVALID

~_thinning( par, 3 );
	--> expected_setfailed --> UNUR_ERR_PAR_INVALID

~_burnin( par, 100 );
	--> expected_setfailed --> UNUR_ERR_PAR_INVALID

unur_par_free(par);

[set - invalid parameters:
   distr = unur_distr_multinormal( 3, NULL, NULL );
   par = unur_gibbs_new(distr); ]

~_thinning( par, 0 );
	--> expected_setfailed --> UNUR_ERR_PAR_SET

~_burnin( par, -1 );
	--> expected_setfailed --> UNUR_ERR_PAR_SET

unur_par_free(par);


#############################################################################

[get]

[get - invalid generator object:
   distr = unur_distr_normal(NULL,0);
   par = unur_arou_new(distr);
   gen = unur_init(par); <-- ! NULL ]

~_state(gen);
        --> expected_NULL --> UNUR_ERR_GEN_INVALID


#############################################################################

[chg]

[chg - invalid generator object:
   double x[] = {0.,0.};
   distr = unur_distr_normal(NULL,0);
   par = unur_ssr_new(distr);
   gen = unur_init( par ); <-- ! NULL ]

~_state(gen,x);
        --> expected_setfailed --> UNUR_ERR_GEN_INVALID

[chg - invalid NULL:
   distr = unur_distr_multinormal(2,NULL,NULL);
   par = unur_gibbs_new(distr);
   gen = unur_init( par ); <-- ! NULL ]

~_state(gen,NULL);
        --> expected_setfailed --> UNUR_ERR_NULL


#############################################################################

# [init]

#############################################################################

[reinit]

[reinit - does not exist:
   double x[3];
   distr = unur_distr_multinormal(3,NULL,NULL);
   par = unur_gibbs_new(distr);
   gen = unur_init( par ); <-- ! NULL ]

unur_reinit( gen );
	--> expected_setfailed --> UNUR_ERR_NO_REINIT

unur_sample_vec( gen, x );
x[0];
	--> expected_INFINITY --> UNUR_ERR_GEN_CONDITION


#############################################################################

[sample]

[sample - test clone:
   const int dim = 3;
   double mean[] = {1.,2.,3.};
   double covar[] = { 2., 2., 1.,   2., 4., 3.,   1., 3., 3. };
   UNUR_GEN *clone;
   distr = unur_distr_multinormal( dim, mean, covar );
   par = unur_gibbs_new(distr);
   /* unur_gibbs_set_variant_random_direction(par); */
   unur_set_debug(par,1u);
   gen = unur_init( par ); <-- ! NULL ]

/* clone */
/* currently we cannot compare clone with original generator. */
/* thus we just run it to test whether cloning works without a segfault. */
clone = unur_gen_clone(gen);
unur_free(gen);
gen = clone;
unur_gibbs_reset_state(gen);
	-->compare_sequence_gen_start


#############################################################################

[validate]

[validate - generators:]

# T=log, coordinate sampling, thinning = THINNIG*dim
par[0] = unur_gibbs_new(@distr@);
unur_gibbs_set_thinning(par,THINNING*unur_distr_get_dim(@distr@));
unur_gibbs_set_burnin(par,1000);

# T=log, random direction sampling, thinning = THINNIG*dim
par[1] = unur_gibbs_new(@distr@);
unur_gibbs_set_variant_random_direction(par);
unur_gibbs_set_thinning(par,THINNING*unur_distr_get_dim(@distr@));
unur_gibbs_set_burnin(par,1000);


# T=sqrt, coordinate sampling, thinning = THINNIG*dim
par[2] = unur_gibbs_new(@distr@);
unur_gibbs_set_thinning(par,THINNING*unur_distr_get_dim(@distr@));
unur_gibbs_set_c(par,-0.5);
##unur_set_debug(par,~0u);

# T=sqrt, random direction sampling, thinning = THINNIG*dim
par[3] = unur_gibbs_new(@distr@);
unur_gibbs_set_variant_random_direction(par);
unur_gibbs_set_thinning(par,THINNING*unur_distr_get_dim(@distr@));
unur_gibbs_set_c(par,-0.5);


[validate - distributions:]

# standard multinormal distribution
distr[0] = unur_distr_multinormal(1,NULL,NULL);

distr[1] = unur_distr_multinormal(2,NULL,NULL);

distr[2] = unur_distr_multinormal(3,NULL,NULL);

# standard multinormal distribution, shifted center
double mean[]  = { 1., 2., 3. };
distr[34] = unur_distr_multinormal(3,mean,NULL);


# multinormal distribution, dim = 1, shifted center 
double mean[]  = { -1. };
double covar[] = { 2. };
distr[3] = unur_distr_multinormal(1,mean,covar);
unur_distr_cvec_set_center(distr[3],NULL);

# multinormal distribution, dim = 3, shifted center 
double mean[]  = { 1., 2., 3. };
double covar[] = { 2., 2., 1.,   2., 4., 3.,   1., 3., 3. };
distr[4] = unur_distr_multinormal(3,mean,covar);


# multinormal with AR(1) 
distr[5] = unur_distr_multinormal_ar1(3,NULL,0.9);

distr[6] = unur_distr_multinormal_ar1(4,NULL,0.8);

distr[7] = unur_distr_multinormal_ar1(5,NULL,0.7);

distr[8] = unur_distr_multinormal_ar1(10,NULL,0.6);


# multinormal with AR(1) (rho=0.9, dim=3), shifted center
double mean[]  = { -1., -2., -3., 4., 5., 6., 7., 8., 9., 10. };
distr[9] = unur_distr_multinormal_ar1(3,mean,0.9);

double mean[]  = { -1., -2., -3., 4., 5., 6., 7., 8., 9., 10. };
distr[10] = unur_distr_multinormal_ar1(4,mean,0.8);

double mean[]  = { -1., -2., -3., 4., 5., 6., 7., 8., 9., 10. };
distr[11] = unur_distr_multinormal_ar1(5,mean,0.7);

double mean[]  = { -1., -2., -3., 4., 5., 6., 7., 8., 9., 10. };
distr[12] = unur_distr_multinormal_ar1(10,mean,0.6);


# multinormal with constant rho
distr[13] = unur_distr_multinormal_constantrho(3,NULL,0.9);

distr[14] = unur_distr_multinormal_constantrho(4,NULL,0.8);

distr[15] = unur_distr_multinormal_constantrho(5,NULL,0.7);

distr[16] = unur_distr_multinormal_constantrho(10,NULL,0.6);


# standard multicauchy distribution
distr[17] = unur_distr_multicauchy(2,NULL,NULL);

distr[18] = unur_distr_multicauchy(3,NULL,NULL);


# multicauchy distribution, dim = 3 
double mean[]  = { 1., 2., 3. };
double covar[] = { 1., 0.5, 0.25,  0.5, 1., 0.5,   0.25, 0.5, 1. };
distr[19] = unur_distr_multicauchy(3,mean,covar);

# multicauchy with AR(1) covariance matrix 
distr[20] = unur_distr_multicauchy_ar1(3,NULL,0.7);

distr[21] = unur_distr_multicauchy_ar1(4,NULL,0.6);

distr[22] = unur_distr_multicauchy_ar1(5,NULL,0.5);

distr[23] = unur_distr_multicauchy_ar1(10,NULL,0.4);


# multistudent with AR(1) covariance matrix 
distr[24] = unur_distr_multistudent_ar1(2,3.,NULL,0.7);

distr[25] = unur_distr_multistudent_ar1(2,5.,NULL,0.7);

distr[26] = unur_distr_multistudent_ar1(2,15.,NULL,0.7);

distr[27] = unur_distr_multistudent_ar1(2,0.5,NULL,0.7);

distr[28] = unur_distr_multistudent_ar1(2,1.5,NULL,0.7);

distr[29] = unur_distr_multistudent_ar1(2,2.5,NULL,0.7);

# standard multinormal distribution with rectangular domain
double ll[3] = {0.,0.,0.};
double ru[3] = {UNUR_INFINITY,UNUR_INFINITY,UNUR_INFINITY};
distr[30] = unur_distr_multinormal(3,NULL,NULL);
unur_distr_cvec_set_domain_rect(distr[30],ll,ru);

# standard multinormal distribution with rectangular domain
double ll[3] = {0.,0.,0.};
double ru[3] = {1.,UNUR_INFINITY,UNUR_INFINITY};
distr[31] = unur_distr_multinormal(3,NULL,NULL);
unur_distr_cvec_set_domain_rect(distr[31],ll,ru);

# standard multinormal distribution with rectangular domain
double ll[3] = {-1.,-1.,1.};
double ru[3] = {1.,0.,2.};
double center[3] = {0.,-0.5,1.5};
distr[32] = unur_distr_multinormal(3,NULL,NULL);
unur_distr_cvec_set_domain_rect(distr[32],ll,ru);
unur_distr_cvec_set_center(distr[32],center);

# invalid: default center of distribution out of truncated domain
double ll[3] = {-1.,-1.,1.};
double ru[3] = {1.,0.,2.};
distr[33] = unur_distr_multinormal(3,NULL,NULL);
unur_distr_cvec_set_domain_rect(distr[33],ll,ru);


# number of distributions: 35


[validate - test chi2:]

#  + ... pass test
#  0 ... fail to initialize generator
#  - ... fail test
#  . ... do not run test
#  # ... comment
#
# generators:
#  [0] ... T=log, coordinate sampling, thinning = THINNIG*dim
#  [1] ... T=log, random direction sampling, thinning = THINNIG*dim
#  [2] ... T=sqrt, coordinate sampling, thinning = THINNIG*dim
#  [3] ... T=sqrt, random direction sampling, thinning = THINNIG*dim
#
#gen    0  1  2  3	# distribution
#---------------------------------------------
  <0>	+  +  +  +	# standard multinormal (dim=1)
  <1>	+  +  +  +	# standard multinormal (dim=2)
  <2>	+  + x+ x+	# standard multinormal (dim=3)
 <34>	+  + x+ x+	# standard multinormal distribution (dim=3), shifted center
x <3>	+  +  +  +	# multinormal (dim=1), shifted center
x <4>	+  +  +  +	# multinormal (dim=3), shifted center
x <5>	+  +  +  +	# multinormal with AR(1) (rho=0.9, dim=3) 
x <6>	+  +  .  .	# multinormal with AR(1) (rho=0.8, dim=4) 
x <7>	+  +  .  .	# multinormal with AR(1) (rho=0.7, dim=5) 
x <8>	+  +  .  .	# multinormal with AR(1) (rho=0.6, dim=10) 
x <9>	+  +  .  .	# multinormal with AR(1) (rho=0.9, dim=3), shifted center
x<10>	+  +  .  .	# multinormal with AR(1) (rho=0.8, dim=4), shifted center
x<11>	+  +  .  .	# multinormal with AR(1) (rho=0.7, dim=5), shifted center
x<12>	+  +  +  +	# multinormal with AR(1) (rho=0.6, dim=10), shifted center
x<13>	+  +  .  .	# multinormal with constant rho (rho=0.9, dim=3) 
x<14>	+  +  .  .	# multinormal with constant rho (rho=0.8, dim=4) 
x<15>	+  +  +  +	# multinormal with constant rho (rho=0.7, dim=5) 
x<16>	+  +  .  .	# multinormal with constant rho (rho=0.6, dim=10) 

 <17>	0  0  +  +	# standard multicauchy (dim=2)
 <18>	0  0  +  +	# standard multicauchy (dim=3)
 <19>	0  0  +  +	# multicauchy (dim=3), shifted center
x<20>	0  0  +  +	# multicauchy with AR(1) covariance matrix (rho=0.7, dim=3)
x<21>	0  0  +  +	# multicauchy with AR(1) covariance matrix (rho=0.6, dim=4)
x<22>	0  0  +  +	# multicauchy with AR(1) covariance matrix (rho=0.5, dim=5)
x<23>	0  0  +  +	# multicauchy with AR(1) covariance matrix (rho=0.4, dim=10)

 <24>	0  0  +  +	# multistudent with AR(1) covariance matrix (rho=0.7, dim=2, nu = 3)
x<25>	0  0  +  +	# multistudent with AR(1) covariance matrix (rho=0.7, dim=2, nu = 5)
x<26>	0  0  +  +	# multistudent with AR(1) covariance matrix (rho=0.7, dim=2, nu = 15)
x<27>	0  0  +  +	# multistudent with AR(1) covariance matrix (rho=0.7, dim=2, nu = 0.5)
x<28>	0  0  +  +	# multistudent with AR(1) covariance matrix (rho=0.7, dim=2, nu = 1.5)
x<29>	0  0  +  +	# multistudent with AR(1) covariance matrix (rho=0.7, dim=2, nu = 2.5)

 <30>	+  .  +  .	# standard multinormal distribution with rectangular domain
 <31>	+  .  +  .	# standard multinormal distribution with rectangular domain
x<32>	+  .  +  .	# standard multinormal distribution with rectangular domain
x<33>	0  0  0  0	# invalid: default center of distribution out of truncated domain


#############################################################################
#############################################################################

[verbatim]

/* dummy function */
int unur_gibbs_set_pedantic( UNUR_PAR *par ATTRIBUTE__UNUSED, int pedantic ATTRIBUTE__UNUSED)
{ return 1; }

#############################################################################

