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

[main]

[main - data:]

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

[main - header:]

/* prototypes */

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

## work-around for missing functions
int unur_distr_condi_set_pedantic(UNUR_PAR *par, int pedantic);
int unur_distr_condi_chg_verify(UNUR_GEN *gen, int verify);


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

[new]

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

unur_distr_condi_new( distr, NULL, NULL, 0 );
	--> expected_NULL --> UNUR_ERR_NULL


[new - invalid NULL ptr: 
   distr = unur_distr_multinormal(3,NULL,NULL); ]

unur_distr_condi_new( distr, NULL, NULL, 0 );
	 --> expected_NULL --> UNUR_ERR_NULL


[new - invalid distribution type:
   double p[] = { 1., 2., 3., 4.}; 
   distr = unur_distr_discr_new(); ]

unur_distr_condi_new( distr, p, NULL, 4 );
	 --> expected_NULL --> UNUR_ERR_DISTR_INVALID


[new - invalid data:
   double p[] = { 1., 2., 3., 4.};
   distr = unur_distr_multinormal(3,NULL,NULL); ]

unur_distr_condi_new( distr, p, NULL, -1 );
	--> expected_NULL --> UNUR_ERR_DISTR_INVALID

unur_distr_condi_new( distr, p, NULL, 3 );
	--> expected_NULL --> UNUR_ERR_DISTR_INVALID


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

[set]

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

unur_distr_condi_set_condition( distr, NULL, NULL, 0 );
	--> expected_setfailed --> UNUR_ERR_NULL


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

unur_distr_condi_set_condition( distr, NULL, NULL, 0 );
	--> expected_setfailed --> UNUR_ERR_DISTR_INVALID


[set - invalid data:
   double p[] = { 1., 2., 3., 4.};
   UNUR_DISTR *condi;
   distr = unur_distr_multinormal(3,NULL,NULL); 
   condi = unur_distr_condi_new( distr, p, NULL, 0 ); ]

unur_distr_condi_set_condition( condi, p, NULL, -1 );
	--> expected_setfailed --> UNUR_ERR_DISTR_INVALID

unur_distr_condi_set_condition( condi, p, NULL, 3 );
	--> expected_setfailed --> UNUR_ERR_DISTR_INVALID

unur_distr_free(condi);


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

[get]

[get - invalid NULL ptr: 
   const double *pos, *dir;
   int k;
   distr = NULL; ]

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

unur_distr_condi_get_condition( distr, &pos, &dir, &k );
	--> expected_setfailed --> UNUR_ERR_NULL


[get - invalid distribution type:
   const double *pos, *dir;
   int k;
   distr = unur_distr_cont_new(); ]

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

unur_distr_condi_get_condition( distr, &pos, &dir, &k );
	--> expected_setfailed --> UNUR_ERR_DISTR_INVALID


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

# [chg]

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

# [init]

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

# [reinit]

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

[sample]

[sample - check for memory leaks:
   double p[] = { 1., 2., 3., 4.};
   double dir[] = { 1., -1., 2., -2.};
   UNUR_DISTR *condi;
   distr = unur_distr_multinormal(3,NULL,NULL); 
   condi = unur_distr_condi_new( distr, p, NULL, 0 ); ]

unur_distr_condi_set_condition( condi, p, NULL, 1 );
	--> none --> UNUR_SUCCESS

unur_distr_condi_set_condition( condi, p, dir, 1 );
	--> none --> UNUR_SUCCESS

unur_distr_free(condi);


[sample - check for memory leaks:
   double p[] = { 1., 2., 3., 4.};
   double dir[] = { 1., -1., 2., -2.};
   UNUR_DISTR *condi;
   distr = unur_distr_multinormal(4,NULL,NULL); 
   condi = unur_distr_condi_new( distr, p, dir, 0 ); ]

unur_distr_condi_set_condition( condi, p, dir, 1 );
	--> none --> UNUR_SUCCESS

unur_distr_condi_set_condition( condi, p, NULL, 1 );
	--> none --> UNUR_SUCCESS

unur_distr_condi_set_condition( condi, p, dir, 3 );
	--> none --> UNUR_SUCCESS

unur_distr_free(condi);


[sample - check for memory leaks:
   double p[] = { 1., 2., 3., 4.};
   double dir[] = { 1., -1., 2., -2.};
   UNUR_DISTR *condi;
   distr = unur_distr_multinormal(4,NULL,NULL); 
   condi = unur_distr_condi_new( distr, p, NULL, 0 ); ]

