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

[main]

[main - data:]

# method
method: TDR

[main - header:]

/* prototypes */

double pdf_sqrtlin( double x, const UNUR_DISTR *distr );
double dpdf_sqrtlin( double x, const UNUR_DISTR *distr );
double cdf_sqrtlin( double x, const UNUR_DISTR *distr );

double pdf_sqrtlinshft(double x, const UNUR_DISTR *distr );
double dpdf_sqrtlinshft( double x, const UNUR_DISTR *distr );
double cdf_sqrtlinshft( double x, const UNUR_DISTR *distr );

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

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

[new]

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

# [set]

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

# [get]

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

# [chg]

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

# [init]

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

# [reinit]

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

[validate]

[validate - generators:]

# sqrt, PS
par[0] = unur_tdr_new(@distr@);
unur_tdr_set_variant_ps(par);
unur_tdr_set_c(par,-0.5);

# sqrt, PS, few starting points, ARS
par[1] = unur_tdr_new(@distr@);
unur_tdr_set_variant_ps(par);
unur_tdr_set_c(par,-0.5);
unur_tdr_set_usedars(par,FALSE);
unur_tdr_set_cpoints(par,10,NULL);

# sqrt, PS, few construction points
par[2] = unur_tdr_new(@distr@);
unur_tdr_set_variant_ps(par);
unur_tdr_set_c(par,-0.5);
unur_tdr_set_usedars(par,FALSE);
unur_tdr_set_cpoints(par,10,NULL);
unur_tdr_set_max_sqhratio(par,0.25);

# sqrt, PS, truncated
par[3] = unur_tdr_new(@distr@);
unur_tdr_set_variant_ps(par);
unur_tdr_set_c(par,-0.5);
unur_tdr_chg_truncated(gen,0.5,0.9);

# log, PS
par[4] = unur_tdr_new(@distr@);
unur_tdr_set_variant_ps(par);
unur_tdr_set_c(par,0.);

# log, PS, few starting points, ARS
par[5] = unur_tdr_new(@distr@);
unur_tdr_set_variant_ps(par);
unur_tdr_set_c(par,0.);
unur_tdr_set_usedars(par,FALSE);
unur_tdr_set_cpoints(par,10,NULL);

# log, PS, few construction points
par[6] = unur_tdr_new(@distr@);
unur_tdr_set_variant_ps(par);
unur_tdr_set_c(par,0.);
unur_tdr_set_usedars(par,FALSE);
unur_tdr_set_cpoints(par,10,NULL);
unur_tdr_set_max_sqhratio(par,0.25);

# sqrt, PS, few construction points, urng_aux
par[7] = unur_tdr_new(@distr@);
unur_tdr_set_variant_ps(par);
unur_tdr_set_c(par,-0.5);
unur_tdr_set_usedars(par,FALSE);
unur_tdr_set_cpoints(par,10,NULL);
unur_tdr_set_max_sqhratio(par,0.25);
unur_use_urng_aux_default(par);

# reinit, sqrt, PS
par[8] = unur_tdr_new(@distr@);
unur_tdr_set_variant_ps(par);
unur_tdr_set_c(par,-0.5);
unur_tdr_set_cpoints(par,10,NULL);
unur_set_use_distr_privatecopy(par,FALSE);
fpm[0] = 1.;
fpm[1] = 4.;
unur_distr_cont_set_pdfparams(@distr@,fpm,2);
unur_tdr_chg_reinit_percentiles(gen, 2, NULL );
unur_reinit(gen);   

# reinit, log, PS
par[9] = unur_tdr_new(@distr@);
unur_tdr_set_variant_ps(par);
unur_tdr_set_c(par,0.);
unur_tdr_set_cpoints(par,10,NULL);
unur_set_use_distr_privatecopy(par,FALSE);
fpm[0] = 1.;
fpm[1] = 4.;
unur_distr_cont_set_pdfparams(@distr@,fpm,2);
unur_tdr_chg_reinit_percentiles(gen, 2, NULL );
unur_reinit(gen);   


[validate - distributions:]

# Beta distributions
fpm[0] = 1.;
fpm[1] = 2.;
distr[0] = unur_distr_beta(fpm,2);

fpm[0] = 1.;
fpm[1] = 5.;
distr[1] = unur_distr_beta(fpm,2);

