Allow EP to have a auto reset option

This commit is contained in:
Alan Saul 2015-11-20 15:06:20 +02:00
parent ebf98328fe
commit efa9b920c3

View file

@ -9,7 +9,7 @@ from ...util import diag
log_2_pi = np.log(2*np.pi) log_2_pi = np.log(2*np.pi)
class EPBase(object): class EPBase(object):
def __init__(self, epsilon=1e-6, eta=1., delta=1.): def __init__(self, epsilon=1e-6, eta=1., delta=1., always_reset=False):
""" """
The expectation-propagation algorithm. The expectation-propagation algorithm.
For nomenclature see Rasmussen & Williams 2006. For nomenclature see Rasmussen & Williams 2006.
@ -22,6 +22,7 @@ class EPBase(object):
:type delta: float64 :type delta: float64
""" """
super(EPBase, self).__init__() super(EPBase, self).__init__()
self.always_reset = always_reset
self.epsilon, self.eta, self.delta = epsilon, eta, delta self.epsilon, self.eta, self.delta = epsilon, eta, delta
self.reset() self.reset()
@ -38,6 +39,9 @@ class EPBase(object):
class EP(EPBase, ExactGaussianInference): class EP(EPBase, ExactGaussianInference):
def inference(self, kern, X, likelihood, Y, mean_function=None, Y_metadata=None, precision=None, K=None): def inference(self, kern, X, likelihood, Y, mean_function=None, Y_metadata=None, precision=None, K=None):
if self.always_reset:
self.reset()
num_data, output_dim = Y.shape num_data, output_dim = Y.shape
assert output_dim == 1, "ep in 1D only (for now!)" assert output_dim == 1, "ep in 1D only (for now!)"