Skip to content

Commit

Permalink
Merge develop into main for new release 0.12.14. (#617)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people committed Nov 10, 2023
1 parent 558d5e4 commit 16bdee9
Show file tree
Hide file tree
Showing 18 changed files with 2,108 additions and 361 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

repos:
- repo: https://github.com/psf/black
rev: 23.1.0
rev: 23.7.0
hooks:
- id: black
description: The uncompromising code formatter
Expand All @@ -27,7 +27,7 @@ repos:
name: isort (pyi)
types: [pyi]
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.6.1
rev: 1.7.0
hooks:
- id: nbqa-black
- id: nbqa-pyupgrade
Expand Down
81 changes: 81 additions & 0 deletions pyabc/external/base.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import copy
import logging
import os
import subprocess # noqa: S404
import tempfile
from typing import List

import numpy as np
import pandas as pd

from ..model import Model
from ..parameters import Parameter
from .utils import timethis

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

Expand Down Expand Up @@ -242,6 +245,84 @@ def __call__(self, pars: Parameter):
def sample(self, pars):
return self(pars)

@timethis
def sample_timing(self, pars):
return self(pars)

def eval_param_limits(self, limits):
"""
evaluate single parameter's boundary value on computation time.
Parameters
----------
limits: dict
the lower and upper boundary values of parameters. The key would
be the parameter name and the value would be a list of the lower
and upper limit of parameter value, e.g., [lower, upper].
Returns
-------
time_eval_dict: dict
a dictionary that contains the parameter names as key and a list
as a value. The list contains the computation time when using
lower and upper limits, e.g., [lower, upper].
"""
time_eval_dict = {}
for key, val in limits.items():
lower_bound = self.sample_timing({key: val[0]})
upper_bound = self.sample_timing({key: val[1]})
time_eval_dict[key] = [lower_bound, upper_bound]
return time_eval_dict

def eval_param_limits_matrix(self, limits):
"""
evaluate two paramters' boundary values on computation time.
Parameters
----------
limits: dict
the lower and upper boundary values of parameters. The key would
be the parameter name and the value would be a list of the lower
and upper limit of parameter value, e.g., [lower, upper].
Returns
-------
time_eval_mat_df_lower: df
a dataframe for the computation time measured when using the lower
limit value of parameters.
time_eval_mat_df_upper: df
a dataframe for the computation time measured when using the upper
limit value of parameters.
"""
time_eval_mat = np.zeros(shape=(len(limits), len(limits)))
time_eval_mat_df_lower = pd.DataFrame(
time_eval_mat,
columns=[list(limits.keys())],
index=[list(limits.keys())],
)
time_eval_mat_df_upper = copy.deepcopy(time_eval_mat_df_lower)
for i, (key_col, val_col) in enumerate(limits.items(), 0):
for j, (key_row, val_row) in enumerate(limits.items(), 0):
if i < j:
time_eval_mat_df_lower.loc[[key_col], [key_row]] = 0
time_eval_mat_df_upper.loc[[key_col], [key_row]] = 0

if key_col == key_row:
lower_bound = self.sample_timing({key_col: val_col[0]})
upper_bound = self.sample_timing({key_col: val_col[1]})

else:
lower_bound = self.sample_timing(
{key_col: val_col[0], key_row: val_row[0]}
)
lower_bound = self.sample_timing(
{key_col: val_col[1], key_row: val_row[1]}
)
time_eval_mat_df_lower.loc[[key_col], [key_row]] = lower_bound
time_eval_mat_df_upper.loc[[key_col], [key_row]] = upper_bound

return time_eval_mat_df_lower, time_eval_mat_df_upper


class ExternalSumStat:
"""
Expand Down
13 changes: 13 additions & 0 deletions pyabc/external/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import time
from functools import wraps


def timethis(func):
@wraps(func)
def wrapper(*args, **kwargs):
start = time.time()
func(*args, **kwargs)
end = time.time()
return end - start

return wrapper
2 changes: 1 addition & 1 deletion pyabc/transition/jump.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,4 @@ def pdf(
]
)

return pds if pds.size != 1 else float(pds)
return pds if pds.size != 1 else float(pds[0])
33 changes: 29 additions & 4 deletions pyabc/visualization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@
plot_contour_matrix,
plot_contour_matrix_lowlevel,
)
from .credible import plot_credible_intervals, plot_credible_intervals_for_time
from .credible import (
plot_credible_intervals,
plot_credible_intervals_for_time,
plot_credible_intervals_plotly,
)
from .data import plot_data_callback, plot_data_default
from .distance import plot_distance_weights
from .effective_sample_size import plot_effective_sample_sizes
from .epsilon import plot_epsilons
from .effective_sample_size import (
plot_effective_sample_sizes,
plot_effective_sample_sizes_plotly,
)
from .epsilon import plot_epsilons, plot_epsilons_plotly
from .histogram import (
plot_histogram_1d,
plot_histogram_1d_lowlevel,
Expand All @@ -29,26 +36,44 @@
from .kde import (
plot_kde_1d,
plot_kde_1d_highlevel,
plot_kde_1d_highlevel_plotly,
plot_kde_1d_plotly,
plot_kde_2d,
plot_kde_2d_highlevel,
plot_kde_2d_highlevel_plotly,
plot_kde_2d_plotly,
plot_kde_matrix,
plot_kde_matrix_highlevel,
plot_kde_matrix_highlevel_plotly,
plot_kde_matrix_plotly,
)
from .model_probabilities import (
plot_model_probabilities,
plot_model_probabilities_plotly,
)
from .model_probabilities import plot_model_probabilities
from .sample import (
plot_acceptance_rates_trajectory,
plot_acceptance_rates_trajectory_plotly,
plot_lookahead_acceptance_rates,
plot_lookahead_evaluations,
plot_lookahead_final_acceptance_fractions,
plot_sample_numbers,
plot_sample_numbers_plotly,
plot_sample_numbers_trajectory,
plot_sample_numbers_trajectory_plotly,
plot_total_sample_numbers,
plot_total_sample_numbers_plotly,
)
from .sankey import plot_sensitivity_sankey
from .walltime import (
plot_eps_walltime,
plot_eps_walltime_lowlevel,
plot_eps_walltime_lowlevel_plotly,
plot_eps_walltime_plotly,
plot_total_walltime,
plot_total_walltime_plotly,
plot_walltime,
plot_walltime_lowlevel,
plot_walltime_lowlevel_plotly,
plot_walltime_plotly,
)
Loading

0 comments on commit 16bdee9

Please sign in to comment.