unur_distr_condi_set_condition( condi, p, NULL, 1 );
	--> none --> UNUR_SUCCESS

unur_distr_condi_set_condition( condi, p, dir, 1 );
	--> none --> UNUR_SUCCESS

unur_distr_condi_set_condition( condi, p, NULL, 3 );
	--> none --> UNUR_SUCCESS

unur_distr_free(condi);


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

[validate]

[validate - generators:]

# AROU (default)
par[0] = unur_arou_new(@distr@);

# TDR (default)
par[1] = unur_tdr_new(@distr@);

# TDR (T=log)
par[2] = unur_tdr_new(@distr@);
unur_tdr_set_c(par,0.);

# ARS
par[3] = unur_ars_new(@distr@);

# TABL (default)
par[4] = unur_tabl_new(@distr@);


[validate - distributions:]

# conditional: standard multinormal distribution
\#define dim (3)
UNUR_DISTR *normal = unur_distr_multinormal(dim,NULL,NULL);
int i;
double p[dim]; 
for(i=0;i<dim;i++) p[i]=3.*unur_urng_sample(NULL);  
distr[0] = unur_distr_condi_new( normal, p, NULL, 0 );
unur_distr_set_name(distr[0],"condi_standardmultinormal_3");
unur_distr_cont_get_mode(distr[0]);
unur_distr_free(normal);
\#undef dim

# conditional: standard multinormal distribution
\#define dim (3)
UNUR_DISTR *normal = unur_distr_multinormal(dim,NULL,NULL);
int i;
double p[dim]; 
for(i=0;i<dim;i++) p[i]=3.*unur_urng_sample(NULL);  
distr[1] = unur_distr_condi_new( normal, p, NULL, 2 );
unur_distr_set_name(distr[1],"condi_standardmultinormal_3");
unur_distr_cont_get_mode(distr[1]);
unur_distr_free(normal);
\#undef dim

# conditional: standard multinormal distribution
\#define dim (4)
UNUR_DISTR *normal = unur_distr_multinormal(dim,NULL,NULL);
int i; 
double p[dim], dir[dim]; 
for(i=0;i<dim;i++) p[i]=3.*unur_urng_sample(NULL);  
for(i=0;i<dim;i++) dir[i]=0.5+unur_urng_sample(NULL);  
distr[2] = unur_distr_condi_new( normal, p, dir, 0 );
unur_distr_set_name(distr[2],"condi_standardmultinormal_4");
unur_distr_cont_get_mode(distr[2]);
unur_distr_free(normal);
\#undef dim

# conditional: multinormal distribution
\#define dim (3)
int i; 
double p[dim], dir[dim]; 
double mean[dim], covar[dim*dim];
UNUR_DISTR *normal;
UNUR_DISTR *covar_distr;
UNUR_GEN *covar_gen;
UNUR_GEN *mean_gen;
for(i=0;i<dim;i++) p[i]=3.*unur_urng_sample(NULL);  
for(i=0;i<dim;i++) dir[i]=0.5+unur_urng_sample(NULL);  
mean_gen = unur_str2gen("normal(0,3)");
for (i=0; i<dim; i++) mean[i] = unur_sample_cont(mean_gen);
unur_free(mean_gen); 
covar_distr = unur_distr_correlation(dim);
covar_gen = unur_init(unur_mcorr_new(covar_distr));
do { unur_sample_matr(covar_gen,covar); 
   normal = unur_distr_multinormal(dim,mean,covar); 
} while (normal==NULL);
unur_distr_free(covar_distr);
unur_free(covar_gen);
distr[3] = unur_distr_condi_new( normal, p, dir, 0 );
unur_distr_set_name(distr[3],"condi_multinormal_random");
unur_distr_cont_get_mode(distr[3]);
unur_distr_free(normal);
\#undef dim

# conditional: multinormal distribution with rectangular domain
\#define dim (3)
int i; 
double p[dim], dir[dim]; 
double ll[3] = {0.,0.,0.};
double ru[3] = {UNUR_INFINITY,UNUR_INFINITY,UNUR_INFINITY};
UNUR_DISTR *normal = unur_distr_multinormal(dim,NULL,NULL);
unur_distr_cvec_set_domain_rect(normal,ll,ru);
for(i=0;i<dim;i++) p[i]=0.01 + 3.*unur_urng_sample(NULL);  
for(i=0;i<dim;i++) dir[i]=0.5+unur_urng_sample(NULL);  
distr[4] = unur_distr_condi_new( normal, p, dir, 0 );
unur_distr_set_name(distr[4],"condi_standardmultinormal_domain");
unur_distr_cont_get_mode(distr[4]);
unur_distr_free(normal);
\#undef dim

