Skip to content

Instantly share code, notes, and snippets.

@j-faria
Created November 2, 2018 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j-faria/554f58a17c59debe02302b77dea4a077 to your computer and use it in GitHub Desktop.
Save j-faria/554f58a17c59debe02302b77dea4a077 to your computer and use it in GitHub Desktop.
Find shape and scale of InvGamma distribution
# how to do the same as Michael Betancourt in
# https://betanalpha.github.io/assets/case_studies/gp_part3/part3.html
import numpy as np
from scipy.stats import invgamma
from scipy.optimize import minimize
f = lambda x, lims: \
(np.array([invgamma(a=x[0], scale=x[1]).cdf(lims[0]) - 0.01,
invgamma(a=x[0], scale=x[1]).sf(lims[1]) - 0.01])**2
).sum()
result = minimize(f, x0=[8, 30], args=[2, 10],
bounds=[(0, None),(0, None)], tol=1e-10)
a, b = result.x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment