Skip to content

Commit

Permalink
make eventScoring work with fs float as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Amirshahi Alireza committed Sep 20, 2023
1 parent 51da727 commit 7408652
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/timescoring/scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,19 @@ def __init__(self, ref: Annotation, hyp: Annotation, param: Parameters = Paramet
self.tpMask = np.zeros_like(self.ref.mask)
extendedRef = EventScoring._extendEvents(self.ref, param.toleranceStart, param.toleranceEnd)
for event in extendedRef.events:
relativeOverlap = (np.sum(self.hyp.mask[round(event[0] * self.fs):round(event[1] * self.fs)]) / self.fs
) / (event[1] - event[0])
start_idx = int(round(event[0] * self.fs))
end_idx = int(round(event[1] * self.fs))
relativeOverlap = (np.sum(self.hyp.mask[start_idx:end_idx]) / self.fs) / (event[1] - event[0])
if relativeOverlap > param.minOverlap + 1e-6:
self.tp += 1
self.tpMask[round(event[0] * self.fs):round(event[1] * self.fs)] = 1
self.tpMask[start_idx: end_idx] = 1

# Count False detections
self.fp = 0
for event in self.hyp.events:
if np.any(~self.tpMask[round(event[0] * self.fs):round(event[1] * self.fs)]):
start_idx = int(round(event[0] * self.fs))
end_idx = int(round(event[1] * self.fs))
if np.any(~self.tpMask[start_idx:end_idx]):
self.fp += 1

self.computeScores()
Expand Down

0 comments on commit 7408652

Please sign in to comment.