Skip to content

Commit 9779ba1

Browse files
author
Junpeng Lao
authored
[WIP] Implement step_size_decay (#2434)
* Revert "Remove unnecessary parameter" This reverts commit 3537b14. * add docstring for step_size_decay
1 parent 224847d commit 9779ba1

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pymc3/step_methods/sgmcmc.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ class BaseStochasticGradient(ArrayStepShared):
7373
Total size of the training data
7474
step_size : float
7575
Step size for the parameter update
76+
step_size_decay : int
77+
Step size decay rate. Every `step_size_decay` iteration the step size reduce
78+
to the half of the previous step size
7679
model : PyMC Model
7780
Optional model for sampling step. Defaults to None (taken from context)
7881
random_seed : int
@@ -98,6 +101,7 @@ def __init__(self,
98101
batch_size=None,
99102
total_size=None,
100103
step_size=1.0,
104+
step_size_decay=100,
101105
model=None,
102106
random_seed=None,
103107
minibatches=None,
@@ -129,6 +133,7 @@ def __init__(self,
129133
self.random = tt_rng(random_seed)
130134

131135
self.step_size = step_size
136+
self.step_size_decay = step_size_decay
132137
shared = make_shared_replacements(vars, model)
133138
self.q_size = int(sum(v.dsize for v in self.vars))
134139

@@ -237,7 +242,7 @@ def mk_training_fn(self):
237242
avg_I = self.avg_I
238243
t = self.t
239244
updates = self.updates
240-
step_size = self.step_size
245+
epsilon = self.step_size / pow(2.0, t // self.step_size_decay)
241246
random = self.random
242247
inarray = self.inarray
243248
gt, dlog_prior = self.dlogp_elemwise, self.dlog_prior
@@ -268,11 +273,11 @@ def mk_training_fn(self):
268273
# where B_ch is cholesky decomposition of B
269274
# i.e. B = dot(B_ch, B_ch^T)
270275
B_ch = tt.slinalg.cholesky(B)
271-
noise_term = tt.dot((2.*B_ch)/tt.sqrt(step_size), \
276+
noise_term = tt.dot((2.*B_ch)/tt.sqrt(epsilon), \
272277
random.normal((q_size,), dtype=theano.config.floatX))
273278
# 9.
274279
# Inv. Fisher Cov. Matrix
275-
cov_mat = (gamma * I_t * N) + ((4. / step_size) * B)
280+
cov_mat = (gamma * I_t * N) + ((4. / epsilon) * B)
276281
inv_cov_mat = tt.nlinalg.matrix_inverse(cov_mat)
277282
# Noise Coefficient
278283
noise_coeff = (dlog_prior + (N * avg_gt) + noise_term)

0 commit comments

Comments
 (0)