EconForge / dolo.py

Economic modelling in python
BSD 2-Clause "Simplified" License
98 stars 72 forks source link

Mixture distribution discretization fails #215

Closed NormannR closed 3 years ago

NormannR commented 3 years ago

Replication code:

from dolo.numeric.distribution import *
from dolo.numeric.processes import *
distr = Mixture(index=Bernouilli(π=0.5), distributions={0: ConstantProcess(μ=0.5), 1: UNormal(σ=1.,μ=0.)})
distr.discretize()

Error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/normann/Dropbox/Pablo/dolo.py/dolo/numeric/distribution.py", line 650, in discretize
    dist = self.distributions[xind].discretize()
TypeError: unhashable type: 'numpy.ndarray'

I am on it.

albop commented 3 years ago

I've checked the state of this issue. In distribution.py the same piece of code appears several times:

            discr_iid = self.discretize(to="iid")
            nodes = discr_iid.points
            transitions = np.array(
                [
                    discr_iid.weights,
                ]
                * N
            )

It seems to me, this should appear only once in the DiscretizedIIDProcess class. Then all subclasses, the subclass should call the parent method when needed.

albop commented 3 years ago

Actually, FiniteDistribution seems to be a better place.