# conditional: multinormal distribution with rectangular domain
\#define dim (3)
int i; 
double p[dim]; 
double ll[3] = {0.,0.,0.};
double ru[3] = {UNUR_INFINITY,UNUR_INFINITY,UNUR_INFINITY};
UNUR_DISTR *normal = unur_distr_multinormal(dim,NULL,NULL);
unur_distr_cvec_set_domain_rect(normal,ll,ru);
for(i=0;i<dim;i++) p[i]=0.01 + 3.*unur_urng_sample(NULL);  
distr[5] = unur_distr_condi_new( normal, p, NULL, 2 );
unur_distr_set_name(distr[5],"condi_standardmultinormal_domain");
unur_distr_cont_get_mode(distr[5]);
unur_distr_free(normal);
\#undef dim

# conditional: multinormal distribution with rectangular domain
\#define dim (3)
double p[dim]; 
double ll[3] = {-1.,0.,1.};
double ru[3] = {1.,1.,2.};
UNUR_DISTR *normal = unur_distr_multinormal(dim,NULL,NULL);
unur_distr_cvec_set_domain_rect(normal,ll,ru);
p[0] = -0.5 + unur_urng_sample(NULL);  
p[1] = unur_urng_sample(NULL);  
p[2] = 1.01 + unur_urng_sample(NULL);  
distr[6] = unur_distr_condi_new( normal, p, NULL, 2 );
unur_distr_set_name(distr[6],"condi_standardmultinormal_domain");
unur_distr_cont_get_mode(distr[6]);
unur_distr_free(normal);
\#undef dim


# number of distributions: 7


[validate - test chi2:]

#  + ... pass test
#  0 ... fail to initialize generator
#  - ... fail test
#  . ... do not run test
#  # ... comment
#
# generators:
#  [0]  ... AROU  (default)
#  [1]  ... TDR   (default)
#  [2]  ... TDR   (c=0)
#  [3]  ... ARS   (c=0)
#  [4]  ... TABL  (default)
#
#	0   1   2   3   4  # distribution
#----------------------------------------
# cannot run chi2 test because we have no CDF

[validate - verify hat:]
#  + ... pass test
#  ~ ... fail in at most 1% of samples
#  0 ... fail to initialize generator
#  - ... fail test
#  . ... do not run test
#  # ... comment
#
# generators:
#  [0]  ... AROU (default)
#  [1]  ... TDR  (default)
#  [2]  ... TDR  (c=0)
#  [3]  ... ARS   (c=0)
#  [4]  ... TABL  (default)
#
#	0   1   2   3   4  # distribution
#----------------------------------------
 <0>	+   +   +   +   +  # standard multinormal (dim=3, coord=0)
 <1>	+   +   +   +   +  # standard multinormal (dim=3, coord=2)
 <2>   x+   +   +   +   +  # standard multinormal (dim=4, random dir)
x<3>    .   +   +   +   +  # multinormal (dim=3, random dir)
 <4>   x+   +   +   +   +  # conditional: multinormal distribution with rectangular domain
 <5>   x+   +   +   +   .  # conditional: multinormal distribution with rectangular domain
 <6>   x+   +   +   +   +  # conditional: multinormal distribution with rectangular domain

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

[verbatim]

## work-around for missing functions
int unur_distr_condi_set_pedantic(UNUR_PAR *par ATTRIBUTE__UNUSED, int pedantic ATTRIBUTE__UNUSED)  { return UNUR_FAILURE; }

int unur_distr_condi_chg_verify(UNUR_GEN *gen, int verify)
{
  if (unur_arou_chg_verify(gen,verify)==UNUR_SUCCESS) return UNUR_SUCCESS;
  if (unur_srou_chg_verify(gen,verify)==UNUR_SUCCESS) return UNUR_SUCCESS;
  if (unur_tabl_chg_verify(gen,verify)==UNUR_SUCCESS) return UNUR_SUCCESS;
  if (unur_tdr_chg_verify(gen,verify)==UNUR_SUCCESS) return UNUR_SUCCESS;
  if (unur_ars_chg_verify(gen,verify)==UNUR_SUCCESS) return UNUR_SUCCESS;
  return UNUR_FAILURE;
}	

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