forked from pabloswfly/genomcmcgan
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparameter.py
51 lines (40 loc) · 1.26 KB
/
parameter.py
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
import numpy as np
class Parameter:
def __init__(
self, name, val, bounds, inferable, log=False, plotlog=False, **kwargs
):
self.name = name
self._val = val
self._proposals = []
self.bounds = bounds
self.log = log
self.init = np.random.uniform(bounds[0], bounds[1])
self.step_size = 0.1
self.inferable = inferable
self.plotlog = plotlog
super(Parameter, self).__init__(**kwargs)
@property
def val(self):
return self._val
@property
def proposals(self):
return self._proposals
@val.setter
def val(self, x):
self._val = x
@proposals.setter
def proposals(self, prop):
self._proposals = prop
def prop(self, i):
return self.proposals[i]
def rand(self):
if not self.inferable:
return self._val
min, max = self.bounds
if self.log:
# RandomState() avoids getting the same random number from different
# CPUs when running the code in several processes in parallel
x = np.random.RandomState().uniform(np.log10(min), np.log10(max))
return np.float_power(10, x)
else:
return np.random.RandomState().uniform(min, max)