likelihoods are now Parameterized objects

This commit is contained in:
Ricardo 2013-09-16 15:45:23 +01:00
parent 3db9d01734
commit 127340d17d
5 changed files with 15 additions and 9 deletions

View file

@ -372,7 +372,10 @@ class Parameterized(object):
for j in tie: for j in tie:
ties[j] = '(' + str(i) + ')' ties[j] = '(' + str(i) + ')'
values = ['%.4f' % float(v) for v in values] if values.size == 1:
values = ['%.4f' %float(values)]
else:
values = ['%.4f' % float(v) for v in values]
max_names = max([len(names[i]) for i in range(len(names))] + [len(header[0])]) max_names = max([len(names[i]) for i in range(len(names))] + [len(header[0])])
max_values = max([len(values[i]) for i in range(len(values))] + [len(header[1])]) max_values = max([len(values[i]) for i in range(len(values))] + [len(header[1])])
max_constraint = max([len(constraints[i]) for i in range(len(constraints))] + [len(header[2])]) max_constraint = max([len(constraints[i]) for i in range(len(constraints))] + [len(header[2])])

View file

@ -37,6 +37,8 @@ class EP(likelihood):
self.VVT_factor = self.V self.VVT_factor = self.V
self.trYYT = 0. self.trYYT = 0.
super(EP, self).__init__()
def restart(self): def restart(self):
self.tau_tilde = np.zeros(self.N) self.tau_tilde = np.zeros(self.N)
self.v_tilde = np.zeros(self.N) self.v_tilde = np.zeros(self.N)

View file

@ -34,6 +34,8 @@ class Gaussian(likelihood):
self._variance = np.asarray(variance) + 1. self._variance = np.asarray(variance) + 1.
self._set_params(np.asarray(variance)) self._set_params(np.asarray(variance))
super(Gaussian, self).__init__()
def set_data(self, data): def set_data(self, data):
self.data = data self.data = data
self.N, D = data.shape self.N, D = data.shape

View file

@ -45,6 +45,8 @@ class Gaussian_Mixed_Noise(likelihood):
self.set_data(data_list) self.set_data(data_list)
self._set_params(np.asarray(noise_params)) self._set_params(np.asarray(noise_params))
super(Gaussian_Mixed_Noise, self).__init__()
def set_data(self, data_list): def set_data(self, data_list):
self.data = np.vstack(data_list) self.data = np.vstack(data_list)
self.N, D = self.data.shape self.N, D = self.data.shape

View file

@ -1,7 +1,8 @@
import numpy as np import numpy as np
import copy import copy
from ..core.parameterized import Parameterized
class likelihood: class likelihood(Parameterized):
""" """
The atom for a likelihood class The atom for a likelihood class
@ -16,10 +17,10 @@ class likelihood:
self.is_heteroscedastic : enables significant computational savings in GP self.is_heteroscedastic : enables significant computational savings in GP
self.precision : a scalar or vector representation of the effective target precision self.precision : a scalar or vector representation of the effective target precision
self.YYT : (optional) = np.dot(self.Y, self.Y.T) enables computational savings for D>N self.YYT : (optional) = np.dot(self.Y, self.Y.T) enables computational savings for D>N
self.V : self.precision * self.Y self.V : self.precision * self.Y
""" """
def __init__(self,data): def __init__(self):
raise ValueError, "this class is not to be instantiated" Parameterized.__init__(self)
def _get_params(self): def _get_params(self):
raise NotImplementedError raise NotImplementedError
@ -38,7 +39,3 @@ class likelihood:
def predictive_values(self, mu, var): def predictive_values(self, mu, var):
raise NotImplementedError raise NotImplementedError
def copy(self):
""" Returns a (deep) copy of the current likelihood """
return copy.deepcopy(self)