close Warning: Can't synchronize with repository "(default)" (/var/svn/tolp does not appear to be a Subversion repository.). Look in the Trac log for more information.

Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#975 closed defect (fixed)

Error in DistPoissonInv

Reported by: imendez Owned by: Víctor de Buen Remiro
Priority: normal Milestone: Numerical methods
Component: Math Version: 2.0.1
Severity: major Keywords: distribution, sample, inverse, probability
Cc:

Description

Hi,

I think the function DistPoissonInv does not work right.
If X is a variable following a Poisson distribution with lambda parameter equal to, for example, 1.1, we have that:

Real lambda = 1.1;
Real prob0 = DistPoisson(0, lambda); // prob0 = 0.332871
Real prob1 = DistPoisson(1, lambda); // prob1 = 0.699030
Real prob2 = DistPoisson(2, lambda); // prob2 = 0.900416

where probZ is the probability of X = z.
Then, using the inverse probability distribution:

Real pois0.1 = DistPoissonInv(0.1, lambda); // prob0.1 = 0
Real pois0.4 = DistPoissonInv(0.4, lambda); // prob0.4 = 0 ¡¡¡!!!
Real pois0.8 = DistPoissonInv(0.8, lambda); // prob0.8 = 1 ¡¡¡!!!

Note that pois0.1 takes the right value, but pois0.4 and pois0.8 should be, respectively, 1 and 2.

In fact, when simulating a Poisson distribution by the inverse transform sample method, the average of the simulated sample is not equal to the lambda parameter used:

// Real lambda = 1.1;
Set poisson_sim = For(1, 1000, Real(Real k){
  Real rnd = Rand(0, 1);
  DistPoissonInv(rnd, lambda)
});
Real poisson_avg = SetAvr(poisson_sim);

In this case, poisson_avg is approximately equal to 0.72, when it should be equal to 1.1 (lambda)

Regards

Change History (11)

comment:1 Changed 14 years ago by Víctor de Buen Remiro

Milestone: Numerical methods
Status: newaccepted

Hola, perdón por el retraso.

He visto que hay problemas en la inversa de funciones de distribución inversa de la librería dcdflib que es la que usamos.

Estoy investigando si hay versiones más modernas o si la tenemos mal implementada, ya que tenemos el código C directamente imbricado y retocado.

También estoy intentando hacer una función de búsqueda binaria con complejidad logarítmica que nos puede servir para todas las distribuciones discretas.

comment:2 Changed 14 years ago by Víctor de Buen Remiro

(In [3037]) Refs #975

comment:3 Changed 14 years ago by Víctor de Buen Remiro

(In [3038]) Refs #975
Upgrading GSL_VERSION_NUM to 10800

comment:4 Changed 14 years ago by Víctor de Buen Remiro

(In [3039]) Refs #975
Upgrading version of DCDFLIB

Source : http://people.sc.fsu.edu/~jburkardt/cpp_src/dcdflib/dcdflib.html
Version : (Last revised on 17 November 2006)

comment:5 Changed 14 years ago by Víctor de Buen Remiro

(In [3040]) Refs #975
New implementation of generic BDat BDiscreteDist::Inverse

comment:6 Changed 14 years ago by Víctor de Buen Remiro

(In [3041]) Refs #975
Upgrading version of DCDFLIB

Source : http://people.sc.fsu.edu/~jburkardt/cpp_src/dcdflib/dcdflib.html
Version : (Last revised on 17 November 2006)

comment:7 Changed 14 years ago by Víctor de Buen Remiro

(In [3042]) Refs #975
Upgrading version of DCDFLIB

Source : http://people.sc.fsu.edu/~jburkardt/cpp_src/dcdflib/dcdflib.html
Version : (Last revised on 17 November 2006)

comment:8 Changed 14 years ago by Víctor de Buen Remiro

(In [3043]) Refs #975
Upgrading version of DCDFLIB

Source : http://people.sc.fsu.edu/~jburkardt/cpp_src/dcdflib/dcdflib.html
Version : (Last revised on 17 November 2006)

comment:9 Changed 14 years ago by Víctor de Buen Remiro

(In [3044]) Refs #975
Upgrading version of DCDFLIB

Source : http://people.sc.fsu.edu/~jburkardt/cpp_src/dcdflib/dcdflib.html
Version : (Last revised on 17 November 2006)

comment:10 Changed 14 years ago by Víctor de Buen Remiro

Resolution: fixed
Status: acceptedclosed

Ya funciona correctamente la función DistPoissonInv.

En test 975 he dejado el código de comprobación.

En cualquier caso, para simular la Poisson existe una función más adecuada que DistPoissonInv, que es la gsl_ran_poisson

comment:11 Changed 14 years ago by Jorge

(In [3045]) refs #975, ipmpar.c is not compiled

Note: See TracTickets for help on using tickets.