Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions petab/v1/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,20 +241,38 @@ def sample_noise(
simulated_value,
)

# default noise distribution is petab.C.NORMAL
noise_distribution = petab_problem.observable_df.loc[
observable_row = petab_problem.observable_df.loc[
measurement_row[petab.C.OBSERVABLE_ID]
].get(petab.C.NOISE_DISTRIBUTION, petab.C.NORMAL)
]
# default noise distribution is petab.C.NORMAL
noise_distribution = observable_row.get(
petab.C.NOISE_DISTRIBUTION, petab.C.NORMAL
)
# an empty noise distribution column in an observables table can result in
# `noise_distribution == float('nan')`
if pd.isna(noise_distribution):
noise_distribution = petab.C.NORMAL

observable_transformation = observable_row.get(
petab.C.OBSERVABLE_TRANSFORMATION, petab.C.LIN
)
# observableTransformation=log -> the log of the simulated value is
# distributed according to `noise_distribution`
if observable_transformation == petab.C.LOG:
simulated_value = np.log(simulated_value)
elif observable_transformation == petab.C.LOG10:
simulated_value = np.log10(simulated_value)

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

if observable_transformation == petab.C.LOG:
simulated_value_with_noise = np.exp(simulated_value_with_noise)
elif observable_transformation == petab.C.LOG10:
simulated_value_with_noise = np.power(10, simulated_value_with_noise)

if zero_bounded and np.sign(simulated_value) != np.sign(
simulated_value_with_noise
):
Expand Down
Loading