Skip to content

Commit cc179dd

Browse files
fix h_inv overflow with higher dimensions
1 parent ae18a22 commit cc179dd

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

crfmnes/alg.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@
1212
def get_h_inv(dim):
1313
f = lambda a, b: ((1. + a * a) * math.exp(a * a / 2.) / 0.24) - 10. - dim
1414
f_prime = lambda a: (1. / 0.24) * a * math.exp(a * a / 2.) * (3. + a * a)
15-
h_inv = 1.0
15+
h_inv = 6.0
1616
while abs(f(h_inv, dim)) > 1e-10:
17+
last = h_inv
1718
h_inv = h_inv - 0.5 * (f(h_inv, dim) / f_prime(h_inv))
19+
if abs(h_inv - last) < 1e-16:
20+
# Exit early since no further improvements are happening
21+
break
1822
return h_inv
1923

2024

0 commit comments

Comments
 (0)