Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stochastic Acceptance Step #197

Merged
merged 255 commits into from
Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
255 commits
Select commit Hold shift + click to select a range
1901566
Merge branch 'master' into feature_noisyacceptor
yannikschaelte May 30, 2018
bab1fe7
Merge branch 'master' into feature_noisyacceptor
yannikschaelte May 30, 2018
e4a4507
Merge branch 'feature_centereddistance' into feature_noisyacceptor
yannikschaelte May 30, 2018
afa58db
improve stochastic acceptor
yannikschaelte Jun 1, 2018
7a3384d
tidy up __init__.py
yannikschaelte Jun 1, 2018
211071a
update version
yannikschaelte Jun 1, 2018
9fba34a
NoEpsilon return nan, StochasticAcceptor updates
yannikschaelte Jun 1, 2018
4f5c935
Merge branch 'feature_centereddistance' into feature_noisyacceptor
yannikschaelte Jun 2, 2018
7e49422
improve doc for viz, fix flake8
yannikschaelte Jun 2, 2018
e998a3d
Merge branch 'feature_viztruevalues' into feature_noisyacceptor
yannikschaelte Jun 2, 2018
2bb7a57
fix merge errors
yannikschaelte Jun 2, 2018
f84d1d5
Merge branch 'feature_viztruevalues' into feature_noisyacceptor
yannikschaelte Jun 2, 2018
5548941
Merge branch 'feature_centereddistance' into feature_noisyacceptor
yannikschaelte Jun 7, 2018
c7c8547
Merge branch 'feature_centereddistance' into feature_noisyacceptor
yannikschaelte Jun 7, 2018
1eeb573
rename acceptor variables
yannikschaelte Jun 12, 2018
04e91e1
improve acceptor
yannikschaelte Jun 12, 2018
3b9b2ed
Merge branch 'feature_noisyacceptor' of https://github.com/icb-dcm/py…
yannikschaelte Jun 12, 2018
7198985
remove print
yannikschaelte Jun 12, 2018
9d5b3fc
Merge branch 'feature_centereddistance' into feature_noisyacceptor
yannikschaelte Jun 15, 2018
9f0f150
add combined_mean_absolute_deviation
yannikschaelte Jun 15, 2018
827b6ff
Merge branch 'feature_centereddistance' into feature_noisyacceptor
yannikschaelte Jun 15, 2018
c8ef256
Merge branch 'feature_centereddistance' into feature_noisyacceptor
yannikschaelte Jun 18, 2018
8cdf647
eps: weighted_distances -> data for ss
yannikschaelte Jun 20, 2018
1040e6a
implement history dist+w+ss
yannikschaelte Jun 22, 2018
1eda934
Merge branch 'feature_centereddistance' into feature_noisyacceptor
yannikschaelte Sep 18, 2018
88b2b40
merge kde
yannikschaelte Oct 4, 2018
4abd1fb
Merge branch 'fix_kde' into feature_noisyacceptor
yannikschaelte Oct 4, 2018
2fb308c
Merge branch 'fix_kde' into feature_noisyacceptor
yannikschaelte Oct 4, 2018
d94066e
Merge branch 'fix_kde' into feature_noisyacceptor
yannikschaelte Nov 29, 2018
94edd6c
fix some flake8 errors
yannikschaelte Nov 29, 2018
5fb5451
Merge branch 'master' into feature_noisyacceptor
yannikschaelte Jan 16, 2019
b24f302
Merge branch 'feature_centereddistance' into feature_noisyacceptor
yannikschaelte Jan 17, 2019
fbf55da
Merge branch 'feature_centereddistance' into feature_noisyacceptor
yannikschaelte Jan 17, 2019
6181919
create uniform acceptor
yannikschaelte Jan 17, 2019
9307f89
init test acceptor (still to be extended considerably)
yannikschaelte Jan 17, 2019
9d9b470
fix imports
yannikschaelte Jan 17, 2019
50d9eca
add wilkinson citation to StochasticAcceptor
yannikschaelte Jan 17, 2019
4ac7d66
add acceptance notebook
yannikschaelte Jan 17, 2019
313db7d
add title for distance_functions
yannikschaelte Jan 19, 2019
2a6a616
fix doc errors
yannikschaelte Jan 19, 2019
8a3be3b
move acceptor to pdf
yannikschaelte Jan 19, 2019
8e7f01b
Merge branch 'feature_noisyacceptor' of https://github.com/icb-dcm/py…
yannikschaelte Jan 19, 2019
46dc63a
add __init__ to all api docs per default
yannikschaelte Jan 20, 2019
04588e1
done first version of StochasticAcceptor with good temperature scheme
yannikschaelte Jan 20, 2019
5089ef2
update dist doc
yannikschaelte Jan 20, 2019
ea1a94c
add get_accepted_sum_stats method to Population
yannikschaelte Jan 20, 2019
96b7641
make smc.py fit for acceptor (call update methods, move parts from ne…
yannikschaelte Jan 20, 2019
cd91541
add temp_max fallback
yannikschaelte Jan 20, 2019
25a678d
remove require_initialize flags by passing a function doing the initi…
yannikschaelte Jan 20, 2019
bf4c923
fix flake8
yannikschaelte Jan 20, 2019
fff92bb
add update method to base Acceptor
yannikschaelte Jan 20, 2019
7dd6130
make temp schemes optional
yannikschaelte Jan 21, 2019
97b9bd3
fix typo
yannikschaelte Jan 21, 2019
4bd417d
tmp edit
yannikschaelte Jan 21, 2019
f6cf0d8
fix typo
yannikschaelte Jan 21, 2019
b721615
cont
yannikschaelte Jan 21, 2019
571abe3
compute prior only when necessary in acceptor
yannikschaelte Jan 21, 2019
92385f4
cont
yannikschaelte Jan 21, 2019
42038a2
fix error acceptor -> init self.c
yannikschaelte Jan 21, 2019
b1be312
tidy up
yannikschaelte Jan 21, 2019
1d35fc0
add daly2017 implementation (without backward loop)
yannikschaelte Jan 21, 2019
b8b0804
cont
yannikschaelte Jan 21, 2019
9024ce8
rewrite acceptance scheme passing, some modifications to smc and acce…
yannikschaelte Jan 22, 2019
cd873fa
Merge branch 'feature_centereddistance' into feature_noisyacceptor
yannikschaelte Jan 27, 2019
51ebcc6
Merge branch 'feature_centereddistance' into feature_noisyacceptor
yannikschaelte Jan 27, 2019
fcbb8a0
Merge branch 'feature_centereddistance' into feature_noisyacceptor
yannikschaelte Jan 28, 2019
175f738
history: add default argument to simplify calling in most common cases
yannikschaelte Jan 29, 2019
06bb6e1
remove tmp comment
yannikschaelte Jan 29, 2019
806a58f
remove unused function
yannikschaelte Jan 29, 2019
c746183
history: add default m, t arguments, improve doc
yannikschaelte Jan 29, 2019
ef8f9ad
minor edit
yannikschaelte Jan 29, 2019
e90a952
Merge branch 'feature_savenostats' into feature_noisyacceptor
yannikschaelte Feb 2, 2019
b2ec34b
fix doc merge
yannikschaelte Feb 2, 2019
fa2c781
Merge branch 'feature_recreate_population' into feature_noisyacceptor
yannikschaelte Feb 4, 2019
6a0be08
update version
yannikschaelte Feb 4, 2019
b84076a
create comparator as base of distance function
yannikschaelte Feb 4, 2019
46349a1
add stochastic_kernel
yannikschaelte Feb 4, 2019
84792f3
implement normal kernels and binomial kernel
yannikschaelte Feb 5, 2019
e3bfec7
move functionality from StochasticAcceptor to StochasticKernel
yannikschaelte Feb 5, 2019
14b4b76
add evaluate_sample method
yannikschaelte Feb 5, 2019
77ebdf4
restructure distance_functions -> distance, and fix several minor issues
yannikschaelte Feb 6, 2019
f951e19
acceptor: adapt to distance, fix return pd, not pd_rescaled
yannikschaelte Feb 6, 2019
be9631f
model: adapt to distance
yannikschaelte Feb 6, 2019
98b5aed
smc: make distance optional (default PNormDistance), adapt to distanc…
yannikschaelte Feb 6, 2019
60f49c5
update __init__.py
yannikschaelte Feb 6, 2019
448e744
fix typos
yannikschaelte Feb 6, 2019
a38b457
adapt adaptive_distances.ipynb ("Distance" logging)
yannikschaelte Feb 6, 2019
cfd4702
make pdf_max real attribute, allow to set in __init__s
yannikschaelte Feb 6, 2019
e3564ca
init implement different pdf_max computation schemes
yannikschaelte Feb 6, 2019
8c3ccad
fix typos
yannikschaelte Feb 6, 2019
85ded1a
add check for empty pdf prevs
yannikschaelte Feb 6, 2019
f76f417
max of sth and inf is kind of obvious
yannikschaelte Feb 6, 2019
aecd89e
Merge branch 'feature_recreate_population' into feature_noisyacceptor
yannikschaelte Feb 21, 2019
30b81bb
Update CONTRIBUTING.md
yannikschaelte Feb 21, 2019
d908109
Merge branch 'develop' into feature_noisyacceptor
yannikschaelte Mar 5, 2019
55eedef
allow estimated variances in kernel
yannikschaelte Mar 5, 2019
49114cc
fix minor error
yannikschaelte Mar 5, 2019
b01bfce
Merge branch 'develop' into feature_noisyacceptor
yannikschaelte Mar 21, 2019
eecebe2
fix adaptive pdf max not used
yannikschaelte Mar 21, 2019
98daae6
add debug remark
yannikschaelte Mar 21, 2019
ff57795
Merge branch 'master' into feature_noisyacceptor
yannikschaelte Mar 25, 2019
10a3542
Merge branch 'develop' into feature_noisyacceptor
yannikschaelte Mar 26, 2019
8449594
fix merge remainder
yannikschaelte Mar 26, 2019
a09be55
add test for pre sample number
yannikschaelte Mar 26, 2019
1065f58
fix flake8
yannikschaelte Mar 27, 2019
fbb8286
fix wrong nr of init samples reported
yannikschaelte Mar 27, 2019
4b8403d
at least test for nr_samples > 0 already
yannikschaelte Mar 27, 2019
61395b4
extend test for nr_eval in init back to exact test
yannikschaelte Mar 27, 2019
ae4cc2b
fix eps_mixin reports wrong nr_evaluations
yannikschaelte Mar 27, 2019
175cb87
add all_accepted to all sample_until_n_accepted
yannikschaelte Mar 27, 2019
373f306
use all_accepted=True in calibration
yannikschaelte Mar 27, 2019
c7ede8d
implement reduced dynamic presimulation
yannikschaelte Mar 27, 2019
8346dab
adapt test_samplers
yannikschaelte Mar 27, 2019
c919ded
Merge branch 'develop' into reduce_dyn_pre
yannikschaelte Mar 27, 2019
3a2e023
update releasenotes
yannikschaelte Mar 27, 2019
6e17440
batch sizes start with 1
yannikschaelte Mar 27, 2019
d8f95e9
eps: reset nr_evaluations beforehand. this should really be changed a…
yannikschaelte Mar 27, 2019
5cd9326
Merge branch 'reduce_dyn_pre' into feature_noisyacceptor
yannikschaelte Mar 27, 2019
edb4b3e
fix last time error
yannikschaelte Mar 27, 2019
5da329f
Merge branch 'develop' into feature_noisyacceptor
yannikschaelte Mar 28, 2019
6d586d7
Merge branch 'develop' into feature_noisyacceptor
yannikschaelte Mar 28, 2019
d021b3f
note issues in about.rst
yannikschaelte Mar 28, 2019
c9a50b8
code cleanup
yannikschaelte Mar 28, 2019
f32853d
Merge branch 'feature_stuff' into feature_noisyacceptor
yannikschaelte Mar 28, 2019
7f7521d
Merge branch 'develop' into feature_noisyacceptor
yannikschaelte Mar 29, 2019
98431c5
Update api_sampler.rst
yannikschaelte Mar 29, 2019
d138cf1
Update api_model.rst
yannikschaelte Mar 29, 2019
5e5f598
Update api_transition.rst
yannikschaelte Mar 29, 2019
6783e90
Merge branch 'develop' into feature_noisyacceptor
yannikschaelte Apr 1, 2019
945c400
Merge branch 'develop' into feature_noisyacceptor
yannikschaelte Apr 1, 2019
f49fac9
Merge branch 'develop' into feature_noisyacceptor
yannikschaelte Apr 2, 2019
bc9cf12
fix unused variables and flake8
yannikschaelte Apr 2, 2019
0fc3f96
fix acceptor parameter pass
yannikschaelte Apr 2, 2019
d5a6189
minor edits
yannikschaelte Apr 2, 2019
2e0b41f
create acceptor module since too lengthy
yannikschaelte Apr 2, 2019
00dfb60
fix flake8
yannikschaelte Apr 2, 2019
d443898
minor edits
yannikschaelte Apr 2, 2019
f143237
tidy up distance/kernel
yannikschaelte Apr 3, 2019
f33aff8
log calibration in smc
yannikschaelte Apr 3, 2019
119f6e2
temp schedules: add safety checks, cleanup, docstrings
yannikschaelte Apr 3, 2019
c285371
add ess-based scheme
yannikschaelte Apr 3, 2019
ccf10e9
use weights in ess
yannikschaelte Apr 3, 2019
47d34ee
add fallback in case of increasing temperatures
yannikschaelte Apr 11, 2019
e113d2d
fix flake8
yannikschaelte Apr 11, 2019
82efa4f
for convenience, check keys initialized in stochastic acceptors
yannikschaelte Apr 13, 2019
9632285
use np looping in binomial kernel
yannikschaelte Apr 16, 2019
29bbebf
always report acceptance rate
yannikschaelte Apr 16, 2019
6fc6463
compute maximum binomial kernel
yannikschaelte Apr 17, 2019
0c2e9c6
fix np max -> maximum
yannikschaelte Apr 17, 2019
e3dcb77
fix arguments for compute_binomial max
yannikschaelte Apr 17, 2019
6681b43
add friel_pettitt
yannikschaelte Apr 18, 2019
322b3fc
mv decay -> polynomial_decay, improve docs
yannikschaelte Apr 20, 2019
31b3b9f
create acceptance result
yannikschaelte Apr 27, 2019
27123d3
use acceptance weights correctly
yannikschaelte Apr 27, 2019
914c73d
correct friel_pettitt
yannikschaelte Apr 27, 2019
41d6a7e
Merge branch 'feature_noisyacceptor' of https://github.com/icb-dcm/py…
yannikschaelte Apr 27, 2019
7854bdc
add warning regarding n_samples_per_parameter
yannikschaelte Apr 30, 2019
4d3780e
improve logging
yannikschaelte Apr 30, 2019
28a8687
add safety check for zero weight
yannikschaelte Apr 30, 2019
241c049
add ess to weighted_statistics
yannikschaelte May 1, 2019
83404f1
add docstrings for weighted_statistics to doc
yannikschaelte May 1, 2019
1050b90
add ess visualization
yannikschaelte May 1, 2019
5ad987c
rerun adap-dist and par-inf nbs
yannikschaelte May 1, 2019
9c5063a
fix flake8
yannikschaelte May 1, 2019
16d90e3
Merge branch 'feature_ess' into feature_noisyacceptor
yannikschaelte May 1, 2019
6789664
Merge branch 'feature_noisyacceptor' into feature_noisy_is
yannikschaelte May 1, 2019
10806ee
Add test for ESS
yannikschaelte May 1, 2019
807a9e4
fix adap-dist nb
yannikschaelte May 1, 2019
7744d74
Merge branch 'feature_ess' into feature_noisyacceptor
yannikschaelte May 1, 2019
ec75ff6
Merge branch 'feature_noisyacceptor' into feature_noisy_is
yannikschaelte May 1, 2019
82510df
Merge branch 'develop' into feature_noisyacceptor
yannikschaelte May 2, 2019
84fb7f5
Merge branch 'feature_noisyacceptor' into feature_noisy_is
yannikschaelte May 2, 2019
b231efd
use longer weight output since sometimes little difference from 1.0
yannikschaelte May 2, 2019
75c6220
Merge branch 'feature_noisy_is' of https://github.com/icb-dcm/pyabc i…
yannikschaelte May 2, 2019
8c43bb1
Merge branch 'develop' into feature_noisyacceptor
yannikschaelte May 5, 2019
9761a6f
Merge branch 'feature_noisyacceptor' into feature_noisy_is
yannikschaelte May 5, 2019
b85c896
Merge branch 'develop' into feature_noisyacceptor
yannikschaelte May 5, 2019
b4cd23b
Merge branch 'feature_noisyacceptor' into feature_noisy_is
yannikschaelte May 5, 2019
7efd777
set ModelResult weight default to 1.0
yannikschaelte May 5, 2019
9044298
Merge branch 'develop' into feature_noisyacceptor
yannikschaelte Aug 12, 2019
f73d250
Merge branch 'master' into feature_noisyacceptor
yannikschaelte Aug 12, 2019
a4a157a
Merge branch 'develop' into feature_noisy_is
yannikschaelte Aug 12, 2019
e833244
Merge branch 'master' into feature_noisy_is
yannikschaelte Aug 12, 2019
ca1c955
fix duplicate target variable
yannikschaelte Aug 12, 2019
4b60df1
fix default args, nr rets
yannikschaelte Aug 12, 2019
54bbb63
Merge branch 'feature_noisyacceptor' into feature_noisy_is
yannikschaelte Aug 12, 2019
eac85fb
fix unused variable
yannikschaelte Aug 12, 2019
5d16a8b
Merge pull request #107 from ICB-DCM/feature_noisy_is
yannikschaelte Aug 13, 2019
408d460
add independent laplace kernel
yannikschaelte Aug 15, 2019
7b8e219
improve docs
yannikschaelte Aug 15, 2019
20af385
Merge branch 'develop' into feature_noisyacceptor
yannikschaelte Sep 5, 2019
146a660
init noise nb
yannikschaelte Sep 28, 2019
249535f
fix typos
yannikschaelte Sep 29, 2019
f5ce932
first form of noise nb
yannikschaelte Sep 29, 2019
c84f88a
rerun adaptive_distances with updated distributed package
yannikschaelte Oct 1, 2019
11c1da9
Merge branch 'develop' into feature_noisyacceptor
yannikschaelte Oct 14, 2019
b3eaac5
Merge branch 'develop' into feature_noisyacceptor
yannikschaelte Oct 20, 2019
746ff83
fix flake8
yannikschaelte Oct 20, 2019
35394ad
fix typo
yannikschaelte Oct 20, 2019
3f14701
minor edit
yannikschaelte Oct 20, 2019
e72f8d8
Merge branch 'develop' into feature_noisyacceptor2
yannikschaelte Oct 21, 2019
f550ab2
fix merge errors
yannikschaelte Oct 22, 2019
bccc6f7
Merge branch 'develop' into feature_noisyacceptor2
yannikschaelte Oct 22, 2019
15bded3
Merge branch 'develop' into feature_noisyacceptor2
yannikschaelte Oct 22, 2019
4ba6e9c
Update README.md
yannikschaelte Oct 22, 2019
ccf14a7
Update index.rst
yannikschaelte Oct 22, 2019
1c82bd4
integrate tempyepsy with stochastic acceptor
yannikschaelte Oct 22, 2019
c4af035
Merge branch 'feature_noisyacceptor2' of https://github.com/icb-dcm/p…
yannikschaelte Oct 22, 2019
cd94861
fix flake8
yannikschaelte Oct 23, 2019
b867c90
add temperatures to __init__
yannikschaelte Oct 23, 2019
f704a42
fix typos; add smc._sanity_check
yannikschaelte Oct 23, 2019
503b796
remove unused notebooks
yannikschaelte Oct 23, 2019
9469809
reset adap_dist nb
yannikschaelte Oct 23, 2019
b670710
Merge branch 'develop' into feature_noisyacceptor2
yannikschaelte Oct 23, 2019
742c3ba
fix codacy: parameters in override differ
yannikschaelte Oct 23, 2019
0011cc3
add correct pylint hint
yannikschaelte Oct 23, 2019
47fd4c3
pylint warnings are nasty
yannikschaelte Oct 23, 2019
b155a6c
fix typo
yannikschaelte Oct 23, 2019
3aec68e
extend acceptor+eps documentation
yannikschaelte Oct 23, 2019
1552bb4
fix typos
yannikschaelte Oct 23, 2019
ecb6d5b
add polynomial, friel-pettit, ess temperature schemes
yannikschaelte Oct 23, 2019
a8d3eb0
fix wrong weights in t=0
yannikschaelte Oct 23, 2019
231f4ee
minor edits
yannikschaelte Oct 23, 2019
cb9f9f2
add usage example
yannikschaelte Oct 24, 2019
00f9413
add tests
yannikschaelte Oct 24, 2019
ba4f190
minor editsg
yannikschaelte Oct 30, 2019
d6ca27a
make log kernel default
yannikschaelte Nov 3, 2019
9b6e315
fix multiple errors with distance kernel; in particular handling of v…
yannikschaelte Nov 4, 2019
6927593
add test for implemented kernels
yannikschaelte Nov 4, 2019
1f22b94
add kernels to __init__
yannikschaelte Nov 4, 2019
75ad908
add basic acceptor test
yannikschaelte Nov 4, 2019
bc896aa
Merge branch 'develop' into feature_noisyacceptor2
yannikschaelte Nov 4, 2019
15cbddb
Merge branch 'develop' into feature_noisyacceptor2
yannikschaelte Nov 4, 2019
c186cd7
Merge branch 'develop' into feature_noisyacceptor2
yannikschaelte Nov 4, 2019
345c0df
Merge branch 'develop' into feature_noisyacceptor2
yannikschaelte Nov 4, 2019
08b3438
fix int division error
yannikschaelte Nov 4, 2019
97c57f3
fix int conversion for ess
yannikschaelte Nov 4, 2019
b7bc1d6
add tests for temperature and temperature schemes
yannikschaelte Nov 4, 2019
0cf4e46
tmp remove noise nb
yannikschaelte Nov 4, 2019
4e62f6a
increase coverage of test_population
yannikschaelte Nov 4, 2019
fe70fce
remove obsolete population function
yannikschaelte Nov 4, 2019
b0d174e
add all kernels to __init__
yannikschaelte Nov 4, 2019
aa778b5
remove acceptor.update distance_function arg; address reviewer comments
yannikschaelte Nov 4, 2019
c9e8c61
decompose log of product for num. stability
yannikschaelte Nov 4, 2019
7b7b708
minor edit
yannikschaelte Nov 4, 2019
0939dfc
address reviewer comment
yannikschaelte Nov 4, 2019
652a9e1
correct version
yannikschaelte Nov 5, 2019
84f97d7
improve docs and fix minor typos
yannikschaelte Nov 5, 2019
798ab15
minor edits
yannikschaelte Nov 5, 2019
9441789
address reviewer comments
yannikschaelte Nov 5, 2019
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
13 changes: 13 additions & 0 deletions doc/releasenotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ Release Notes
..........


0.9.21 (2019-11-05)
-------------------

* Introduce acceptor.StochasticAcceptor to encode the stochastic acceptance
step generalizing the standard uniform criterion.
* Introduce distance.StochasticKernel to encode noise distributions, with
several concrete implementations already.
* Introduce epsilon.Temperature to capture the temperature replacing the
traditional epsilons. In addition, multiple concrete
pyabc.epsilon.TemperatureSchemes have been implemented that handle the
calculation of the next temperature value (all #197).


0.9.20 (2019-10-30)
-------------------

Expand Down
37 changes: 33 additions & 4 deletions pyabc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import os
import logging


from .parameters import Parameter
from .random_variables import (
Distribution,
Expand All @@ -33,22 +32,37 @@
MinMaxDistance,
PercentileDistance,
RangeEstimatorDistance,
DistanceWithMeasureList)
DistanceWithMeasureList,
NormalKernel,
IndependentNormalKernel,
IndependentLaplaceKernel,
BinomialKernel)
from .epsilon import (
Epsilon,
NoEpsilon,
ConstantEpsilon,
QuantileEpsilon,
MedianEpsilon,
ListEpsilon)
ListEpsilon,
Temperature,
TemperatureScheme,
AcceptanceRateScheme,
ExponentialDecayScheme,
PolynomialDecayScheme,
DalyScheme,
FrielPettittScheme,
EssScheme)
from .smc import ABCSMC
from .storage import (
History,
create_sqlite_db_id)
from .acceptor import (
Acceptor,
SimpleFunctionAcceptor,
UniformAcceptor)
UniformAcceptor,
StochasticAcceptor,
pdf_norm_from_kernel,
pdf_norm_max_found)
from .model import (
Model,
SimpleModel,
Expand Down Expand Up @@ -87,13 +101,25 @@
"PercentileDistance",
"RangeEstimatorDistance",
"DistanceWithMeasureList",
"NormalKernel",
"IndependentNormalKernel",
"IndependentLaplaceKernel",
"BinomialKernel",
# epsilon
"Epsilon",
"NoEpsilon",
"ConstantEpsilon",
"ListEpsilon",
"QuantileEpsilon",
"MedianEpsilon",
"Temperature",
"TemperatureScheme",
"AcceptanceRateScheme",
"ExponentialDecayScheme",
"PolynomialDecayScheme",
"DalyScheme",
"FrielPettittScheme",
"EssScheme",
# random variable
"RVBase",
"RV",
Expand All @@ -118,6 +144,9 @@
"Acceptor",
"SimpleFunctionAcceptor",
"UniformAcceptor",
"StochasticAcceptor",
"pdf_norm_from_kernel",
"pdf_norm_max_found",
# model
"ModelResult",
"Model",
Expand Down
9 changes: 9 additions & 0 deletions pyabc/acceptor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
Acceptor,
SimpleFunctionAcceptor,
UniformAcceptor,
StochasticAcceptor,
)
from .pdf_norm import (
pdf_norm_from_kernel,
pdf_norm_max_found,
)