fpm[0] = 1.;
fpm[1] = 100.;
distr[2] = unur_distr_beta(fpm,2);

fpm[0] = 2.;
fpm[1] = 5.;
distr[30] = unur_distr_beta(fpm,2);

fpm[0] = 5.;
fpm[1] = 2.;
distr[31] = unur_distr_beta(fpm,2);

fpm[0] = 3.;
fpm[1] = 4.;
distr[3] = unur_distr_beta(fpm,2);

fpm[0] = 5.;
fpm[1] = 100.;
distr[4] = unur_distr_beta(fpm,2);

fpm[0] = 500.;
fpm[1] = 300.;
distr[5] = unur_distr_beta(fpm,2);

fpm[0] = 5.;
fpm[1] = 10.;
fpm[2] = -3.;
fpm[3] = 15.;
distr[6] = unur_distr_beta(fpm,4);

# Cauchy distributions
distr[7] = unur_distr_cauchy(NULL,0);

fpm[0] = 1.;
fpm[1] = 20.;
distr[8] = unur_distr_cauchy(fpm,2);

# Exponential distributions
distr[24] = unur_distr_exponential(NULL,0);

fpm[0] = 30.;
fpm[1] = -5.;
distr[25] = unur_distr_exponential(fpm,2);

# Gamma distributions
fpm[0] = 1.;
distr[9] = unur_distr_gamma(fpm,1);

fpm[0] = 2.;
distr[10] = unur_distr_gamma(fpm,1);

fpm[0] = 3.;
distr[11] = unur_distr_gamma(fpm,1);

fpm[0] = 10.;
distr[12] = unur_distr_gamma(fpm,1);

fpm[0] = 1000.;
distr[13] = unur_distr_gamma(fpm,1);

fpm[0] = 5.;
fpm[1] = 1000.;
distr[14] = unur_distr_gamma(fpm,2);

fpm[0] = 5.;
fpm[1] = 1.e-5;
distr[15] = unur_distr_gamma(fpm,2);

fpm[0] = 5.;
fpm[1] = 10.;
fpm[2] = 1000.;
distr[16] = unur_distr_gamma(fpm,3);

# Laplace distributions
distr[26] = unur_distr_laplace(NULL,0);

fpm[0] = -10.;
fpm[1] = 100.;
distr[27] = unur_distr_laplace(fpm,2);

# Normal distributions
distr[17] = unur_distr_normal(NULL,0);

fpm[0] = 1.;
fpm[1] = 1.e-5;
distr[18] = unur_distr_normal(fpm,2);

fpm[0] = 0.;
fpm[1] = 1.e+5;
distr[19] = unur_distr_normal(fpm,2);

# Uniform distributions
distr[20] = unur_distr_uniform(NULL,0);

fpm[0] = 1.;
fpm[1] = 20.;
distr[21] = unur_distr_uniform(fpm,2);

# F distributions
fpm[0] = 4.;
fpm[1] = 10.;
distr[32] = unur_distr_F(fpm,2);

# pdf with piecewise linear function as transformed density with T = -1/sqrt
distr[28] = unur_distr_cont_new();
unur_distr_cont_set_pdf(distr[28],pdf_sqrtlin);
unur_distr_cont_set_dpdf(distr[28],dpdf_sqrtlin);
unur_distr_cont_set_cdf(distr[28],cdf_sqrtlin);
unur_distr_set_name(distr[28],"sqrtlin");

# pdf with piecewise linear function as transformed density with T = -1/sqrt and shifted mode
distr[29] = unur_distr_cont_new();
unur_distr_cont_set_pdf(distr[29],pdf_sqrtlinshft);
unur_distr_cont_set_dpdf(distr[29],dpdf_sqrtlinshft);
unur_distr_cont_set_cdf(distr[29],cdf_sqrtlinshft);
unur_distr_set_name(distr[29],"sqrtlin");

# truncated distributions
distr[22] = unur_distr_cauchy(NULL,0);
unur_distr_cont_set_domain(distr[22],0.1,1.);
unur_distr_cont_upd_mode(distr[22]);
unur_distr_cont_upd_pdfarea(distr[22]);

# domain exceeds support of pdf
fpm[0] = 3.;
fpm[1] = 4.;
distr[23] = unur_distr_beta(fpm,2);
unur_distr_cont_set_domain(distr[23],-2.,5.);


