﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	severity	resolution	keywords	cc
52	Density Functions Correction	jcaballero	Jorge	"Hello all:

We're Antonio Cerdán, Andrés Martínez and Jorge Caballero from Bayes.

We have detected anomalies in density functions integrated in TOL; we have 
created a new function: Eulerian gamma Integral:

1) Uniform Density Function
2) gamma Eulerian function
3) Gamma Density Funtion
4) Exponential Density Function

///////////////////////

/////////////////////////////////////////////////////////////////////
Real DensUnif( Real x, Real a, Real b)
///////////////////////////////////////////////////////////////////// 
{
  Real salida = If(And(LE(a,x),GE(b,x)),1/(b-a),0);
  salida
};
/////////////////////////////////////////////////////////////////////
PutDescription(""Density Uniform(a,b)"",DensUnif);
/////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////
Real gamma( Real alpha)
///////////////////////////////////////////////////////////////////// 
{
  Real UserFunc00(Matrix X)
  {
    Real theta = MatDat(X,1,1);
    theta^(alpha-1)*Exp(-theta)
  };
  If(IsInteger(alpha),Factorial(alpha-1),
  {
    Set vegas = MonteCarloVegas(UserFunc00,1,Col(0),Col(300*alpha),1000,
10000);
    WriteLn(""gamma(""<<alpha<<"")=""<<vegas[1]);
    vegas[1]
  })
};
/////////////////////////////////////////////////////////////////////
PutDescription(""Eulerian improper gamma integral "",gamma);
/////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////
Real DensGam(Real x, Real alpha, Real beta)
///////////////////////////////////////////////////////////////////// 
{
  Real func   = If(GE(x,0),x^(alpha-1)*Exp(-beta*x),0);
  Real cte    = gamma(x);
  Real output = cte*func;
  output
};
/////////////////////////////////////////////////////////////////////
PutDescription(""Gamma Density constructed from Eulerian gamma"",
DensGam);
/////////////////////////////////////////////////////////////////////

//////////////////////////////////////////
Real DensExpon(Real x, Real lambda)
//////////////////////////////////////////
{
  Real output = If(GE(x,0),lambda*Exp(-lambda*x),0);
  output
};
/////////////////////////////////////////////////////////////////////
PutDescription(""Exponential Density Function with parameter lambda"",
DensExpon);
/////////////////////////////////////////////////////////////////////

///////////////

Follows the explication about the old functions did not work:

1) Uniform:

   DensUniform(Real x, Real a, Real b);

   Example:
     Real a = DensUniform(1,0,2);
     Return a = 1, when the true value is a = 0.5

   Because of the pdf is:

    f(x) = 1/(b-a), si x belong to (a,b) or
    f(x) = 0      , otherwise

   With the new pdf will be:

   Real a = DensUnif(1,0,2);
   Obtaining a = 0.5

2) Gamma Density Function:

   DensGamma(Real x,Real p);

  The Gamma Density Function needs 3 parameters:

  DensGamma(Real x,Real p, Real q); 
  We have verify that  the value for q is 1 by defect in the old pdf, where q is
  the exponential parameter.

   With the new pdf DensGamma(Real x,Real p);
   Real a = DensGam(3,1,4);
   The true value is: a = 0.000012

3) Exponential pdf:

   DensExp(Real x);

   The Exponential Density Function needs 2 parameters, present pdf don' t work.

   With the new pdf:

   Real a = DensExpon(3,1);
   The true value is: a = 0.049787;

Best regards.

Bayes Team for TdE"	defect	closed	normal		Math	head	normal	fixed		
