-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathparameters.py
More file actions
70 lines (51 loc) · 1.8 KB
/
parameters.py
File metadata and controls
70 lines (51 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# -*- coding: utf-8 -*-
import numpy as np
class SampledParam:
"""A SciPy-based parameter prior class.
Parameters
----------
scipy_distribution: SciPy continuous random variable class
A SciPy statistical distribution (i.e. scipy.stats.norm)
args:
Arguments for the SciPy distribution
kwargs:
keyword arguments for the SciPy distribution
"""
def __init__(self, scipy_distribution, *args, **kwargs):
self.dist = scipy_distribution(*args, **kwargs)
self.dsize = self.random().size
def interval(self, alpha=1):
"""Return the interval for a given alpha value."""
return self.dist.interval(alpha)
def random(self, reseed=False):
"""Return a random value drawn from this prior."""
if reseed:
random_seed = np.random.RandomState()
else:
random_seed = None
return self.dist.rvs(random_state=random_seed)
def prior(self, q0):
"""Return the prior log probability given a point.
Parameters
----------
q0: array
A location in parameter space.
"""
logp = np.sum(self.dist.logpdf(q0))
return logp
class FlatParam(SampledParam):
"""A Flat parameter class (returns 0 at all locations).
Parameters
----------
test_value: array
Representative value for the parameter. Used to infer the parameter dimension, which is needed in the DREAM algorithm.
"""
def __init__(self, test_value):
self.dsize = test_value.size
def prior(self, q0):
return 0
def interval(self, alpha=1):
"""Return the interval for a given alpha value."""
lower = [-np.inf] * self.dsize
upper = [np.inf] * self.dsize
return [lower, upper]