Skip to content

Commit 6bf30e9

Browse files
committed
now error raising are coherent with paper
1 parent 30c277a commit 6bf30e9

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

grb-trigger-algorithms/algorithms/pfocus.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ def __call__(
7474
self.global_max = 0.0
7575
self.time_offset = 0
7676
for t, (x_t, b_t) in enumerate(zip(xs, bs)):
77+
if b_t <= 0:
78+
raise ValueError("background rate must be greater than zero.")
7779
self.update(x_t, b_t)
7880
if self.global_max > self.threshold_llr:
7981
return sqrt(2 * self.global_max), -self.time_offset + t + 1, t
8082
return 0.0, len(xs) + 1, len(xs)
8183

8284
def update(self, x, b):
83-
if b <= 0:
84-
raise ValueError("Background rate must be greater than zero.")
8585
p = self.curve_list.pop(-1)
8686
acc = Curve(p.x + x, p.b + b, p.t + 1, p.m)
8787
while dominate(p, self.curve_list[-1], acc) <= 0:

grb-trigger-algorithms/algorithms/pfocus_des.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ def step(self, x):
116116
x_t_m = self.buffer.popleft()
117117
self.des_update(x_t_m)
118118
self.lambda_t = self.s_t + self.m * self.b_t
119+
if self.lambda_t <= 0:
120+
raise ValueError("background rate must be greater than zero.")
119121
self.focus.update(x, self.lambda_t)
120122
if self.focus.global_max:
121123
significance, offset = self.qc()
@@ -127,7 +129,6 @@ def init(**kwargs):
127129
"""
128130
For compatibility with exhaustive and conventional algorithms.
129131
"""
130-
131132
def run(xs):
132133
"""
133134
Args:

grb-trigger-algorithms/algorithms/pfocus_minimal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ def focus_maximize(cs):
2222

2323

2424
def focus_update(cs, x, b, c):
25-
if b <= 0:
26-
raise ValueError("Background rate must be greater than zero.")
2725
if cs and dominates(k := curve_update(cs[0], x, b), c):
2826
return [k] + focus_update(cs[1:], x, b, k)
2927
return [(0, 0.0, 0)]
@@ -52,6 +50,8 @@ def focus(xs: list[int], bs: list[float], threshold: float):
5250
cs = [(0, 0.0, 0)]
5351

5452
for t, (x_t, b_t) in enumerate(zip(xs, bs)):
53+
if b_t <= 0:
54+
raise ValueError("background rate must be greater than zero.")
5555
cs = focus_update(cs, x_t, b_t, (1, 1.0, 0))
5656
global_max, time_offset = focus_maximize(cs)
5757
if global_max > threshold:

grb-trigger-algorithms/algorithms/pfocus_true.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ def run(xs: list[int]):
4141
return sqrt(2 * focus.global_max), t - focus.time_offset + 1, t
4242
return 0, t + 1, t
4343

44+
if b <= 0:
45+
raise ValueError("background rate must be greater than zero.")
4446
if mu_min < 1:
4547
raise ValueError("mumin must be greater or equal 1.0")
4648
if threshold <= 0:

0 commit comments

Comments
 (0)