Expand All @@ -21,4 +26,8 @@
'Acceptor',
'SimpleFunctionAcceptor',
'UniformAcceptor',
'StochasticAcceptor',
# pdf norm
'pdf_norm_from_kernel',
'pdf_norm_max_found',
]
180 changes: 167 additions & 13 deletions pyabc/acceptor/acceptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
time.
"""

import numpy as np
import pandas as pd
from typing import Callable
import logging

from ..distance import Distance
from ..distance import Distance, SCALE_LIN
from ..epsilon import Epsilon
from ..parameters import Parameter
from .pdf_norm import pdf_norm_max_found


logger = logging.getLogger("Acceptor")
Expand Down Expand Up @@ -78,7 +80,6 @@ def initialize(
self,
t: int,
get_weighted_distances: Callable[[], pd.DataFrame],
max_nr_populations: int,
distance_function: Distance,
x_0: dict):
"""
Expand All @@ -93,8 +94,6 @@ def initialize(
The timepoint to initialize the acceptor for.
get_weighted_distances: Callable[[], pd.DataFrame]
Returns on demand the distances for initializing the acceptor.
max_nr_populations: int
Maximum number of populations in current run.
distance_function: Distance
Distance object. The acceptor should not modify it, but might
extract some meta information.
Expand All @@ -105,9 +104,7 @@ def initialize(

def update(self,
t: int,
weighted_distances: pd.DataFrame,
distance_function: Distance,
acceptance_rate: float):
weighted_distances: pd.DataFrame):
"""
Update the acceptance criterion.

Expand All @@ -118,10 +115,6 @@ def update(self,
The timepoint to initialize the acceptor for.
weighted_distances: Callable[[], pd.DataFrame]
The current generation's weighted distances.
distance_function: Distance
Distance object.
acceptance_rate: float
The current generation's acceptance rate.
"""
pass

Expand Down Expand Up @@ -171,6 +164,24 @@ def __call__(self,
"""
raise NotImplementedError()

# pylint: disable=R0201
def get_epsilon_config(self, t: int) -> dict:
elbaraim marked this conversation as resolved.
Show resolved Hide resolved
"""
Create a configuration object that contains all values of interest for
the update of the Epsilon object.

Parameters
----------
t: int
The timepoint for which to get the config.

Returns
-------
config: dict
The relevant information.
"""
return None


class SimpleFunctionAcceptor(Acceptor):
"""
Expand All @@ -183,7 +194,7 @@ class SimpleFunctionAcceptor(Acceptor):
Callable with the same signature as the __call__ method.
"""

def __init__(self, fun=None):
def __init__(self, fun: Callable):
super().__init__()
self.fun = fun

Expand Down Expand Up @@ -220,7 +231,6 @@ def accept_use_current_time(
Use only the distance function and epsilon criterion at the current time
point to evaluate whether to accept or reject.
"""

d = distance_function(x, x_0, t, par)
accept = d <= eps(t)

Expand Down Expand Up @@ -287,3 +297,147 @@ def __call__(self, distance_function, eps, x, x_0, t, par):
else: # use only current time
return accept_use_current_time(
distance_function, eps, x, x_0, t, par)


class StochasticAcceptor(Acceptor):
"""
This acceptor implements a stochastic acceptance step based on a
probability density, generalizing from the uniform acceptance kernel.
A particle is accepted if for the simulated summary statistics x,
observed summary statistics x_0 and parameters theta holds

.. math::

\\frac{\\text{pdf}(x_0|x,\\theta)}{c}\\geq u

where u ~ U[0,1], and c is a normalizing constant.

The concept is based on [#wilkinson]_. In addition, we introduce
acceptance kernel temperation and rejection control importance sampling
to permit a more flexible choice and adaptation of c.

.. [#wilkinson] Wilkinson, Richard David; "Approximate Bayesian
computation (ABC) gives exact results under the assumption of model
error"; Statistical applications in genetics and molecular biology
12.2 (2013): 129-141.

"""

def __init__(
self,
pdf_norm_method: Callable = None):
"""
Parameters
----------
pdf_norm_method: Callable
Function to calculate a pdf normalization (denoted `c` above).
Shipped are `pyabc.acceptor.pdf_norm_from_kernel` to use the
value provided by the StochasticKernel, and
`pyabc.acceptor.pdf_norm_max_found` (default) to always use
the maximum value among accepted particles so far.
Note that re-weighting based on ideas from rejection control
importance sampling to handle the normalization constant being
insufficient, and thus avoiding an importance sampling bias,
is included either way.
"""
super().__init__()

if pdf_norm_method is None:
pdf_norm_method = pdf_norm_max_found
self.pdf_norm_method = pdf_norm_method

# maximum pdfs, indexed by time
self.pdf_norms = {}

# fields to be filled later
self.x_0 = None
self.kernel_scale = None
self.kernel_pdf_max = None

def initialize(
self,
t: int,
get_weighted_distances: Callable[[], pd.DataFrame],
distance_function: Distance,
x_0: dict):
"""
Initialize temperature and maximum pdf.
"""
self.x_0 = x_0
self.kernel_scale = distance_function.ret_scale
self.kernel_pdf_max = distance_function.pdf_max

# update
self._update(t, get_weighted_distances)

def update(self,
t: int,
weighted_distances: pd.DataFrame):
self._update(t, lambda: weighted_distances)

def _update(self,
t: int,
get_weighted_distances: Callable[[], pd.DataFrame]):
"""
Update schemes for the upcoming time point t.
"""
# update pdf normalization
pdf_norm = self.pdf_norm_method(
kernel_val=self.kernel_pdf_max,
get_weighted_distances=get_weighted_distances,
prev_pdf_norm=None if not self.pdf_norms
else max(self.pdf_norms.values()))
self.pdf_norms[t] = pdf_norm

logger.debug(f"pdf_norm={self.pdf_norms[t]:.4e} for t={t}.")

def get_epsilon_config(self, t: int) -> dict:
elbaraim marked this conversation as resolved.
Show resolved Hide resolved
"""
Pack the pdf normalization and the kernel scale.
"""
return dict(
pdf_norm=self.pdf_norms[t],
kernel_scale=self.kernel_scale, # TODO Refactor
)

def __call__(self, distance_function, eps, x, x_0, t, par):
# rename
kernel = distance_function

# temperature
temp = eps(t)

# compute probability density
pd = kernel(x, x_0, t, par)
pdf_norm = self.pdf_norms[t]

# rescale
if kernel.ret_scale == SCALE_LIN:
pd_rescaled = pd / pdf_norm
else: # kernel.ret_scale == SCALE_LOG
pd_rescaled = np.exp(pd - pdf_norm)

# acceptance probability
acceptance_probability = pd_rescaled ** (1 / temp)

# accept
threshold = np.random.uniform(low=0, high=1)
if acceptance_probability >= threshold:
accept = True
else:
accept = False

# weight
if acceptance_probability == 0.0:
weight = 0.0
else:
weight = acceptance_probability / min(1, acceptance_probability)

# check pdf max ok
if pdf_norm < pd:
logger.debug(
f"Encountered pd={pd:.4e} > c={pdf_norm:.4e}, "
f"thus weight={weight:.4e}.")

# return unscaled density value and the acceptance flag
return AcceptorResult(pd, accept, weight)
Loading