Skip to content

Commit

Permalink
Use numba_scipy to speed up approximation of CLR critical value funct…
Browse files Browse the repository at this point in the history
…io (#80)

* Use numba_scipy to speed up approximation of CLR critical value function.

* numba-scipy not numba_scipy.

* Without numba

* Forgot some lineprof decorators.
  • Loading branch information
mlondschien authored Jun 7, 2024
1 parent f5bbf5b commit 9aa042d
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions ivmodels/tests/conditional_likelihood_ratio.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,25 @@ def conditional_likelihood_ratio_critical_value_function(
return 1 - scipy.stats.chi2(q).cdf(z)

if method in ["numerical_integration"]:
beta = scipy.stats.beta((q - p) / 2, p / 2)
chi2 = scipy.stats.chi2(q)
alpha = (q - p) / 2.0
beta = p / 2.0
k = q / 2.0
z_over_2 = z / 2.0

a = s_min / (z + s_min)
const = np.power(a, -alpha - beta + 1) / scipy.special.beta(alpha, beta)

def integrand(b):
return beta.pdf(b) * chi2.cdf(z / (1 - a * b))
def integrand(y):
return const * scipy.special.gammainc(k, z_over_2 / y)

res = scipy.integrate.quad(
integrand,
0,
1 - a,
1,
weight="alg",
wvar=(beta - 1, alpha - 1),
epsabs=tol,
)

return 1 - res[0]

elif method == "power_series":
Expand Down

0 comments on commit 9aa042d

Please sign in to comment.