# number of distributions: 33


[validate - test chi2:]

#  + ... pass test
#  0 ... fail to initialize generator
#  - ... fail test
#  . ... do not run test
#  # ... comment
#
# generators:
#   [0] sqrt, PS
#   [1] sqrt, PS, few starting points, ARS
#   [2] sqrt, PS, few construction points
#   [3] sqrt, PS, truncated
#   [4] log, PS
#   [5] log, PS, few starting points, ARS
#   [6] log, PS, few construction points
#   [7] sqrt, PS, few construction points, urng_aux
#   [8] reinit, log, PS
#   [9] reinit, sqrt, PS
#
#
#	0  1  2  3  4  5  6  7  8  9	# distribution
#-----------------------------------------------------
x <0>	+  +  +  +  +  +  +  +  +  +	# beta (1, 2)
  <1>	+  +  +  +  +  +  +  +  .  .	# beta (1, 5)
x <2>	+  +  +  +  +  +  +  +  +  +	# beta (1, 100)
 <30>	+  +  +  +  +  +  +  +  .  .	# beta (2, 5)
 <31>	+  +  +  +  +  +  +  +  +  +	# beta (5, 2)
  <3>	+  +  +  +  +  +  +  +  .  .	# beta (3, 4)
  <4>	+  +  +  +  +  +  +  +  .  .	# beta (5, 100)
  <5>	+  +  +  +  +  +  +  +  +  +	# beta (500, 300)
  <6>	+  +  +  +  +  +  +  +  +  +	# beta (5, 10, -3, 15)
  <7>	+  +  +  +  0  -  -  +  +  0	# cauchy ()
  <8>	+  +  +  +  0  -  -  +  +  0	# cauchy (1, 20)
 <24>	+  +  +  +  +  +  +  +  +  +	# exponential ()
 <25>	+  +  +  +  +  +  +  +  +  +	# exponential (30, -5)
x <9>	+  +  +  +  +  +  +  +  .  .	# gamma (1)
 <10>	+  +  +  +  +  +  +  +  .  .	# gamma (2)
 <11>	+  +  +  +  +  +  +  +  +  +	# gamma (3)
 <12>	+  +  + x+  +  +  +  +  .  .	# gamma (10)
x<13>	+  +  +  .  +  +  +  +  .  .	# gamma (1000)
 <14>	+  +  +  .  +  +  +  +  .  .	# gamma (5, 1000, 0)
x<15>	+  +  +  .  +  +  +  +  .  .	# gamma (5, 1e-05, 0)
x<16>	+  +  +  .  +  +  +  +  .  .	# gamma (5, 10, 1000)
 <26>	+  +  +  +  +  +  +  +  +  +	# laplace ()
 <27>	+  +  +  +  +  +  +  +  .  .	# laplace (-10, 100)
 <17>	+  +  +  +  +  +  +  +  +  +	# normal ()
x<18>	+  +  +  +  +  +  +  +  .  .	# normal (1, 1e-05)
 <19>	+  +  +  +  +  +  +  +  .  .	# normal (1, 1e+05)
 <20>	+  +  +  +  +  +  +  +  +  +	# uniform ()
 <21>	+  +  +  +  +  +  +  +  .  .	# uniform (1, 20)
 <32>	+  +  +  +  0  0  0  +  -  -	# F (4, 10)

 <22>	+  +  +  +  +  +  +  +  .  .	# cauchy () - truncated
 <23>	+  +  +  +  +  +  +  +  .  .	# beta () - domain superset of support
 <28>	+  +  +  +  0  0  0  +  .  .	# sqrtlin
 <29>	+  +  +  +  0  0  0  +  .  .	# sqrtlin with shifted mode


# sqrtlin ... pdf with piecewise linear function as 
#             transformed density with T = -1/sqrt

[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] sqrt, PS
#   [1] sqrt, PS, few starting points, ARS
#   [2] sqrt, PS, few construction points
#   [3] sqrt, PS, truncated
#   [4] log, PS
#   [5] log, PS, few starting points, ARS
#   [6] log, PS, few construction points
#   [7] sqrt, PS, few construction points, urng_aux
#   [8] reinit, log, PS
#   [9] reinit, sqrt, PS
#
#
#	0  1  2  3  4  5  6  7	8  9	# distribution
#-----------------------------------------------------
x <0>	+  +  +  +  +  +  +  +  +  +	# beta (1, 2)
  <1>	+  +  +  +  +  +  +  +  .  .	# beta (1, 5)
