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

[main]

[main - data:]

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

[main - header:]

/* prototypes */

double HR_invalid(double x, const UNUR_DISTR *distr);

double HR_decreasing(double x, const UNUR_DISTR *distr);
double CDF_decreasing(double x, const UNUR_DISTR *distr);

double HR_constant(double x, const UNUR_DISTR *distr);
double CDF_constant(double x, const UNUR_DISTR *distr);

double HR_increasing_wb31(double x, const UNUR_DISTR *distr);
double CDF_increasing_wb31(double x, const UNUR_DISTR *distr);

double HR_increasing_gm31(double x, const UNUR_DISTR *distr);
double CDF_increasing_gm31(double x, const UNUR_DISTR *distr);

double HR_increasing_gm51(double x, const UNUR_DISTR *distr);
double CDF_increasing_gm51(double x, const UNUR_DISTR *distr);

int unur_hri_set_pedantic( UNUR_PAR *par, int pedantic );

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

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

[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

[new - data missing in distribution object:
   distr = unur_distr_cont_new(); ]

/* hazard rate */
~( distr );
	--> expected_NULL --> UNUR_ERR_DISTR_REQUIRED

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

[set]

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

~_verify(par,1);
	--> expected_setfailed --> UNUR_ERR_NULL

~_p0(par,1.);
	--> expected_setfailed --> UNUR_ERR_NULL


[set - invalid parameter object:
   distr = unur_distr_normal(NULL,0);
   par = unur_arou_new(distr); ]

~_verify(par,1);
	--> expected_setfailed --> UNUR_ERR_PAR_INVALID

~_p0(par,1.);
	--> expected_setfailed --> UNUR_ERR_PAR_INVALID

unur_par_free(par);


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

# [get]

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

[chg]

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

~_verify(gen,1);
	--> expected_setfailed --> UNUR_ERR_GEN_INVALID


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

[init]

[init - left border no valid upper bound:
   gen = NULL;
   distr = unur_distr_cont_new();
   unur_distr_cont_set_hr(distr,HR_invalid);
   par = unur_hri_new(distr); <-- ! NULL]

gen = unur_init( par );
        --> expected_NULL --> UNUR_ERR_GEN_CONDITION


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

[reinit]

[reinit - does not exist:
   distr = unur_distr_cont_new();
   unur_distr_cont_set_hr(distr,HR_increasing_wb31);
   par = unur_hri_new(distr);
   gen = unur_init( par ); <-- ! NULL ]

unur_reinit( gen );
	--> expected_reinit

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

[sample]

[sample - compare:
    distr = unur_distr_cont_new();
    unur_distr_cont_set_hr(distr,HR_increasing_wb31);
    par = NULL; ]

/* default algorithm */
par = unur_hri_new(distr);
	-->compare_sequence_par_start

/* default algorithm - verifying mode */
par = unur_hri_new(distr);
unur_hri_set_verify(par,1);
	-->compare_sequence_par

/* default algorithm - ignore invalid boundary */
unur_distr_cont_set_domain(distr,-10.,10.);
par = unur_hri_new(distr);
	-->compare_sequence_par_start

#.....................................................................

[sample - compare reinit:
   distr = unur_distr_cont_new();
   unur_distr_cont_set_hr(distr,HR_increasing_wb31);
   par = NULL;
   gen = NULL; ]

/* original generator object */
par = unur_hri_new(distr);
gen = unur_init(par);
        -->compare_sequence_gen_start

/* reinit */
unur_reinit(gen);
        -->compare_sequence_gen

#.....................................................................

[sample - compare stringparser:
   distr = NULL;
   par = NULL;
   gen = NULL; ]

distr = unur_distr_cont_new();
unur_distr_cont_set_hrstr(distr,"3*x^2");
par = unur_hri_new(distr);
gen = unur_init(par);
	-->compare_sequence_gen_start

unur_free(gen); gen = NULL;
unur_distr_free(distr); distr = NULL;
gen = unur_str2gen( "cont; hr = \"3*x^2\"; domain = (0,inf)& \
	             method = hri" );
	-->compare_sequence_gen

#unur_free(gen); gen = NULL;
#distr = unur_distr_cont_new();
#unur_distr_cont_set_hrstr(distr,"3*x^2");
#par = unur_hri_new(distr);
#unur_hri_set_p0(par,2.);
#gen = unur_init(par);
#	-->compare_sequence_gen_start

#unur_free(gen); gen = NULL;
#unur_distr_free(distr); distr = NULL;
#gen = unur_str2gen( "cont; hr = \"1/(1+x)\"; domain = (0,inf)& \
#		     method = hri; p0 = 1." );
#	-->compare_sequence_gen


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

[validate]

[validate - generators:]

# default program
par[0] = unur_hri_new(@distr@);

# set design point
par[0] = unur_hri_new(@distr@);
unur_hri_set_p0(par,2.);

[validate - distributions:]

# decreasing hazard rate
distr[0] = unur_distr_cont_new();
unur_distr_set_name(distr[0],"decreasing HR");
unur_distr_cont_set_hr(distr[0],HR_decreasing);
unur_distr_cont_set_cdf(distr[0],CDF_decreasing);

# constant hazard rate
distr[1] = unur_distr_cont_new();
unur_distr_set_name(distr[1],"constant HR");
unur_distr_cont_set_hr(distr[1],HR_constant);
unur_distr_cont_set_cdf(distr[1],CDF_constant);

# increasing hazard rate
distr[2] = unur_distr_cont_new();
unur_distr_set_name(distr[2],"increasing HR wb31");
unur_distr_cont_set_hr(distr[2],HR_increasing_wb31);
unur_distr_cont_set_cdf(distr[2],CDF_increasing_wb31);

distr[3] = unur_distr_cont_new();
unur_distr_set_name(distr[3],"increasing HR gm31");
unur_distr_cont_set_hr(distr[3],HR_increasing_gm31);
unur_distr_cont_set_cdf(distr[3],CDF_increasing_gm31);

distr[4] = unur_distr_cont_new();
unur_distr_set_name(distr[4],"increasing HR gm51");
unur_distr_cont_set_hr(distr[4],HR_increasing_gm51);
unur_distr_cont_set_cdf(distr[4],CDF_increasing_gm51);

# number of distributions: 5

[validate - test chi2:]

#  + ... pass test
#  0 ... fail to initialize generator
#  - ... fail test
#  . ... do not run test
#  # ... comment
#
# generators:
#  [0] ... default variant
#  [1] ... set design point
#
#gen	0   1	# distribution
#---------------------------------------------
x<0>	-   -	# hazard rate decreasing 
 <1>	+   +	# hazard rate constant
 <2>	+   +	# hazard rate increasing wb31
 <3>	+   +	# hazard rate increasing gm31
 <4>	+   +	# hazard rate increasing gm51


[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] ... default variant
#  [1] ... set design point
#
#gen	0   1	# distribution
#---------------------------------------------
x<0>	-   .	# hazard rate decreasing 
 <1>	+   +	# hazard rate constant
 <2>	+   +	# hazard rate increasing wb31
 <3>	+   +	# hazard rate increasing gm31
 <4>	+   +	# hazard rate increasing gm51


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

[verbatim]

double HR_invalid(double x ATTRIBUTE__UNUSED, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
     /* example with invalid hazard rate */
{ return 0.; }


double HR_decreasing(double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
     /* example with decreasing hazard rate */
{ return (1./(1.+x)); }

double CDF_decreasing(double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
     /* CDF for example with decreasing hazard rate */
{ return (x/(1. + x)); }


double HR_constant(double x ATTRIBUTE__UNUSED, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
     /* example with constant hazard rate: standard expontential */
{ return 1.; }

double CDF_constant(double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
     /* CDF for example with constant hazard rate: standard expontential */
{ return (1.-exp(-x)); }


double HR_increasing_wb31(double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
     /* example with increasing hazard rate: Weibull (alpha=3,beta=1) */
{ return (3*x*x); }

double CDF_increasing_wb31(double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
     /* CDF for example with increasing hazard rate: Weibull (alpha=3,beta=1) */
{ return (1.-exp(-x*x*x)); }


double HR_increasing_gm31(double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
     /* example with increasing hazard rate: gamma (alpha=3,beta=1) */
{ return (x*x)/(x*x+2*x+2.); }

double CDF_increasing_gm31(double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
     /* CDF for example with increasing hazard rate: gamma (alpha=3,beta=1) */
{ return 1.-(x*x*exp(-x))/2.-(x*exp(-x))-exp(-x); }


double HR_increasing_gm51(double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
     /* example with increasing hazard rate: gamma (alpha=5,beta=1) */
{ return pow(x,4.)/(pow(x,4.)+4*pow(x,3.)+12.*x*x+24.*x+24.); }

double CDF_increasing_gm51(double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
     /* CDF for example with increasing hazard rate: gamma (alpha=5,beta=1) */
{ return (-exp(-x)/24.)*((pow(x,4.)+4*pow(x,3.)+12.*x*x+24.*x+24.))+1.; }


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

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