Skip to content

Commit 75f5f7f

Browse files
dweindldilpath
andauthored
Update petab/v1/simulate.py
Co-authored-by: Dilan Pathirana <59329744+dilpath@users.noreply.github.com>
1 parent 1fb6b39 commit 75f5f7f

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

petab/v1/simulate.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,22 +256,23 @@ def sample_noise(
256256
observable_transformation = observable_row.get(
257257
petab.C.OBSERVABLE_TRANSFORMATION, petab.C.LIN
258258
)
259+
transform = lambda x: x
259260
# observableTransformation=log -> the log of the simulated value is
260261
# distributed according to `noise_distribution`
261262
if observable_transformation == petab.C.LOG:
262263
simulated_value = np.log(simulated_value)
264+
transform = np.exp
263265
elif observable_transformation == petab.C.LOG10:
264266
simulated_value = np.log10(simulated_value)
267+
transform = lambda x: np.power(10, x)
265268

266269
# below is e.g.: `np.random.normal(loc=simulation, scale=noise_value)`
267270
simulated_value_with_noise = getattr(rng, noise_distribution)(
268271
loc=simulated_value, scale=noise_value * noise_scaling_factor
269272
)
270273

271-
if observable_transformation == petab.C.LOG:
272-
simulated_value_with_noise = np.exp(simulated_value_with_noise)
273-
elif observable_transformation == petab.C.LOG10:
274-
simulated_value_with_noise = np.power(10, simulated_value_with_noise)
274+
# apply observable transformation, ensure `float` type
275+
simulated_value_with_noise = float(transform(simulated_value_with_noise))
275276

276277
if zero_bounded and np.sign(simulated_value) != np.sign(
277278
simulated_value_with_noise

0 commit comments

Comments
 (0)