In [2]:
import os, tempfile
import logging
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
In [3]:
from ionchannelABC import theoretical_population_size
from ionchannelABC import IonChannelDistance, EfficientMultivariateNormalTransition, IonChannelAcceptor
from ionchannelABC.experiment import setup
from ionchannelABC.visualization import plot_sim_results, plot_kde_matrix_custom
import myokit
In [4]:
from pyabc import Distribution, RV, History, ABCSMC
from pyabc.epsilon import MedianEpsilon
from pyabc.sampler import MulticoreEvalParallelSampler, SingleCoreSampler
from pyabc.populationstrategy import ConstantPopulationSize
Load experiments used for unified dataset calibration:
In [5]:
from experiments.ina_sakakibara import (sakakibara_act,
sakakibara_inact,
sakakibara_inact_kin,
sakakibara_rec)
from experiments.ina_schneider import schneider_taum
In [6]:
modelfile = 'models/standardised_ina.mmt'
Combine model and experiments to produce:
In [19]:
observations, model, summary_statistics = setup(modelfile,
sakakibara_act,
sakakibara_inact,
schneider_taum,
sakakibara_inact_kin,
sakakibara_rec)
In [20]:
assert len(observations)==len(summary_statistics(model({})))
In [21]:
g = plot_sim_results(modelfile,
sakakibara_act,
schneider_taum,
sakakibara_inact,
sakakibara_inact_kin,
sakakibara_rec)
In [22]:
limits = {'log_ina.A': (0., 1.),
'log_ina.p_1': (1., 5.),
'ina.p_2': (1e-7, 0.2),
'log_ina.p_3': (-3., 1.),
'ina.p_4': (1e-7, 0.4),
'log_ina.p_5': (-1., 3.),
'ina.p_6': (1e-7, 0.2),
'log_ina.p_7': (-4., 0.),
'ina.p_8': (1e-7, 0.2)}
prior = Distribution(**{key: RV("uniform", a, b - a)
for key, (a,b) in limits.items()})
In [23]:
# Test this works correctly with set-up functions
assert len(observations) == len(summary_statistics(model(prior.rvs())))
In [10]:
db_path = ("sqlite:///" + os.path.join(tempfile.gettempdir(), "standardised_ina_unified.db"))
In [34]:
logging.basicConfig()
abc_logger = logging.getLogger('ABC')
abc_logger.setLevel(logging.DEBUG)
eps_logger = logging.getLogger('Epsilon')
eps_logger.setLevel(logging.DEBUG)
In [35]:
pop_size = theoretical_population_size(2, len(limits))
print("Theoretical minimum population size is {} particles".format(pop_size))
In [36]:
abc = ABCSMC(models=model,
parameter_priors=prior,
distance_function=IonChannelDistance(
exp_id=list(observations.exp_id),
variance=list(observations.variance),
delta=0.05),
population_size=ConstantPopulationSize(1000),
summary_statistics=summary_statistics,
transitions=EfficientMultivariateNormalTransition(),
eps=MedianEpsilon(initial_epsilon=100),
sampler=MulticoreEvalParallelSampler(n_procs=8),
acceptor=IonChannelAcceptor())
In [37]:
obs = observations.to_dict()['y']
obs = {str(k): v for k, v in obs.items()}
In [38]:
abc_id = abc.new(db_path, obs)
In [ ]:
history = abc.run(minimum_epsilon=0., max_nr_populations=100, min_acceptance_rate=0.01)
In [ ]:
history = abc.run(minimum_epsilon=0., max_nr_populations=100, min_acceptance_rate=0.01)
In [27]:
history = History('sqlite:///results/standardised/ina/standardised_ina_unified.db')
In [29]:
history.all_runs() # most recent is relevant
Out[29]:
In [30]:
df, w = history.get_distribution( m=0)
In [31]:
df.describe()
Out[31]:
In [32]:
sns.set_context('poster')
mpl.rcParams['font.size'] = 14
mpl.rcParams['legend.fontsize'] = 14
g = plot_sim_results(modelfile,
sakakibara_act,
schneider_taum,
sakakibara_inact,
sakakibara_inact_kin,
sakakibara_rec,
df=df, w=w)
plt.tight_layout()
In [33]:
m,_,_ = myokit.load(modelfile)
In [36]:
sns.set_context('paper')
g = plot_kde_matrix_custom(df, w, limits=limits)
plt.tight_layout()
In [ ]: