Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multivariate normal with discrete approximation #948

Merged
merged 9 commits into from
May 26, 2021
18 changes: 17 additions & 1 deletion HARK/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,22 @@ def approx(self, N):
return DiscreteDistribution(
pmf, X, seed=self.RNG.randint(0, 2 ** 31 - 1, dtype="int32")
)

def approx_equiprobable(self, N):
Mv77 marked this conversation as resolved.
Show resolved Hide resolved

CDF = np.linspace(0,1,N+1)
lims = stats.norm.ppf(CDF)
scores = (lims - self.mu)/self.sigma
pdf = stats.norm.pdf(scores)

# Find conditional means using Mills's ratio
pmf = np.diff(CDF)
X = self.mu - np.diff(pdf)/pmf

return DiscreteDistribution(
pmf, X, seed=self.RNG.randint(0, 2 ** 31 - 1, dtype="int32")
)


class MVNormal(Distribution):
"""
Expand Down Expand Up @@ -367,7 +383,7 @@ def approx(self, N):
A = np.matmul(Q,sqrtV)

# Now find a discretization for a univariate standard normal.
z_approx = Normal().approx(N)
z_approx = Normal().approx_equiprobable(N)

# Now create the multivariate grid and pmf
Z = np.array(list(product(*[z_approx.X]*self.M)))
Expand Down