Skip to content

Commit f50e79f

Browse files
added numerical stability to eta computation in ./models
1 parent 63e04a5 commit f50e79f

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

batchglm/models/base_glm/model.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ def eta_loc(self) -> np.ndarray:
9898

9999
@property
100100
def eta_scale(self) -> np.ndarray:
101-
return np.matmul(self.design_scale, self.b)
101+
eta = np.matmul(self.design_scale, self.b)
102+
eta = self.np_clip_param(eta, "eta_scale")
103+
return eta
102104

103105
@property
104106
def location(self):

batchglm/models/glm_nb/model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def eta_loc(self) -> np.ndarray:
3030
eta = np.matmul(self.design_loc, self.a)
3131
if self.size_factors is not None:
3232
eta += self.size_factors
33+
eta = self.np_clip_param(eta, "eta_loc")
3334
return eta
3435

3536
def eta_loc_j(self, j) -> np.ndarray:
@@ -39,6 +40,7 @@ def eta_loc_j(self, j) -> np.ndarray:
3940
eta = np.matmul(self.design_loc, self.a[:, j])
4041
if self.size_factors is not None:
4142
eta += self.size_factors
43+
eta = self.np_clip_param(eta, "eta_loc")
4244
return eta
4345

4446
# Re-parameterizations:

0 commit comments

Comments
 (0)