Skip to content

Commit 3725276

Browse files
committed
doc changes
1 parent 69745d7 commit 3725276

File tree

4 files changed

+65
-10
lines changed

4 files changed

+65
-10
lines changed

pymc/model.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ def get_context(cls):
3939
raise TypeError("No context on context stack")
4040

4141
def withcontext(contexttype, argname):
42+
"""
43+
Returns a decorator for wrapping functions so they look for an argument in a specific argument slot.
44+
If not found, the decorated function searches the for a context and inserts it in that slot.
45+
46+
Parameters
47+
----------
48+
contexttype : type
49+
The type of context to search for
50+
argname : string
51+
The name of the argument slot where the context should go
52+
53+
Returns
54+
-------
55+
decorator function
56+
57+
"""
4258
def decorator(fn):
4359
n = list(fn.func_code.co_varnames).index(argname)
4460

@@ -83,20 +99,25 @@ def logp(model):
8399

84100
@property
85101
def logpc(model):
102+
"""Compiled log probability density function"""
86103
return compilef(model.logp)
87104

88105
def dlogpc(model, vars = None):
106+
"""Compiled log probability density gradient function"""
89107
return compilef(gradient(model.logp, vars))
90108

91109
def d2logpc(model, vars = None):
110+
"""Compiled log probability density hessian function"""
92111
return compilef(hessian(model.logp, vars))
93112

94113
@property
95114
def test_point(self):
115+
"""Test point used to check that the model doesn't generate errors"""
96116
return Point(self, ((var, var.tag.test_value) for var in self.vars))
97117

98118
@property
99119
def cont_vars(model):
120+
"""All the continuous variables in the model"""
100121
return typefilter(model.vars, continuous_types)
101122

102123
"""
@@ -144,6 +165,18 @@ def Point(model, *args,**kwargs):
144165

145166

146167
def compilef(outs, mode = None):
168+
"""
169+
Compiles a Theano function which returns `outs` and takes the variable ancestors of `outs` as inputs.
170+
171+
Parameters
172+
----------
173+
outs : Theano variable or iterable of Theano variables
174+
mode : Theano compilation mode
175+
176+
Returns
177+
-------
178+
Compiled Theano function
179+
"""
147180
return PointFunc(
148181
function(inputvars(outs), outs,
149182
allow_input_downcast = True,

pymc/sample.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def sample(model, draws, step, start = None, trace = None, track_progress = True
1818
Parameters
1919
----------
2020
21+
model : Model (optional if in `with` context)
2122
draws : int
2223
The number of samples to draw
2324
step : function

pymc/tuning/scaling.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@
1010
__all__ = ['approx_hess', 'find_hessian', 'trace_cov']
1111

1212
@withmodel
13-
def approx_hess(model, start, vars=None):
13+
def approx_hess(model, point, vars=None):
1414
"""
1515
Returns an approximation of the Hessian at the current chain location.
1616
1717
Parameters
1818
----------
19-
model : Model
20-
start : dict
21-
vars : list or array
19+
model : Model (optional if in `with` context)
20+
point : dict
21+
vars : list
2222
Variables for which Hessian is to be calculated.
2323
"""
2424
if vars is None :
2525
vars = model.cont_vars
2626

27-
start = Point(model, start)
27+
point = Point(model, point)
2828

29-
bij = DictToArrayBijection(ArrayOrdering(vars), start)
29+
bij = DictToArrayBijection(ArrayOrdering(vars), point)
3030
dlogp = bij.mapf(model.dlogpc(vars))
3131

3232

@@ -38,18 +38,39 @@ def grad_logp(point):
3838
this should be the Hessian; invert it to find the approximate
3939
covariance matrix.
4040
'''
41-
return -nd.Jacobian(grad_logp)(bij.map(start))
41+
return -nd.Jacobian(grad_logp)(bij.map(point))
4242

4343
@withmodel
4444
def find_hessian(model, point, vars = None):
45+
"""
46+
Returns Hessian of logp at the point passed.
47+
48+
Parameters
49+
----------
50+
model : Model (optional if in `with` context)
51+
point : dict
52+
vars : list
53+
Variables for which Hessian is to be calculated.
54+
"""
4555
H = model.d2logpc(vars)
4656
return H(Point(model, point))
4757

4858
def trace_cov(trace, vars = None):
4959
"""
5060
Calculate the flattened covariance matrix using a sample trace
5161
52-
Useful if you want to base your covariance on some initial samples.
62+
Useful if you want to base your covariance matrix for further sampling on some initial samples.
63+
64+
Parameters
65+
----------
66+
trace : Trace
67+
vars : list
68+
variables for which to calculate covariance matrix
69+
70+
Returns
71+
-------
72+
r : array (n,n)
73+
covariance matrix
5374
"""
5475

5576
if vars is None:

pymc/tuning/starting.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ def find_MAP(model, start = None, vars=None, fmin = optimize.fmin_bfgs, return_r
2020
2121
Parameters
2222
----------
23-
model : Model
23+
model : Model (optional if in `with` context)
2424
start : dict of parameter values (Defaults to model.test_point)
25-
vars : list or array
25+
vars : list
2626
List of variables to set to MAP point (Defaults to all continuous).
2727
fmin : function
2828
Optimization algorithm (Defaults to `scipy.optimize.fmin_l_bfgs_b`).

0 commit comments

Comments
 (0)