Skip to content

Commit 6420d67

Browse files
committed
once more
1 parent e25785f commit 6420d67

File tree

7 files changed

+436
-365
lines changed

7 files changed

+436
-365
lines changed

doc/example/distributions.ipynb

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,34 @@
3232
"import seaborn as sns\n",
3333
"\n",
3434
"from petab.v1.C import *\n",
35-
"from petab.v1.distributions import *\n",
35+
"from petab.v1.priors import Prior\n",
3636
"\n",
3737
"sns.set_style(None)\n",
3838
"\n",
3939
"\n",
40-
"def plot(distr: Distribution, ax=None):\n",
40+
"def plot(prior: Prior, ax=None):\n",
4141
" \"\"\"Visualize a distribution.\"\"\"\n",
4242
" if ax is None:\n",
4343
" fig, ax = plt.subplots()\n",
4444
"\n",
45-
" sample = distr.sample(10000)\n",
45+
" sample = prior.sample(10000)\n",
4646
"\n",
4747
" # pdf\n",
48-
" xmin = min(sample.min(), distr.lb_scaled if distr.bounds is not None else sample.min())\n",
49-
" xmax = max(sample.max(), distr.ub_scaled if distr.bounds is not None else sample.max())\n",
48+
" xmin = min(sample.min(), prior.lb_scaled if prior.bounds is not None else sample.min())\n",
49+
" xmax = max(sample.max(), prior.ub_scaled if prior.bounds is not None else sample.max())\n",
5050
" x = np.linspace(xmin, xmax, 500)\n",
51-
" y = distr.pdf(x)\n",
51+
" y = prior.pdf(x)\n",
5252
" ax.plot(x, y, color='red', label='pdf')\n",
5353
"\n",
5454
" sns.histplot(sample, stat='density', ax=ax, label=\"sample\")\n",
5555
"\n",
5656
" # bounds\n",
57-
" if distr.bounds is not None:\n",
58-
" for bound in (distr.lb_scaled, distr.ub_scaled):\n",
57+
" if prior.bounds is not None:\n",
58+
" for bound in (prior.lb_scaled, prior.ub_scaled):\n",
5959
" if bound is not None and np.isfinite(bound):\n",
6060
" ax.axvline(bound, color='black', linestyle='--', label='bound')\n",
6161
"\n",
62-
" ax.set_title(str(distr))\n",
62+
" ax.set_title(str(prior))\n",
6363
" ax.set_xlabel('Parameter value on the parameter scale')\n",
6464
" ax.grid(False)\n",
6565
" handles, labels = ax.get_legend_handles_labels()\n",
@@ -81,11 +81,11 @@
8181
"metadata": {},
8282
"cell_type": "code",
8383
"source": [
84-
"plot(Uniform(0, 1))\n",
85-
"plot(Normal(0, 1))\n",
86-
"plot(Laplace(0, 1))\n",
87-
"plot(LogNormal(0, 1))\n",
88-
"plot(LogLaplace(1, 0.5))"
84+
"plot(Prior(UNIFORM, (0, 1)))\n",
85+
"plot(Prior(NORMAL, (0, 1)))\n",
86+
"plot(Prior(LAPLACE, (0, 1)))\n",
87+
"plot(Prior(LOG_NORMAL, (0, 1)))\n",
88+
"plot(Prior(LOG_LAPLACE, (1, 0.5)))"
8989
],
9090
"id": "4f09e50a3db06d9f",
9191
"outputs": [],
@@ -101,10 +101,11 @@
101101
"metadata": {},
102102
"cell_type": "code",
103103
"source": [
104-
"plot(Normal(10, 2, transformation=LIN))\n",
105-
"plot(Normal(10, 2, transformation=LOG))\n",
104+
"plot(Prior(NORMAL, (10, 2), transformation=LIN))\n",
105+
"plot(Prior(NORMAL, (10, 2), transformation=LOG))\n",
106+
"\n",
106107
"# Note that the log-normal distribution is different from a log-transformed normal distribution:\n",
107-
"plot(LogNormal(10, 2, transformation=LIN))"
108+
"plot(Prior(LOG_NORMAL, (10, 2), transformation=LIN))"
108109
],
109110
"id": "f6192c226f179ef9",
110111
"outputs": [],
@@ -120,8 +121,8 @@
120121
"metadata": {},
121122
"cell_type": "code",
122123
"source": [
123-
"plot(LogNormal(10, 2, transformation=LOG))\n",
124-
"plot(ParameterScaleNormal(10, 2))"
124+
"plot(Prior(LOG_NORMAL, (10, 2), transformation=LOG))\n",
125+
"plot(Prior(PARAMETER_SCALE_NORMAL, (10, 2)))"
125126
],
126127
"id": "34c95268e8921070",
127128
"outputs": [],
@@ -137,11 +138,11 @@
137138
"metadata": {},
138139
"cell_type": "code",
139140
"source": [
140-
"plot(Uniform(0, 1, transformation=LOG10))\n",
141-
"plot(ParameterScaleUniform(0, 1, transformation=LOG10))\n",
141+
"plot(Prior(UNIFORM, (0.01, 2), transformation=LOG10))\n",
142+
"plot(Prior(PARAMETER_SCALE_UNIFORM, (0.01, 2), transformation=LOG10))\n",
142143
"\n",
143-
"plot(Uniform(0, 1, transformation=LIN))\n",
144-
"plot(ParameterScaleUniform(0, 1, transformation=LIN))\n"
144+
"plot(Prior(UNIFORM, (0.01, 2), transformation=LIN))\n",
145+
"plot(Prior(PARAMETER_SCALE_UNIFORM, (0.01, 2), transformation=LIN))\n"
145146
],
146147
"id": "5ca940bc24312fc6",
147148
"outputs": [],
@@ -157,8 +158,8 @@
157158
"metadata": {},
158159
"cell_type": "code",
159160
"source": [
160-
"plot(Normal(0, 1, bounds=(-4, 4))) # negligible clipping-bias at 4 sigma\n",
161-
"plot(Uniform(0, 1, bounds=(0.1, 0.9))) # significant clipping-bias"
161+
"plot(Prior(NORMAL, (0, 1), bounds=(-4, 4))) # negligible clipping-bias at 4 sigma\n",
162+
"plot(Prior(UNIFORM, (0, 1), bounds=(0.1, 0.9))) # significant clipping-bias"
162163
],
163164
"id": "4ac42b1eed759bdd",
164165
"outputs": [],
@@ -174,8 +175,10 @@
174175
"metadata": {},
175176
"cell_type": "code",
176177
"source": [
177-
"plot(Normal(10, 1, bounds=(6, 14), transformation=\"log10\"))\n",
178-
"plot(ParameterScaleNormal(10, 1, bounds=(10**6, 10**14), transformation=\"log10\"))\n"
178+
"plot(Prior(NORMAL, (10, 1), bounds=(6, 14), transformation=\"log10\"))\n",
179+
"plot(Prior(PARAMETER_SCALE_NORMAL, (10, 1), bounds=(10**6, 10**14), transformation=\"log10\"))\n",
180+
"plot(Prior(LAPLACE, (10, 2), bounds=(6, 14)))\n",
181+
"\n"
179182
],
180183
"id": "581e1ac431860419",
181184
"outputs": [],
@@ -185,7 +188,7 @@
185188
"metadata": {},
186189
"cell_type": "code",
187190
"source": "",
188-
"id": "802a64be56a6c94f",
191+
"id": "633733651bbc3ef0",
189192
"outputs": [],
190193
"execution_count": null
191194
}

petab/v1/C.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@
173173
LOG10 = "log10"
174174
#: Supported observable transformations
175175
OBSERVABLE_TRANSFORMATIONS = [LIN, LOG, LOG10]
176-
176+
#: Supported parameter transformations
177+
PARAMETER_SCALES = [LIN, LOG, LOG10]
177178

178179
# NOISE MODELS
179180

0 commit comments

Comments
 (0)