Skip to content

Commit 42c69d1

Browse files
committed
fix constant to prevent nan or inf errors
1 parent fa0380d commit 42c69d1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

spikefinder/main.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ def optimize_predictions(predictions, spikes, num_support=10, regularize=5e-8, v
136136
# support points of piece-wise linear function
137137
if num_support > 2:
138138
F = predictions
139-
F = F[F > (max(F) - min(F)) / 100.]
139+
if F.sum() > 0:
140+
F = F[F > (max(F) - min(F)) / 100.]
140141
x = list(percentile(F, range(0, 101, num_support)[1:-1]))
141142
x = asarray([0.] + x + [max(F)])
142143

@@ -154,7 +155,7 @@ def objf(y):
154155
f = interp1d(x, y)
155156

156157
# compute predicted firing rates
157-
l = f(predictions) + 1e-16
158+
l = f(predictions) + 1e-8
158159

159160
# compute negative log-likelihood (ignoring constants)
160161
K = mean(l - spikes * log(l))

0 commit comments

Comments
 (0)