Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion petabtests/cases/v2.0.0/sbml/0024/0024.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@

case = PetabV2TestCase.from_problem(
id=24,
brief="Prior distributions.",
brief="Truncated prior distributions.",
description=DESCRIPTION,
model=sbml_file,
problem=problem,
Expand Down
94 changes: 94 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0025/0025.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
from inspect import cleandoc
from numpy import inf

from petab.v2.C import *
from petab.v2 import Problem
from petabtests import (
PetabV2TestCase,
antimony_to_sbml_str,
)
from pathlib import Path
from petab.v2 import PriorDistribution

DESCRIPTION = cleandoc(r"""
## Objective

This case tests different non-truncated prior distributions, as well as
implicit uniform priors and fixed parameters.

## Model

A simple model with all constant parameters.
""")

# problem --------------------------------------------------------------------

priors = [
(PriorDistribution.UNIFORM, (2, 8), 2, 8),
(PriorDistribution.NORMAL, (4, 2), -inf, inf),
(PriorDistribution.LOG_NORMAL, (5, 2), 0.0, inf),
(PriorDistribution.CAUCHY, (3, 5), -inf, inf),
(PriorDistribution.CHI_SQUARED, (4), 0.0, inf),
(PriorDistribution.EXPONENTIAL, (3), 0.0, inf),
(PriorDistribution.GAMMA, (3, 5), 0, inf),
(PriorDistribution.LAPLACE, (3, 5), -inf, inf),
(PriorDistribution.LOG_LAPLACE, (3, 5), 0, inf),
(PriorDistribution.LOG_UNIFORM, (3, 5), 3, 5),
(PriorDistribution.RAYLEIGH, (3), 0, inf),
]

tested_prior_distrs = {pd for pd, _, _, _ in priors}
untested_distrs = [
pd.value for pd in PriorDistribution if pd not in tested_prior_distrs
]
if untested_distrs:
print("Untested prior distributions:", untested_distrs)

sbml_file = Path(__file__).parent / "_model.xml"

parameters = "\n".join(
f"p_{prior_type.value.replace('-', '_')} = 5;" for prior_type, _, _, _ in priors
)
ant_model = f"""
model petab_test_0025
{parameters}
end
"""
sbml_file.write_text(antimony_to_sbml_str(ant_model))

problem = Problem()
for prior_type, prior_pars, support_lb, support_ub in priors:
problem.add_parameter(
f"p_{prior_type.value.replace('-', '_')}",
estimate=True,
lb=support_lb,
ub=support_ub,
nominal_value=5,
prior_distribution=prior_type,
prior_parameters=prior_pars,
)
# implicit uniform prior
problem.add_parameter("p1", estimate=True, nominal_value=1, lb=0, ub=2)
# fixed, i.e., no prior
problem.add_parameter("p_fixed", estimate=False, nominal_value=1)
# we need some observable and measurement
problem.add_observable("obs_p1", "p1", noise_formula="p_fixed")
problem.add_measurement("obs_p1", experiment_id="", time=0, measurement=1)

# solutions ------------------------------------------------------------------

simulation_df = problem.measurement_df.copy(deep=True).rename(
columns={MEASUREMENT: SIMULATION}
)
simulation_df[SIMULATION] = [
1,
]

case = PetabV2TestCase.from_problem(
id=25,
brief="Non-truncated prior distributions.",
description=DESCRIPTION,
model=sbml_file,
problem=problem,
simulation_df=simulation_df,
)
10 changes: 10 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0025/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# PEtab test case 0025

## Objective

This case tests different non-truncated prior distributions, as well as
implicit uniform priors and fixed parameters.

## Model

A simple model with all constant parameters.
13 changes: 13 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0025/_0025.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
condition_files: []
experiment_files: []
format_version: 2.0.0
measurement_files:
- _measurements.tsv
model_files:
model_0:
language: sbml
location: _model.xml
observable_files:
- _observables.tsv
parameter_files:
- _parameters.tsv
23 changes: 23 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0025/_0025_solution.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
chi2: 0.0
llh: -0.91893853320467
log_prior:
p1: -0.69314718055995
p_cauchy: -2.90258780340177
p_chisquare: -2.27685644868579
p_exponential: -2.76527895533478
p_gamma: -3.30258509299405
p_laplace: -2.70258509299405
p_log_laplace: -4.19013542294133
p_log_normal: -4.65851253490362
p_log_uniform: -0.93771092034198
p_normal: -1.73708571376462
p_rayleigh: -1.97667555379101
p_uniform: -1.79175946922805
simulation_files:
- _simulations.tsv
tol_chi2: 0.001
tol_llh: 0.001
tol_log_prior: 1.0e-14
tol_simulations: 0.001
tol_unnorm_log_posterior: 0.001
unnorm_log_posterior: -30.85385872214566
2 changes: 2 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0025/_measurements.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
modelId observableId experimentId time measurement observableParameters noiseParameters
obs_p1 0.0 1.0
19 changes: 19 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0025/_model.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created by libAntimony version v3.1.1 with libSBML version 5.20.5. -->
<sbml xmlns="http://www.sbml.org/sbml/level3/version2/core" level="3" version="2">
<model metaid="petab_test_0025" id="petab_test_0025">
<listOfParameters>
<parameter id="p_uniform" value="5" constant="true"/>
<parameter id="p_normal" value="5" constant="true"/>
<parameter id="p_log_normal" value="5" constant="true"/>
<parameter id="p_cauchy" value="5" constant="true"/>
<parameter id="p_chisquare" value="5" constant="true"/>
<parameter id="p_exponential" value="5" constant="true"/>
<parameter id="p_gamma" value="5" constant="true"/>
<parameter id="p_laplace" value="5" constant="true"/>
<parameter id="p_log_laplace" value="5" constant="true"/>
<parameter id="p_log_uniform" value="5" constant="true"/>
<parameter id="p_rayleigh" value="5" constant="true"/>
</listOfParameters>
</model>
</sbml>
2 changes: 2 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0025/_observables.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
observableId observableName observableFormula noiseFormula noiseDistribution observablePlaceholders noisePlaceholders
obs_p1 p1 p_fixed normal
14 changes: 14 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0025/_parameters.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
parameterId lowerBound upperBound nominalValue estimate priorDistribution priorParameters
p_uniform 2.0 8.0 5.0 true uniform 2.0;8.0
p_normal -inf inf 5.0 true normal 4.0;2.0
p_log_normal 0.0 inf 5.0 true log-normal 5.0;2.0
p_cauchy -inf inf 5.0 true cauchy 3.0;5.0
p_chisquare 0.0 inf 5.0 true chisquare 4.0
p_exponential 0.0 inf 5.0 true exponential 3.0
p_gamma 0.0 inf 5.0 true gamma 3.0;5.0
p_laplace -inf inf 5.0 true laplace 3.0;5.0
p_log_laplace 0.0 inf 5.0 true log-laplace 3.0;5.0
p_log_uniform 3.0 5.0 5.0 true log-uniform 3.0;5.0
p_rayleigh 0.0 inf 5.0 true rayleigh 3.0
p1 0.0 2.0 1.0 true
p_fixed 1.0 false
2 changes: 2 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0025/_simulations.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
modelId observableId experimentId time simulation observableParameters noiseParameters
obs_p1 0.0 1
6 changes: 5 additions & 1 deletion petabtests/cases/v2.0.0/sbml/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,9 @@ Events during steady-state simulations.

# [0024](0024/)

Prior distributions.
Truncated prior distributions.

# [0025](0025/)

Non-truncated prior distributions.