Skip to content

Commit

Permalink
ENH: Allow autosaving to save only some nodes instead of all
Browse files Browse the repository at this point in the history
  • Loading branch information
jluttine committed Jul 31, 2015
1 parent bfc6301 commit c583211
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions bayespy/inference/vmp/vmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def __init__(self,
self.l = dict(zip(self.model,
len(self.model)*[np.array([])]))
self.autosave_iterations = autosave_iterations
self.autosave_nodes = None
if not autosave_filename:
date = datetime.datetime.today().strftime('%Y%m%d%H%M%S')
prefix = 'vb_autosave_%s_' % date
Expand All @@ -95,9 +96,10 @@ def __init__(self,
self.callback_output = None
self.tol = tol

def set_autosave(self, filename, iterations=None):
def set_autosave(self, filename, iterations=None, nodes=None):
self.autosave_filename = filename
self.filename = filename
self.autosave_nodes = nodes
if iterations is not None:
self.autosave_iterations = iterations

Expand Down Expand Up @@ -671,7 +673,10 @@ def _end_iteration_step(self, method, cputime, tol=None, verbose=True, bound_cpu
if (self.autosave_iterations > 0
and np.mod(self.iter+1, self.autosave_iterations) == 0):

self.save(filename=self.autosave_filename)
if self.autosave_nodes is not None:
self.save(*self.autosave_nodes, filename=self.autosave_filename)
else:
self.save(filename=self.autosave_filename)
if verbose:
print('Auto-saved to %s' % self.autosave_filename)

Expand Down

0 comments on commit c583211

Please sign in to comment.