x <2>	+  +  +  +  +  +  +  +  +  +	# beta (1, 100)
 <30>	+  +  +  +  +  +  +  +  .  .	# beta (2, 5)
 <31>	+  +  +  +  +  +  +  +  +  +	# beta (5, 2)
  <3>	+  +  +  +  +  +  +  +  .  .	# beta (3, 4)
  <4>	+  +  +  +  +  +  +  +  .  .	# beta (5, 100)
  <5>	+  +  +  +  +  +  +  +  +  +    # beta (500,300)
  <6>	+  +  +  +  +  +  +  +  +  +	# beta (5, 10, -3, 15)
  <7>	+  +  +  +  0  -  -  +  .  .	# cauchy ()
  <8>	+  +  +  +  0  -  -  +  .  .	# cauchy (1, 20)
 <24>	+  +  +  +  +  +  +  +  +  +	# exponential ()
 <25>	+  +  +  +  +  +  +  +  +  +	# exponential (30, -5)
x <9>	+  +  +  +  +  +  +  +  .  .	# gamma (1)
 <10>	+  +  +  +  +  +  +  +  .  .	# gamma (2)
 <11>	+  +  +  +  +  +  +  +  +  +	# gamma (3)
 <12>	+  +  + x+  +  +  +  +  .  .	# gamma (10)
x<13>	+  +  +  .  +  +  +  +  .  .	# gamma (1000)
 <14>	+  +  +  .  +  +  +  +  .  .	# gamma (5, 1000, 0)
x<15>	+  +  +  .  +  +  +  +  .  .	# gamma (5, 1e-05, 0)
x<16>	+  +  +  .  +  +  +  +  .  .	# gamma (5, 10, 100000)
 <26>	+  +  +  +  +  +  +  +  +  +	# laplace ()
 <27>	+  +  +  +  +  +  +  +  .  .	# laplace (-10, 100)
 <17>	+  +  +  +  +  +  +  +  +  +	# normal ()
x<18>	+  +  +  +  +  +  +  +  .  .	# normal (1, 1e-05)
 <19>	+  +  +  +  +  +  +  +  .  .	# normal (1, 1e+05)
 <20>	+  +  +  +  +  +  +  +  +  +	# uniform ()
 <21>	+  +  +  +  +  +  +  +  .  .	# uniform (1, 20)
 <32>	+  +  +  +  0  0  0  +  -  -	# F (4, 10)

 <22>	+  +  +  +  +  +  +  +  .  .	# cauchy () - truncated
 <23>	+  +  +  +  +  +  +  +  .  .	# beta () - domain superset of support
 <28>	+  +  +  +  .  .  .  +  .  .	# sqrtlin
 <29>	.  .  .  .  .  .  .  .  .  .	# sqrtlin with shifted mode


# sqrtlin ... pdf with piecewise linear function as 
#             transformed density with T = -1/sqrt


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

[verbatim]

/* pdf with piecewise linear function as transformed density with T = -1/sqrt */
double pdf_sqrtlin( double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
{ 
	double y = 1./(fabs(x)+1.);
	return y*y;
}
double dpdf_sqrtlin( double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
{ 
	double y = 1./(fabs(x)+1.);
	y = 2.*y*y*y;
	return ((x<0.) ? y : - y);
}
double cdf_sqrtlin( double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
{ 
	if (x<=0.)
		return 0.5/(1.-x);
	else
		return (1.-0.5/(1.+x));
}

/* pdf with piecewise linear function as transformed density with T = -1/sqrt and shifted mode */
double pdf_sqrtlinshft( double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
{ 
	double y;
	x -= 1000.;
	y = 1./(fabs(x)+1.);
	return y*y;
}
double dpdf_sqrtlinshft( double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
{ 
	double y;
	x -= 1000.;
	y = 1./(fabs(x)+1.);
	y = 2.*y*y*y;
	return ((x<0.) ? y : - y);
}
double cdf_sqrtlinshft( double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
{ 
	x -= 1000.;
	if (x<=0.)
		return 0.5/(1.-x);
	else
		return (1.-0.5/(1.+x));
}

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