Skip to content

Commit e84d804

Browse files
committed
renamed IdxMap to ArrayOrdering, which seems more informative
1 parent da10a5a commit e84d804

File tree

5 files changed

+38
-22
lines changed

5 files changed

+38
-22
lines changed

pymc/blocking.py

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
import numpy as np
77
import collections
88

9-
__all__ = ['IdxMap', 'DictToArrayBijection', 'DictToVarBijection']
9+
__all__ = ['ArrayOrdering', 'DictToArrayBijection', 'DictToVarBijection']
1010

1111
VarMap = collections.namedtuple('VarMap', 'var, slc, shp')
1212

1313
# TODO Classes and methods need to be fully documented.
14-
class IdxMap(object):
14+
class ArrayOrdering(object):
15+
"""
16+
An ordering for an array space
17+
"""
1518
def __init__(self, vars):
1619
self.vmap = []
1720
dim = 0
@@ -25,8 +28,11 @@ def __init__(self, vars):
2528

2629

2730
class DictToArrayBijection(object):
28-
def __init__(self, idxmap, dpoint):
29-
self.idxmap = idxmap
31+
"""
32+
A mapping between a dict space and an array space
33+
"""
34+
def __init__(self, ordering, dpoint):
35+
self.ordering = ordering
3036
self.dpt = dpoint
3137

3238
def map(self, dpt):
@@ -37,8 +43,8 @@ def map(self, dpt):
3743
----------
3844
dpt : dict
3945
"""
40-
apt = np.empty(self.idxmap.dimensions)
41-
for var, slc, _ in self.idxmap.vmap:
46+
apt = np.empty(self.ordering.dimensions)
47+
for var, slc, _ in self.ordering.vmap:
4248
apt[slc] = np.ravel(dpt[var])
4349
return apt
4450

@@ -52,24 +58,31 @@ def rmap(self, apt):
5258
"""
5359
dpt = self.dpt.copy()
5460

55-
for var, slc, shp in self.idxmap.vmap:
61+
for var, slc, shp in self.ordering.vmap:
5662
dpt[var] = np.reshape(apt[slc], shp)
5763

5864

5965
return dpt
6066

6167
def mapf(self, f):
6268
"""
63-
Maps function f : DictSpace -> T to ArraySpace -> T
69+
function f : DictSpace -> T to ArraySpace -> T
6470
6571
Parameters
66-
---------
72+
----------
6773
6874
f : dict -> T
75+
76+
Returns
77+
-------
78+
f : array -> T
6979
"""
70-
return BijectionWrapFunc(self,f)
80+
return Compose(self.rmap,f)
7181

7282
class DictToVarBijection(object):
83+
"""
84+
A mapping between a dict space and the array space for one element within the dict space
85+
"""
7386
def __init__(self, var, idx, dpoint):
7487
self.var = str(var)
7588
self.idx = idx
@@ -88,13 +101,16 @@ def rmap(self, apt):
88101

89102
return dpt
90103
def mapf(self, f):
91-
return BijectionWrapFunc(self, f)
104+
return Compose(self.rmap, f)
92105

93106

94-
class BijectionWrapFunc(object):
95-
def __init__(self, bij, fn):
96-
self.bij = bij
97-
self.fn = fn
107+
class Compose(object):
108+
"""
109+
Compose two functions in a pickleable way
110+
"""
111+
def __init__(self, fa, fb):
112+
self.fa = fa
113+
self.fb = fb
98114

99-
def __call__(self, d):
100-
return self.fn(self.bij.rmap(d))
115+
def __call__(self, x):
116+
return self.fa(self.fb(x))

pymc/step_methods/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
class array_step(object):
99
def __init__(self, vars, fs, allvars = False):
10-
self.idxmap = IdxMap(vars)
10+
self.ordering = ArrayOrdering(vars)
1111
self.fs = fs
1212
self.allvars = allvars
1313

1414
def step(self, state, point):
15-
bij = DictToArrayBijection(self.idxmap, point)
15+
bij = DictToArrayBijection(self.ordering, point)
1616

1717
inputs = map(bij.mapf, self.fs)
1818
if self.allvars:

pymc/tuning/scaling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def approx_hess(model, start, vars=None):
2424

2525
start = clean_point(start)
2626

27-
bij = DictToArrayBijection(IdxMap(vars), start)
27+
bij = DictToArrayBijection(ArrayOrdering(vars), start)
2828
dlogp = bij.mapf(model.dlogpc(vars))
2929

3030

pymc/tuning/starting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def find_MAP(model, start = None, vars=None, fmin = optimize.fmin_bfgs, return_r
3737
vars = model.cont_vars
3838

3939
start = clean_point(start)
40-
bij = DictToArrayBijection(IdxMap(vars), start)
40+
bij = DictToArrayBijection(ArrayOrdering(vars), start)
4141

4242
logp = bij.mapf(model.logpc)
4343
dlogp = bij.mapf(model.dlogpc(vars))

tests/test_distributions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def check_int_to_1(model, value, domains):
8686
def check_dlogp(model, value, domains):
8787

8888
domains = [d[1:-1] for d in domains]
89-
bij = DictToArrayBijection(IdxMap(model.cont_vars), model.test_point)
89+
bij = DictToArrayBijection(ArrayOrdering(model.cont_vars), model.test_point)
9090

9191
dlp = model.dlogpc()
9292
dlogp = bij.mapf(model.dlogpc())

0 commit comments

Comments
 (0)