Skip to content

Commit 71ee881

Browse files
stephanmgyannikschaelteEmadAlamoudi
committed
Merge develop into main for new release 0.12.14. (#617)
* Fix assets for pyabc visserver. * Update R. * Fix for logo path in abc-server-dash * Preparing release notes for next patch release. * Updating about.rst. * Updating changelog. * Create plotly versions of selected matplotlib visualizations (#610) * Create ploty versions of selected matplotlib visualizations * update r install instructions * fix pandas float deprecation warnings * fixarray ndim > 0 float extraction deprecationwarning --------- Co-authored-by: Stephan Grein <[email protected]> * add the functionality to evaluate the model using boundry values of p… (#355) * add the functionality to evaluate the model using boundry values of parameter * fix flake8 issues * fix additional flake8 issues * add test case * flake8 fixes * flake8 fixes * flake8 fixes * flake8 fixes * flake8 fixes * black fixes * Update test_external.py Use correct comparison operator. --------- Co-authored-by: Yannik Schälte <[email protected]> Co-authored-by: Stephan Grein <[email protected]> Co-authored-by: Stephan Grein <[email protected]> --------- Co-authored-by: Yannik Schälte <[email protected]> Co-authored-by: Emad Alamoudi <[email protected]>
1 parent 558d5e4 commit 71ee881

File tree

18 files changed

+2108
-361
lines changed

18 files changed

+2108
-361
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
repos:
1313
- repo: https://github.com/psf/black
14-
rev: 23.1.0
14+
rev: 23.7.0
1515
hooks:
1616
- id: black
1717
description: The uncompromising code formatter
@@ -27,7 +27,7 @@ repos:
2727
name: isort (pyi)
2828
types: [pyi]
2929
- repo: https://github.com/nbQA-dev/nbQA
30-
rev: 1.6.1
30+
rev: 1.7.0
3131
hooks:
3232
- id: nbqa-black
3333
- id: nbqa-pyupgrade

pyabc/external/base.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
import copy
12
import logging
23
import os
34
import subprocess # noqa: S404
45
import tempfile
56
from typing import List
67

78
import numpy as np
9+
import pandas as pd
810

911
from ..model import Model
1012
from ..parameters import Parameter
13+
from .utils import timethis
1114

1215
logger = logging.getLogger("ABC.External")
1316

@@ -242,6 +245,84 @@ def __call__(self, pars: Parameter):
242245
def sample(self, pars):
243246
return self(pars)
244247

248+
@timethis
249+
def sample_timing(self, pars):
250+
return self(pars)
251+
252+
def eval_param_limits(self, limits):
253+
"""
254+
evaluate single parameter's boundary value on computation time.
255+
256+
Parameters
257+
----------
258+
limits: dict
259+
the lower and upper boundary values of parameters. The key would
260+
be the parameter name and the value would be a list of the lower
261+
and upper limit of parameter value, e.g., [lower, upper].
262+
263+
Returns
264+
-------
265+
time_eval_dict: dict
266+
a dictionary that contains the parameter names as key and a list
267+
as a value. The list contains the computation time when using
268+
lower and upper limits, e.g., [lower, upper].
269+
"""
270+
time_eval_dict = {}
271+
for key, val in limits.items():
272+
lower_bound = self.sample_timing({key: val[0]})
273+
upper_bound = self.sample_timing({key: val[1]})
274+
time_eval_dict[key] = [lower_bound, upper_bound]
275+
return time_eval_dict
276+
277+
def eval_param_limits_matrix(self, limits):
278+
"""
279+
evaluate two paramters' boundary values on computation time.
280+
281+
Parameters
282+
----------
283+
limits: dict
284+
the lower and upper boundary values of parameters. The key would
285+
be the parameter name and the value would be a list of the lower
286+
and upper limit of parameter value, e.g., [lower, upper].
287+
288+
Returns
289+
-------
290+
time_eval_mat_df_lower: df
291+
a dataframe for the computation time measured when using the lower
292+
limit value of parameters.
293+
time_eval_mat_df_upper: df
294+
a dataframe for the computation time measured when using the upper
295+
limit value of parameters.
296+
"""
297+
time_eval_mat = np.zeros(shape=(len(limits), len(limits)))
298+
time_eval_mat_df_lower = pd.DataFrame(
299+
time_eval_mat,
300+
columns=[list(limits.keys())],
301+
index=[list(limits.keys())],
302+
)
303+
time_eval_mat_df_upper = copy.deepcopy(time_eval_mat_df_lower)
304+
for i, (key_col, val_col) in enumerate(limits.items(), 0):
305+
for j, (key_row, val_row) in enumerate(limits.items(), 0):
306+
if i < j:
307+
time_eval_mat_df_lower.loc[[key_col], [key_row]] = 0
308+
time_eval_mat_df_upper.loc[[key_col], [key_row]] = 0
309+
310+
if key_col == key_row:
311+
lower_bound = self.sample_timing({key_col: val_col[0]})
312+
upper_bound = self.sample_timing({key_col: val_col[1]})
313+
314+
else:
315+
lower_bound = self.sample_timing(
316+
{key_col: val_col[0], key_row: val_row[0]}
317+
)
318+
lower_bound = self.sample_timing(
319+
{key_col: val_col[1], key_row: val_row[1]}
320+
)
321+
time_eval_mat_df_lower.loc[[key_col], [key_row]] = lower_bound
322+
time_eval_mat_df_upper.loc[[key_col], [key_row]] = upper_bound
323+
324+
return time_eval_mat_df_lower, time_eval_mat_df_upper
325+
245326

246327
class ExternalSumStat:
247328
"""

pyabc/external/utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import time
2+
from functools import wraps
3+
4+
5+
def timethis(func):
6+
@wraps(func)
7+
def wrapper(*args, **kwargs):
8+
start = time.time()
9+
func(*args, **kwargs)
10+
end = time.time()
11+
return end - start
12+
13+
return wrapper

pyabc/transition/jump.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,4 @@ def pdf(
142142
]
143143
)
144144

145-
return pds if pds.size != 1 else float(pds)
145+
return pds if pds.size != 1 else float(pds[0])

pyabc/visualization/__init__.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,18 @@
1313
plot_contour_matrix,
1414
plot_contour_matrix_lowlevel,
1515
)
16-
from .credible import plot_credible_intervals, plot_credible_intervals_for_time
16+
from .credible import (
17+
plot_credible_intervals,
18+
plot_credible_intervals_for_time,
19+
plot_credible_intervals_plotly,
20+
)
1721
from .data import plot_data_callback, plot_data_default
1822
from .distance import plot_distance_weights
19-
from .effective_sample_size import plot_effective_sample_sizes
20-
from .epsilon import plot_epsilons
23+
from .effective_sample_size import (
24+
plot_effective_sample_sizes,
25+
plot_effective_sample_sizes_plotly,
26+
)
27+
from .epsilon import plot_epsilons, plot_epsilons_plotly
2128
from .histogram import (
2229
plot_histogram_1d,
2330
plot_histogram_1d_lowlevel,
@@ -29,26 +36,44 @@
2936
from .kde import (
3037
plot_kde_1d,
3138
plot_kde_1d_highlevel,
39+
plot_kde_1d_highlevel_plotly,
40+
plot_kde_1d_plotly,
3241
plot_kde_2d,
3342
plot_kde_2d_highlevel,
43+
plot_kde_2d_highlevel_plotly,
44+
plot_kde_2d_plotly,
3445
plot_kde_matrix,
3546
plot_kde_matrix_highlevel,
47+
plot_kde_matrix_highlevel_plotly,
48+
plot_kde_matrix_plotly,
49+
)
50+
from .model_probabilities import (
51+
plot_model_probabilities,
52+
plot_model_probabilities_plotly,
3653
)
37-
from .model_probabilities import plot_model_probabilities
3854
from .sample import (
3955
plot_acceptance_rates_trajectory,
56+
plot_acceptance_rates_trajectory_plotly,
4057
plot_lookahead_acceptance_rates,
4158
plot_lookahead_evaluations,
4259
plot_lookahead_final_acceptance_fractions,
4360
plot_sample_numbers,
61+
plot_sample_numbers_plotly,
4462
plot_sample_numbers_trajectory,
63+
plot_sample_numbers_trajectory_plotly,
4564
plot_total_sample_numbers,
65+
plot_total_sample_numbers_plotly,
4666
)
4767
from .sankey import plot_sensitivity_sankey
4868
from .walltime import (
4969
plot_eps_walltime,
5070
plot_eps_walltime_lowlevel,
71+
plot_eps_walltime_lowlevel_plotly,
72+
plot_eps_walltime_plotly,
5173
plot_total_walltime,
74+
plot_total_walltime_plotly,
5275
plot_walltime,
5376
plot_walltime_lowlevel,
77+
plot_walltime_lowlevel_plotly,
78+
plot_walltime_plotly,
5479
)

0 commit comments

Comments
 (0)