diff --git a/GPy/core/gp.py b/GPy/core/gp.py index 68d4376e..63903242 100644 --- a/GPy/core/gp.py +++ b/GPy/core/gp.py @@ -176,7 +176,7 @@ class GP(GPBase): .. Note:: For multiple output models only """ - assert hasattr(self,'multioutput') + assert hasattr(self,'multioutput'), 'This function is for multiple output models only.' index = np.ones_like(Xnew)*output Xnew = np.hstack((Xnew,index)) @@ -204,8 +204,7 @@ class GP(GPBase): .. Note:: For multiple output models only """ - assert hasattr(self,'multioutput') - + assert hasattr(self,'multioutput'), 'This function is for multiple output models only.' # creates an index column and appends it to _Xnew index = np.ones_like(_Xnew)*output _Xnew = np.hstack((_Xnew,index)) diff --git a/GPy/core/gp_base.py b/GPy/core/gp_base.py index 4513ddac..e26deb0f 100644 --- a/GPy/core/gp_base.py +++ b/GPy/core/gp_base.py @@ -59,28 +59,28 @@ class GPBase(Model): def plot_f(self, samples=0, plot_limits=None, which_data='all', which_parts='all', resolution=None, full_cov=False, fignum=None, ax=None,output=None): """ - Plot the GP's view of the world, where the data is normalized and the - - In one dimension, the function is plotted with a shaded region identifying two standard deviations. - - In two dimsensions, a contour-plot shows the mean predicted function - - Not implemented in higher dimensions + Plot the GP's view of the world, where the data is normalized and the + - In one dimension, the function is plotted with a shaded region identifying two standard deviations. + - In two dimsensions, a contour-plot shows the mean predicted function + - Not implemented in higher dimensions - :param samples: the number of a posteriori samples to plot - :param plot_limits: The limits of the plot. If 1D [xmin,xmax], if 2D [[xmin,ymin],[xmax,ymax]]. Defaluts to data limits - :param which_data: which if the training data to plot (default all) - :type which_data: 'all' or a slice object to slice self.X, self.Y - :param which_parts: which of the kernel functions to plot (additively) - :type which_parts: 'all', or list of bools - :param resolution: the number of intervals to sample the GP on. Defaults to 200 in 1D and 50 (a 50x50 grid) in 2D - :type resolution: int - :param full_cov: - :type full_cov: bool - :param fignum: figure to plot on. - :type fignum: figure number - :param ax: axes to plot on. - :type ax: axes handle + :param samples: the number of a posteriori samples to plot + :param plot_limits: The limits of the plot. If 1D [xmin,xmax], if 2D [[xmin,ymin],[xmax,ymax]]. Defaluts to data limits + :param which_data: which if the training data to plot (default all) + :type which_data: 'all' or a slice object to slice self.X, self.Y + :param which_parts: which of the kernel functions to plot (additively) + :type which_parts: 'all', or list of bools + :param resolution: the number of intervals to sample the GP on. Defaults to 200 in 1D and 50 (a 50x50 grid) in 2D + :type resolution: int + :param full_cov: + :type full_cov: bool + :param fignum: figure to plot on. + :type fignum: figure number + :param ax: axes to plot on. + :type ax: axes handle - :param output: which output to plot (for multiple output models only) - :type output: integer (first output is 0) + :param output: which output to plot (for multiple output models only) + :type output: integer (first output is 0) """ if which_data == 'all': which_data = slice(None) @@ -89,69 +89,81 @@ class GPBase(Model): fig = pb.figure(num=fignum) ax = fig.add_subplot(111) - if self.X.shape[1] == 1 and not hasattr(self,'multioutput'): - Xnew, xmin, xmax = x_frame1D(self.X, plot_limits=plot_limits) - if samples == 0: - m, v = self._raw_predict(Xnew, which_parts=which_parts) - gpplot(Xnew, m, m - 2 * np.sqrt(v), m + 2 * np.sqrt(v), axes=ax) + if not hasattr(self,'multioutput'): + + if self.X.shape[1] == 1: + Xnew, xmin, xmax = x_frame1D(self.X, plot_limits=plot_limits) + if samples == 0: + m, v = self._raw_predict(Xnew, which_parts=which_parts) + gpplot(Xnew, m, m - 2 * np.sqrt(v), m + 2 * np.sqrt(v), axes=ax) + ax.plot(self.X[which_data], self.likelihood.Y[which_data], 'kx', mew=1.5) + else: + m, v = self._raw_predict(Xnew, which_parts=which_parts, full_cov=True) + v = v.reshape(m.size,-1) if len(v.shape)==3 else v + Ysim = np.random.multivariate_normal(m.flatten(), v, samples) + gpplot(Xnew, m, m - 2 * np.sqrt(np.diag(v)[:, None]), m + 2 * np.sqrt(np.diag(v))[:, None, ], axes=ax) + for i in range(samples): + ax.plot(Xnew, Ysim[i, :], Tango.colorsHex['darkBlue'], linewidth=0.25) + ax.plot(self.X[which_data], self.likelihood.Y[which_data], 'kx', mew=1.5) + ax.set_xlim(xmin, xmax) + ymin, ymax = min(np.append(self.likelihood.Y, m - 2 * np.sqrt(np.diag(v)[:, None]))), max(np.append(self.likelihood.Y, m + 2 * np.sqrt(np.diag(v)[:, None]))) + ymin, ymax = ymin - 0.1 * (ymax - ymin), ymax + 0.1 * (ymax - ymin) + ax.set_ylim(ymin, ymax) + + if hasattr(self,'Z'): + Zu = self.Z * self._Xscale + self._Xoffset + ax.plot(Zu, np.zeros_like(Zu) + ax.get_ylim()[0], 'r|', mew=1.5, markersize=12) + + elif self.X.shape[1] == 2: + resolution = resolution or 50 + Xnew, xmin, xmax, xx, yy = x_frame2D(self.X, plot_limits, resolution) + m, v = self._raw_predict(Xnew, which_parts=which_parts) + m = m.reshape(resolution, resolution).T + ax.contour(xx, yy, m, vmin=m.min(), vmax=m.max(), cmap=pb.cm.jet) # @UndefinedVariable + ax.scatter(self.X[:, 0], self.X[:, 1], 40, self.likelihood.Y, linewidth=0, cmap=pb.cm.jet, vmin=m.min(), vmax=m.max()) # @UndefinedVariable + ax.set_xlim(xmin[0], xmax[0]) + ax.set_ylim(xmin[1], xmax[1]) + else: - m, v = self._raw_predict(Xnew, which_parts=which_parts, full_cov=True) - Ysim = np.random.multivariate_normal(m.flatten(), v, samples) - gpplot(Xnew, m, m - 2 * np.sqrt(np.diag(v)[:, None]), m + 2 * np.sqrt(np.diag(v))[:, None, ], axes=ax) - for i in range(samples): - ax.plot(Xnew, Ysim[i, :], Tango.colorsHex['darkBlue'], linewidth=0.25) - ax.plot(self.X[which_data], self.likelihood.Y[which_data], 'kx', mew=1.5) - ax.set_xlim(xmin, xmax) - ymin, ymax = min(np.append(self.likelihood.Y, m - 2 * np.sqrt(np.diag(v)[:, None]))), max(np.append(self.likelihood.Y, m + 2 * np.sqrt(np.diag(v)[:, None]))) - ymin, ymax = ymin - 0.1 * (ymax - ymin), ymax + 0.1 * (ymax - ymin) - ax.set_ylim(ymin, ymax) - - elif self.X.shape[1] == 2 and not hasattr(self,'multioutput'): - resolution = resolution or 50 - Xnew, xmin, xmax, xx, yy = x_frame2D(self.X, plot_limits, resolution) - m, v = self._raw_predict(Xnew, which_parts=which_parts) - m = m.reshape(resolution, resolution).T - ax.contour(xx, yy, m, vmin=m.min(), vmax=m.max(), cmap=pb.cm.jet) # @UndefinedVariable - ax.scatter(self.X[:, 0], self.X[:, 1], 40, self.likelihood.Y, linewidth=0, cmap=pb.cm.jet, vmin=m.min(), vmax=m.max()) # @UndefinedVariable - ax.set_xlim(xmin[0], xmax[0]) - ax.set_ylim(xmin[1], xmax[1]) - - - elif self.X.shape[1] == 2 and hasattr(self,'multioutput'): - output -= 1 - assert self.num_outputs >= output, 'The model has only %s outputs.' %self.num_outputs - Xu = self.X[self.X[:,-1]==output ,0:1] - Xnew, xmin, xmax = x_frame1D(Xu, plot_limits=plot_limits) - - if samples == 0: - m, v = self._raw_predict_single_output(Xnew, output=output, which_parts=which_parts) - gpplot(Xnew, m, m - 2 * np.sqrt(v), m + 2 * np.sqrt(v), axes=ax) - ax.plot(Xu[which_data], self.likelihood.Y[self.likelihood.index==output][:,None], 'kx', mew=1.5) - else: - m, v = self._raw_predict_single_output(Xnew, output=output, which_parts=which_parts, full_cov=True) - Ysim = np.random.multivariate_normal(m.flatten(), v, samples) - gpplot(Xnew, m, m - 2 * np.sqrt(np.diag(v)[:, None]), m + 2 * np.sqrt(np.diag(v))[:, None, ], axes=ax) - for i in range(samples): - ax.plot(Xnew, Ysim[i, :], Tango.colorsHex['darkBlue'], linewidth=0.25) - ax.set_xlim(xmin, xmax) - ymin, ymax = min(np.append(self.likelihood.Y, m - 2 * np.sqrt(np.diag(v)[:, None]))), max(np.append(self.likelihood.Y, m + 2 * np.sqrt(np.diag(v)[:, None]))) - ymin, ymax = ymin - 0.1 * (ymax - ymin), ymax + 0.1 * (ymax - ymin) - ax.set_ylim(ymin, ymax) - - if hasattr(self,'Z'): - Zu = self.Z[self.Z[:,-1]==output,:] - Zu = self.Z * self._Xscale + self._Xoffset - Zu = self.Z[self.Z[:,-1]==output ,0:1] #?? - ax.plot(Zu, np.zeros_like(Zu) + ax.get_ylim()[0], 'r|', mew=1.5, markersize=12) - - elif self.X.shape[1] == 3 and hasattr(self,'multioutput'): - raise NotImplementedError, "Plots not implemented for multioutput models with 2D inputs...yet" - output -= 1 - assert self.num_outputs >= output, 'The model has only %s outputs.' %self.num_outputs - + raise NotImplementedError, "Cannot define a frame with more than two input dimensions" else: - raise NotImplementedError, "Cannot define a frame with more than two input dimensions" + assert self.num_outputs > output, 'The model has only %s outputs.' %self.num_outputs + + if self.X.shape[1] == 2: + assert self.num_outputs >= output, 'The model has only %s outputs.' %self.num_outputs + Xu = self.X[self.X[:,-1]==output ,0:1] + Xnew, xmin, xmax = x_frame1D(Xu, plot_limits=plot_limits) + + if samples == 0: + m, v = self._raw_predict_single_output(Xnew, output=output, which_parts=which_parts) + gpplot(Xnew, m, m - 2 * np.sqrt(v), m + 2 * np.sqrt(v), axes=ax) + ax.plot(Xu[which_data], self.likelihood.Y[self.likelihood.index==output][:,None], 'kx', mew=1.5) + else: + m, v = self._raw_predict_single_output(Xnew, output=output, which_parts=which_parts, full_cov=True) + v = v.reshape(m.size,-1) if len(v.shape)==3 else v + Ysim = np.random.multivariate_normal(m.flatten(), v, samples) + gpplot(Xnew, m, m - 2 * np.sqrt(np.diag(v)[:, None]), m + 2 * np.sqrt(np.diag(v))[:, None, ], axes=ax) + for i in range(samples): + ax.plot(Xnew, Ysim[i, :], Tango.colorsHex['darkBlue'], linewidth=0.25) + ax.set_xlim(xmin, xmax) + ymin, ymax = min(np.append(self.likelihood.Y, m - 2 * np.sqrt(np.diag(v)[:, None]))), max(np.append(self.likelihood.Y, m + 2 * np.sqrt(np.diag(v)[:, None]))) + ymin, ymax = ymin - 0.1 * (ymax - ymin), ymax + 0.1 * (ymax - ymin) + ax.set_ylim(ymin, ymax) + + elif self.X.shape[1] == 3: + raise NotImplementedError, "Plots not implemented for multioutput models with 2D inputs...yet" + assert self.num_outputs >= output, 'The model has only %s outputs.' %self.num_outputs + + else: + raise NotImplementedError, "Cannot define a frame with more than two input dimensions" + + if hasattr(self,'Z'): + Zu = self.Z[self.Z[:,-1]==output,:] + Zu = self.Z * self._Xscale + self._Xoffset + Zu = self.Z[self.Z[:,-1]==output ,0:1] #?? + ax.plot(Zu, np.zeros_like(Zu) + ax.get_ylim()[0], 'r|', mew=1.5, markersize=12) + def plot(self, plot_limits=None, which_data='all', which_parts='all', resolution=None, levels=20, samples=0, fignum=None, ax=None, output=None, fixed_inputs=[], linecol=Tango.colorsHex['darkBlue'],fillcol=Tango.colorsHex['lightBlue']): """ @@ -203,7 +215,7 @@ class GPBase(Model): if plotdims == 1: resolution = resolution or 200 - Xu = self.X * self._Xscale + self._Xoffset # NOTE self.X are the normalized values now + Xu = self.X * self._Xscale + self._Xoffset #NOTE self.X are the normalized values now fixed_dims = np.array([i for i,v in fixed_inputs]) freedim = np.setdiff1d(np.arange(self.input_dim),fixed_dims) diff --git a/GPy/core/model.py b/GPy/core/model.py index 6832d4e0..89150b3a 100644 --- a/GPy/core/model.py +++ b/GPy/core/model.py @@ -31,8 +31,8 @@ class Model(Parameterized): def getstate(self): """ Get the current state of the class. - Inherited from Parameterized, so add those parameters to the state + :return: list of states from the model. """ @@ -46,7 +46,7 @@ class Model(Parameterized): call Parameterized with the rest of the state :param state: the state of the model. - :type state: list as returned from getstate. + :type state: list as returned from getstate. """ self.preferred_optimizer = state.pop() self.sampling_runs = state.pop() @@ -397,17 +397,20 @@ class Model(Parameterized): return np.nan return 0.5 * self._get_params().size * np.log(2 * np.pi) + self.log_likelihood() - hld - def __str__(self, names=None): - if names is None: - names = self._get_print_names() - s = Parameterized.__str__(self, names=names).split('\n') + def __str__(self): + s = Parameterized.__str__(self).split('\n') + #def __str__(self, names=None): + # if names is None: + # names = self._get_print_names() + #s = Parameterized.__str__(self, names=names).split('\n') # add priors to the string if self.priors is not None: strs = [str(p) if p is not None else '' for p in self.priors] else: - strs = [''] * len(self._get_param_names()) - name_indices = self.grep_param_names("|".join(names)) - strs = np.array(strs)[name_indices] + strs = [''] * len(self._get_params()) + # strs = [''] * len(self._get_param_names()) + # name_indices = self.grep_param_names("|".join(names)) + # strs = np.array(strs)[name_indices] width = np.array(max([len(p) for p in strs] + [5])) + 4 log_like = self.log_likelihood() diff --git a/GPy/core/parameterized.py b/GPy/core/parameterized.py index cad4d2a9..aeb9ef85 100644 --- a/GPy/core/parameterized.py +++ b/GPy/core/parameterized.py @@ -27,9 +27,9 @@ class Parameterized(object): def _get_param_names(self): raise NotImplementedError, "this needs to be implemented to use the Parameterized class" - def _get_print_names(self): - """ Override for which names to print out, when using print m """ - return self._get_param_names() + #def _get_print_names(self): + # """ Override for which names to print out, when using print m """ + # return self._get_param_names() def pickle(self, filename, protocol=None): if protocol is None: @@ -63,10 +63,10 @@ class Parameterized(object): """ Get the current state of the class, here just all the indices, rest can get recomputed - For inheriting from Parameterized: - Allways append the state of the inherited object - and call down to the inherited object in setstate!! + + Allways append the state of the inherited object + and call down to the inherited object in setstate!! """ return [self.tied_indices, self.fixed_indices, @@ -336,26 +336,30 @@ class Parameterized(object): n = [nn for i, nn in enumerate(n) if not i in remove] return n - @property - def all(self): - return self.__str__(self._get_param_names()) + #@property + #def all(self): + # return self.__str__(self._get_param_names()) - def __str__(self, names=None, nw=30): + #def __str__(self, names=None, nw=30): + def __str__(self, nw=30): """ Return a string describing the parameter names and their ties and constraints """ - if names is None: - names = self._get_print_names() - name_indices = self.grep_param_names("|".join(names)) + names = self._get_param_names() + #if names is None: + # names = self._get_print_names() + #name_indices = self.grep_param_names("|".join(names)) N = len(names) if not N: return "This object has no free parameters." header = ['Name', 'Value', 'Constraints', 'Ties'] - values = self._get_params()[name_indices] # map(str,self._get_params()) + values = self._get_params() # map(str,self._get_params()) + #values = self._get_params()[name_indices] # map(str,self._get_params()) # sort out the constraints - constraints = [''] * len(self._get_param_names()) + constraints = [''] * len(names) + #constraints = [''] * len(self._get_param_names()) for i, t in zip(self.constrained_indices, self.constraints): for ii in i: constraints[ii] = t.__str__() @@ -368,7 +372,10 @@ class Parameterized(object): for j in tie: 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_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])]) @@ -383,3 +390,77 @@ class Parameterized(object): return ('\n'.join([header_string[0], separator] + param_string)) + '\n' + + def grep_model(self,regexp): + regexp_indices = self.grep_param_names(regexp) + all_names = self._get_param_names() + + names = [all_names[pj] for pj in regexp_indices] + N = len(names) + + if not N: + return "Match not found." + + header = ['Name', 'Value', 'Constraints', 'Ties'] + all_values = self._get_params() + values = np.array([all_values[pj] for pj in regexp_indices]) + constraints = [''] * len(names) + + _constrained_indices,aux = self._pick_elements(regexp_indices,self.constrained_indices) + _constraints = [self.constraints[pj] for pj in aux] + + for i, t in zip(_constrained_indices, _constraints): + for ii in i: + iii = regexp_indices.tolist().index(ii) + constraints[iii] = t.__str__() + + _fixed_indices,aux = self._pick_elements(regexp_indices,self.fixed_indices) + for i in _fixed_indices: + for ii in i: + iii = regexp_indices.tolist().index(ii) + constraints[ii] = 'Fixed' + + _tied_indices,aux = self._pick_elements(regexp_indices,self.tied_indices) + ties = [''] * len(names) + for i,ti in zip(_tied_indices,aux): + for ii in i: + iii = regexp_indices.tolist().index(ii) + ties[iii] = '(' + str(ti) + ')' + + 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_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_ties = max([len(ties[i]) for i in range(len(ties))] + [len(header[3])]) + cols = np.array([max_names, max_values, max_constraint, max_ties]) + 4 + + header_string = ["{h:^{col}}".format(h=header[i], col=cols[i]) for i in range(len(cols))] + header_string = map(lambda x: '|'.join(x), [header_string]) + separator = '-' * len(header_string[0]) + param_string = ["{n:^{c0}}|{v:^{c1}}|{c:^{c2}}|{t:^{c3}}".format(n=names[i], v=values[i], c=constraints[i], t=ties[i], c0=cols[0], c1=cols[1], c2=cols[2], c3=cols[3]) for i in range(len(values))] + + print header_string[0] + print separator + for string in param_string: + print string + + def _pick_elements(self,regexp_ind,array_list): + """Removes from array_list the elements different from regexp_ind""" + new_array_list = [] #New list with elements matching regexp_ind + array_indices = [] #Indices that matches the arrays in new_array_list and array_list + + array_index = 0 + for array in array_list: + _new = [] + for ai in array: + if ai in regexp_ind: + _new.append(ai) + if len(_new): + new_array_list.append(np.array(_new)) + array_indices.append(array_index) + array_index += 1 + return new_array_list, array_indices diff --git a/GPy/core/sparse_gp.py b/GPy/core/sparse_gp.py index 7085c2fc..31d2c695 100644 --- a/GPy/core/sparse_gp.py +++ b/GPy/core/sparse_gp.py @@ -165,13 +165,17 @@ class SparseGP(GPBase): raise NotImplementedError, "heteroscedatic derivates with uncertain inputs not implemented" else: + + LBi = chol_inv(self.LB) Lmi_psi1, nil = dtrtrs(self._Lm, np.asfortranarray(self.psi1.T), lower=1, trans=0) _LBi_Lmi_psi1, _ = dtrtrs(self.LB, np.asfortranarray(Lmi_psi1), lower=1, trans=0) - _Bi_Lmi_psi1, _ = dtrtrs(self.LB.T, np.asfortranarray(_LBi_Lmi_psi1), lower=1, trans=0) + self.partial_for_likelihood = -0.5 * self.likelihood.precision + 0.5 * self.likelihood.V**2 self.partial_for_likelihood += 0.5 * self.output_dim * (self.psi0 - np.sum(Lmi_psi1**2,0))[:,None] * self.likelihood.precision**2 - self.partial_for_likelihood += 0.5*np.sum(_Bi_Lmi_psi1*Lmi_psi1,0)[:,None]*self.likelihood.precision**2 #NOTE this term has numerical issues + + self.partial_for_likelihood += 0.5*np.sum(mdot(LBi.T,LBi,Lmi_psi1)*Lmi_psi1,0)[:,None]*self.likelihood.precision**2 + self.partial_for_likelihood += -np.dot(self._LBi_Lmi_psi1Vf.T,_LBi_Lmi_psi1).T * self.likelihood.Y * self.likelihood.precision**2 self.partial_for_likelihood += 0.5*np.dot(self._LBi_Lmi_psi1Vf.T,_LBi_Lmi_psi1).T**2 * self.likelihood.precision**2 @@ -208,8 +212,8 @@ class SparseGP(GPBase): return sum([['iip_%i_%i' % (i, j) for j in range(self.Z.shape[1])] for i in range(self.Z.shape[0])], [])\ + self.kern._get_param_names_transformed() + self.likelihood._get_param_names() - def _get_print_names(self): - return self.kern._get_param_names_transformed() + self.likelihood._get_param_names() + #def _get_print_names(self): + # return self.kern._get_param_names_transformed() + self.likelihood._get_param_names() def update_likelihood_approximation(self): """ @@ -254,7 +258,7 @@ class SparseGP(GPBase): """ The derivative of the bound wrt the inducing inputs Z """ - dL_dZ = self.kern.dK_dX(self.dL_dKmm, self.Z) + dL_dZ = self.kern.dK_dX(self.dL_dKmm, self.Z) if self.has_uncertain_inputs: dL_dZ += self.kern.dpsi1_dZ(self.dL_dpsi1, self.Z, self.X, self.X_variance) dL_dZ += self.kern.dpsi2_dZ(self.dL_dpsi2, self.Z, self.X, self.X_variance) @@ -288,7 +292,7 @@ class SparseGP(GPBase): Kxx = self.kern.Kdiag(Xnew, which_parts=which_parts) var = Kxx - np.sum(Kx * np.dot(Kmmi_LmiBLmi, Kx), 0) else: - # assert which_p.Tarts=='all', "swithching out parts of variational kernels is not implemented" + # assert which_parts=='all', "swithching out parts of variational kernels is not implemented" Kx = self.kern.psi1(self.Z, Xnew, X_variance_new) # , which_parts=which_parts) TODO: which_parts mu = np.dot(Kx, self.Cpsi1V) if full_cov: @@ -344,38 +348,45 @@ class SparseGP(GPBase): which_data = slice(None) GPBase.plot(self, samples=0, plot_limits=plot_limits, which_data='all', which_parts='all', resolution=None, levels=20, ax=ax, output=output) - if self.X.shape[1] == 1 and not hasattr(self,'multioutput'): - if self.has_uncertain_inputs: - Xu = self.X * self._Xscale + self._Xoffset # NOTE self.X are the normalized values now - ax.errorbar(Xu[which_data, 0], self.likelihood.data[which_data, 0], - xerr=2 * np.sqrt(self.X_variance[which_data, 0]), - ecolor='k', fmt=None, elinewidth=.5, alpha=.5) - Zu = self.Z * self._Xscale + self._Xoffset - ax.plot(Zu, np.zeros_like(Zu) + ax.get_ylim()[0], 'r|', mew=1.5, markersize=12) - elif self.X.shape[1] == 2 and not hasattr(self,'multioutput'): - Zu = self.Z * self._Xscale + self._Xoffset - ax.plot(Zu[:, 0], Zu[:, 1], 'wo') + if not hasattr(self,'multioutput'): - elif self.X.shape[1] == 2 and hasattr(self,'multioutput'): - Xu = self.X[self.X[:,-1]==output,:] - if self.has_uncertain_inputs: - Xu = self.X * self._Xscale + self._Xoffset # NOTE self.X are the normalized values now + if self.X.shape[1] == 1: + if self.has_uncertain_inputs: + Xu = self.X * self._Xscale + self._Xoffset # NOTE self.X are the normalized values now + ax.errorbar(Xu[which_data, 0], self.likelihood.data[which_data, 0], + xerr=2 * np.sqrt(self.X_variance[which_data, 0]), + ecolor='k', fmt=None, elinewidth=.5, alpha=.5) + Zu = self.Z * self._Xscale + self._Xoffset + ax.plot(Zu, np.zeros_like(Zu) + ax.get_ylim()[0], 'r|', mew=1.5, markersize=12) - Xu = self.X[self.X[:,-1]==output ,0:1] #?? - - ax.errorbar(Xu[which_data, 0], self.likelihood.data[which_data, 0], - xerr=2 * np.sqrt(self.X_variance[which_data, 0]), - ecolor='k', fmt=None, elinewidth=.5, alpha=.5) - - Zu = self.Z[self.Z[:,-1]==output,:] - Zu = self.Z * self._Xscale + self._Xoffset - Zu = self.Z[self.Z[:,-1]==output ,0:1] #?? - ax.plot(Zu, np.zeros_like(Zu) + ax.get_ylim()[0], 'r|', mew=1.5, markersize=12) - #ax.set_ylim(ax.get_ylim()[0],) + elif self.X.shape[1] == 2: + Zu = self.Z * self._Xscale + self._Xoffset + ax.plot(Zu[:, 0], Zu[:, 1], 'wo') else: - raise NotImplementedError, "Cannot define a frame with more than two input dimensions" + pass + """ + if self.X.shape[1] == 2 and hasattr(self,'multioutput'): + Xu = self.X[self.X[:,-1]==output,:] + if self.has_uncertain_inputs: + Xu = self.X * self._Xscale + self._Xoffset # NOTE self.X are the normalized values now + + Xu = self.X[self.X[:,-1]==output ,0:1] #?? + + ax.errorbar(Xu[which_data, 0], self.likelihood.data[which_data, 0], + xerr=2 * np.sqrt(self.X_variance[which_data, 0]), + ecolor='k', fmt=None, elinewidth=.5, alpha=.5) + + Zu = self.Z[self.Z[:,-1]==output,:] + Zu = self.Z * self._Xscale + self._Xoffset + Zu = self.Z[self.Z[:,-1]==output ,0:1] #?? + ax.plot(Zu, np.zeros_like(Zu) + ax.get_ylim()[0], 'r|', mew=1.5, markersize=12) + #ax.set_ylim(ax.get_ylim()[0],) + + else: + raise NotImplementedError, "Cannot define a frame with more than two input dimensions" + """ def predict_single_output(self, Xnew, output=0, which_parts='all', full_cov=False): """ diff --git a/GPy/examples/classification.py b/GPy/examples/classification.py index 77d1982c..88582351 100644 --- a/GPy/examples/classification.py +++ b/GPy/examples/classification.py @@ -166,3 +166,35 @@ def FITC_crescent_data(num_inducing=10, seed=default_seed): print(m) m.plot() return m + + +def toy_heaviside(seed=default_seed): + """ + Simple 1D classification example using a heavy side gp transformation + :param seed : seed value for data generation (default is 4). + :type seed: int + """ + + data = GPy.util.datasets.toy_linear_1d_classification(seed=seed) + Y = data['Y'][:, 0:1] + Y[Y.flatten() == -1] = 0 + + # Model definition + noise_model = GPy.likelihoods.binomial(GPy.likelihoods.noise_models.gp_transformations.Heaviside()) + likelihood = GPy.likelihoods.EP(Y,noise_model) + m = GPy.models.GPClassification(data['X'], likelihood=likelihood) + + # Optimize + m.update_likelihood_approximation() + # Parameters optimization: + m.optimize() + #m.pseudo_EM() + + # Plot + fig, axes = pb.subplots(2,1) + m.plot_f(ax=axes[0]) + m.plot(ax=axes[1]) + print(m) + + return m + diff --git a/GPy/examples/regression.py b/GPy/examples/regression.py index e1727d5f..c6dc1d9f 100644 --- a/GPy/examples/regression.py +++ b/GPy/examples/regression.py @@ -9,9 +9,9 @@ import pylab as pb import numpy as np import GPy -def coregionalisation_toy2(max_iters=100): +def coregionalization_toy2(max_iters=100): """ - A simple demonstration of coregionalisation on two sinusoidal functions. + A simple demonstration of coregionalization on two sinusoidal functions. """ X1 = np.random.rand(50, 1) * 8 X2 = np.random.rand(30, 1) * 5 @@ -40,9 +40,9 @@ def coregionalisation_toy2(max_iters=100): pb.plot(X2[:, 0], Y2[:, 0], 'gx', mew=2) return m -def coregionalisation_toy(max_iters=100): +def coregionalization_toy(max_iters=100): """ - A simple demonstration of coregionalisation on two sinusoidal functions. + A simple demonstration of coregionalization on two sinusoidal functions. """ X1 = np.random.rand(50, 1) * 8 X2 = np.random.rand(30, 1) * 5 @@ -63,9 +63,9 @@ def coregionalisation_toy(max_iters=100): axes[1].set_title('Output 1') return m -def coregionalisation_sparse(max_iters=100): +def coregionalization_sparse(max_iters=100): """ - A simple demonstration of coregionalisation on two sinusoidal functions using sparse approximations. + A simple demonstration of coregionalization on two sinusoidal functions using sparse approximations. """ X1 = np.random.rand(500, 1) * 8 X2 = np.random.rand(300, 1) * 5 @@ -75,41 +75,18 @@ def coregionalisation_sparse(max_iters=100): Y2 = -np.sin(X2) + np.random.randn(*X2.shape) * 0.05 Y = np.vstack((Y1, Y2)) - num_inducing = 40 - Z = np.hstack((np.random.rand(num_inducing, 1) * 8, np.random.randint(0, 2, num_inducing)[:, None])) - Z = np.hstack((np.random.rand(num_inducing, 1) * 8, np.random.randint(0, 2, num_inducing)[:, None])) - k1 = GPy.kern.rbf(1) m = GPy.models.SparseGPMultioutputRegression(X_list=[X1,X2],Y_list=[Y1,Y2],kernel_list=[k1],num_inducing=20) - #k2 = GPy.kern.coregionalize(2, 2) - #k = k1**k2 #.prod(k2, tensor=True) # + GPy.kern.white(2,0.001) - #m = GPy.models.SparseGPRegression(X, Y, kernel=k, Z=Z) - m.constrain_fixed('.*rbf_var', 1.) - - #m.constrain_fixed('iip') - #m.constrain_bounded('noise_variance', 1e-3, 1e-1) -# m.optimize_restarts(5, robust=True, messages=1, max_iters=max_iters, optimizer='bfgs') - m.optimize(max_iters=max_iters) + m.constrain_fixed('.*rbf_var',1.) + m.optimize(messages=1) + #m.optimize_restarts(5, robust=True, messages=1, max_iters=max_iters, optimizer='bfgs') fig, axes = pb.subplots(2,1) m.plot(output=0,ax=axes[0]) m.plot(output=1,ax=axes[1]) axes[0].set_title('Output 0') axes[1].set_title('Output 1') - # plotting: - #pb.figure() - #Xtest1 = np.hstack((np.linspace(0, 9, 100)[:, None], np.zeros((100, 1)))) - #Xtest2 = np.hstack((np.linspace(0, 9, 100)[:, None], np.ones((100, 1)))) - #mean, var, low, up = m.predict(Xtest1) - #GPy.util.plot.gpplot(Xtest1[:, 0], mean, low, up) - #mean, var, low, up = m.predict(Xtest2) - #GPy.util.plot.gpplot(Xtest2[:, 0], mean, low, up) - #pb.plot(X1[:, 0], Y1[:, 0], 'rx', mew=2) - #pb.plot(X2[:, 0], Y2[:, 0], 'gx', mew=2) - #y = pb.ylim()[0] - #pb.plot(Z[:, 0][Z[:, 1] == 0], np.zeros(np.sum(Z[:, 1] == 0)) + y, 'r|', mew=2) - #pb.plot(Z[:, 0][Z[:, 1] == 1], np.zeros(np.sum(Z[:, 1] == 1)) + y, 'g|', mew=2) return m def epomeo_gpx(max_iters=100): @@ -136,7 +113,7 @@ def epomeo_gpx(max_iters=100): k1 = GPy.kern.rbf(1) k2 = GPy.kern.coregionalize(output_dim=5, rank=5) - k = k1**k2 + k = k1**k2 m = GPy.models.SparseGPRegression(t, Y, kernel=k, Z=Z, normalize_Y=True) m.constrain_fixed('.*rbf_var', 1.) diff --git a/GPy/kern/constructors.py b/GPy/kern/constructors.py index f9d7a99a..ce55f197 100644 --- a/GPy/kern/constructors.py +++ b/GPy/kern/constructors.py @@ -373,7 +373,7 @@ def symmetric(k): k_.parts = [symmetric.Symmetric(p) for p in k.parts] return k_ -def coregionalize(output_dim,W_columns=1, W=None, kappa=None): +def coregionalize(output_dim,rank=1, W=None, kappa=None): """ Coregionlization matrix B, of the form: .. math:: @@ -387,16 +387,16 @@ def coregionalize(output_dim,W_columns=1, W=None, kappa=None): :param output_dim: the number of outputs to corregionalize :type output_dim: int - :param W_columns: number of columns of the W matrix (this parameter is ignored if parameter W is not None) - :type W_colunns: int - :param W: a low rank matrix that determines the correlations between the different outputs, together with kappa it forms the coregionalisation matrix B - :type W: numpy array of dimensionality (num_outpus, W_columns) + :param rank: number of columns of the W matrix (this parameter is ignored if parameter W is not None) + :type rank: int + :param W: a low rank matrix that determines the correlations between the different outputs, together with kappa it forms the coregionalization matrix B + :type W: numpy array of dimensionality (num_outpus, rank) :param kappa: a vector which allows the outputs to behave independently :type kappa: numpy array of dimensionality (output_dim,) :rtype: kernel object """ - p = parts.coregionalize.Coregionalize(output_dim,W_columns,W,kappa) + p = parts.coregionalize.Coregionalize(output_dim,rank,W,kappa) return kern(1,[p]) @@ -456,7 +456,7 @@ def hierarchical(k): _parts = [parts.hierarchical.Hierarchical(k.parts)] return kern(k.input_dim+len(k.parts),_parts) -def build_lcm(input_dim, output_dim, kernel_list = [], W_columns=1,W=None,kappa=None): +def build_lcm(input_dim, output_dim, kernel_list = [], rank=1,W=None,kappa=None): """ Builds a kernel of a linear coregionalization model @@ -464,8 +464,8 @@ def build_lcm(input_dim, output_dim, kernel_list = [], W_columns=1,W=None,kappa= :output_dim: Number of outputs :kernel_list: List of coregionalized kernels, each element in the list will be multiplied by a different corregionalization matrix :type kernel_list: list of GPy kernels - :param W_columns: number tuples of the corregionalization parameters 'coregion_W' - :type W_columns: integer + :param rank: number tuples of the corregionalization parameters 'coregion_W' + :type rank: integer ..Note the kernels dimensionality is overwritten to fit input_dim """ @@ -475,11 +475,11 @@ def build_lcm(input_dim, output_dim, kernel_list = [], W_columns=1,W=None,kappa= k.input_dim = input_dim warnings.warn("kernel's input dimension overwritten to fit input_dim parameter.") - k_coreg = coregionalize(output_dim,W_columns,W,kappa) + k_coreg = coregionalize(output_dim,rank,W,kappa) kernel = kernel_list[0]**k_coreg.copy() for k in kernel_list[1:]: - k_coreg = coregionalize(output_dim,W_columns,W,kappa) + k_coreg = coregionalize(output_dim,rank,W,kappa) kernel += k**k_coreg.copy() return kernel diff --git a/GPy/kern/parts/__init__.py b/GPy/kern/parts/__init__.py index fff24d04..888d19c3 100644 --- a/GPy/kern/parts/__init__.py +++ b/GPy/kern/parts/__init__.py @@ -6,7 +6,7 @@ import eq_ode1 import finite_dimensional import fixed import gibbs -import hetero #hetero.py is not commited: omitting for now. JH. +import hetero import hierarchical import independent_outputs import linear diff --git a/GPy/kern/parts/coregionalize.py b/GPy/kern/parts/coregionalize.py index 8e960038..2de1b1bc 100644 --- a/GPy/kern/parts/coregionalize.py +++ b/GPy/kern/parts/coregionalize.py @@ -24,8 +24,8 @@ class Coregionalize(Kernpart): :param output_dim: number of outputs to coregionalize :type output_dim: int - :param W_columns: number of columns of the W matrix (this parameter is ignored if parameter W is not None) - :type W_colunns: int + :param rank: number of columns of the W matrix (this parameter is ignored if parameter W is not None) + :type rank: int :param W: a low rank matrix that determines the correlations between the different outputs, together with kappa it forms the coregionalization matrix B :type W: numpy array of dimensionality (num_outpus, W_columns) :param kappa: a vector which allows the outputs to behave independently @@ -38,6 +38,8 @@ class Coregionalize(Kernpart): self.name = 'coregion' self.output_dim = output_dim self.rank = rank + if self.rank>output_dim-1: + print("Warning: Unusual choice of rank, it should normally be less than the output_dim.") if W is None: self.W = 0.5*np.random.randn(self.output_dim,self.rank)/np.sqrt(self.rank) else: @@ -158,4 +160,5 @@ class Coregionalize(Kernpart): target += np.hstack([dW.flatten(),dkappa]) def dK_dX(self,dL_dK,X,X2,target): + #NOTE In this case, pass is equivalent to returning zero. pass diff --git a/GPy/kern/parts/poly.py b/GPy/kern/parts/poly.py index cdc65210..3719f412 100644 --- a/GPy/kern/parts/poly.py +++ b/GPy/kern/parts/poly.py @@ -20,8 +20,8 @@ class POLY(Kernpart): The kernel is not recommended as it is badly behaved when the \sigma^2_w*x'*y + \sigma^2_b has a magnitude greater than one. For completeness - there is an automatic relevance determination version of this - kernel provided. + there will be an automatic relevance determination version of this + kernel provided (NOT YET IMPLEMENTED!). :param input_dim: the number of input dimensions :type input_dim: int diff --git a/GPy/kern/parts/prod.py b/GPy/kern/parts/prod.py index dd8ed7c8..0549ea22 100644 --- a/GPy/kern/parts/prod.py +++ b/GPy/kern/parts/prod.py @@ -2,6 +2,7 @@ # Licensed under the BSD 3-clause license (see LICENSE.txt) from kernpart import Kernpart +from coregionalize import Coregionalize import numpy as np import hashlib @@ -18,7 +19,7 @@ class Prod(Kernpart): """ def __init__(self,k1,k2,tensor=False): self.num_params = k1.num_params + k2.num_params - self.name = '['+k1.name + '(x)' + k2.name +']' + self.name = '['+k1.name + '**' + k2.name +']' self.k1 = k1 self.k2 = k2 if tensor: @@ -60,7 +61,7 @@ class Prod(Kernpart): """Compute the part of the kernel associated with k2.""" self._K_computations(X, X2) return self._K2 - + def dK_dtheta(self,dL_dK,X,X2,target): """Derivative of the covariance matrix with respect to the parameters.""" self._K_computations(X,X2) @@ -90,8 +91,18 @@ class Prod(Kernpart): def dK_dX(self,dL_dK,X,X2,target): """derivative of the covariance matrix with respect to X.""" self._K_computations(X,X2) - self.k1.dK_dX(dL_dK*self._K2, X[:,self.slice1], X2[:,self.slice1], target[:,self.slice1]) - self.k2.dK_dX(dL_dK*self._K1, X[:,self.slice2], X2[:,self.slice2], target[:,self.slice2]) + if X2 is None: + if not isinstance(self.k1,Coregionalize) and not isinstance(self.k2,Coregionalize): + self.k1.dK_dX(dL_dK*self._K2, X[:,self.slice1], None, target[:,self.slice1]) + self.k2.dK_dX(dL_dK*self._K1, X[:,self.slice2], None, target[:,self.slice2]) + else:#if isinstance(self.k1,Coregionalize) or isinstance(self.k2,Coregionalize): + #NOTE The indices column in the inputs makes the ki.dK_dX fail when passing None instead of X[:,self.slicei] + X2 = X + self.k1.dK_dX(2.*dL_dK*self._K2, X[:,self.slice1], X2[:,self.slice1], target[:,self.slice1]) + self.k2.dK_dX(2.*dL_dK*self._K1, X[:,self.slice2], X2[:,self.slice2], target[:,self.slice2]) + else: + self.k1.dK_dX(dL_dK*self._K2, X[:,self.slice1], X2[:,self.slice1], target[:,self.slice1]) + self.k2.dK_dX(dL_dK*self._K1, X[:,self.slice2], X2[:,self.slice2], target[:,self.slice2]) def dKdiag_dX(self, dL_dKdiag, X, target): K1 = np.zeros(X.shape[0]) diff --git a/GPy/kern/parts/rational_quadratic.py b/GPy/kern/parts/rational_quadratic.py index 61473f9c..a75a5b11 100644 --- a/GPy/kern/parts/rational_quadratic.py +++ b/GPy/kern/parts/rational_quadratic.py @@ -57,7 +57,7 @@ class RationalQuadratic(Kernpart): dist2 = np.square((X-X2.T)/self.lengthscale) dvar = (1 + dist2/2.)**(-self.power) - dl = self.power * self.variance * dist2 * self.lengthscale**(-3) * (1 + dist2/2./self.power)**(-self.power-1) + dl = self.power * self.variance * dist2 / self.lengthscale * (1 + dist2/2.)**(-self.power-1) dp = - self.variance * np.log(1 + dist2/2.) * (1 + dist2/2.)**(-self.power) target[0] += np.sum(dvar*dL_dK) @@ -70,7 +70,7 @@ class RationalQuadratic(Kernpart): def dK_dX(self,dL_dK,X,X2,target): """derivative of the covariance matrix with respect to X.""" - if X2 is None: + if X2 is None: dist2 = np.square((X-X.T)/self.lengthscale) dX = -2.*self.variance*self.power * (X-X.T)/self.lengthscale**2 * (1 + dist2/2./self.lengthscale)**(-self.power-1) else: diff --git a/GPy/likelihoods/ep.py b/GPy/likelihoods/ep.py index c9f23839..9a816e65 100644 --- a/GPy/likelihoods/ep.py +++ b/GPy/likelihoods/ep.py @@ -37,6 +37,8 @@ class EP(likelihood): self.VVT_factor = self.V self.trYYT = 0. + super(EP, self).__init__() + def restart(self): self.tau_tilde = np.zeros(self.N) self.v_tilde = np.zeros(self.N) diff --git a/GPy/likelihoods/gaussian.py b/GPy/likelihoods/gaussian.py index cdf54dd6..8f66d074 100644 --- a/GPy/likelihoods/gaussian.py +++ b/GPy/likelihoods/gaussian.py @@ -34,6 +34,8 @@ class Gaussian(likelihood): self._variance = np.asarray(variance) + 1. self._set_params(np.asarray(variance)) + super(Gaussian, self).__init__() + def set_data(self, data): self.data = data self.N, D = data.shape diff --git a/GPy/likelihoods/gaussian_mixed_noise.py b/GPy/likelihoods/gaussian_mixed_noise.py index e7df2584..4df01ec2 100644 --- a/GPy/likelihoods/gaussian_mixed_noise.py +++ b/GPy/likelihoods/gaussian_mixed_noise.py @@ -45,6 +45,8 @@ class Gaussian_Mixed_Noise(likelihood): self.set_data(data_list) self._set_params(np.asarray(noise_params)) + super(Gaussian_Mixed_Noise, self).__init__() + def set_data(self, data_list): self.data = np.vstack(data_list) self.N, D = self.data.shape diff --git a/GPy/likelihoods/likelihood.py b/GPy/likelihoods/likelihood.py index d073ba6e..cda62bfc 100644 --- a/GPy/likelihoods/likelihood.py +++ b/GPy/likelihoods/likelihood.py @@ -1,7 +1,8 @@ import numpy as np import copy +from ..core.parameterized import Parameterized -class likelihood: +class likelihood(Parameterized): """ The atom for a likelihood class @@ -16,10 +17,10 @@ class likelihood: self.is_heteroscedastic : enables significant computational savings in GP 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.V : self.precision * self.Y + self.V : self.precision * self.Y """ - def __init__(self,data): - raise ValueError, "this class is not to be instantiated" + def __init__(self): + Parameterized.__init__(self) def _get_params(self): raise NotImplementedError @@ -38,7 +39,3 @@ class likelihood: def predictive_values(self, mu, var): raise NotImplementedError - - def copy(self): - """ Returns a (deep) copy of the current likelihood """ - return copy.deepcopy(self) diff --git a/GPy/likelihoods/noise_model_constructors.py b/GPy/likelihoods/noise_model_constructors.py index 158f1674..ec971e04 100644 --- a/GPy/likelihoods/noise_model_constructors.py +++ b/GPy/likelihoods/noise_model_constructors.py @@ -19,7 +19,7 @@ def binomial(gp_link=None): analytical_mean = True analytical_variance = False - elif isinstance(gp_link,noise_models.gp_transformations.Step): + elif isinstance(gp_link,noise_models.gp_transformations.Heaviside): analytical_mean = True analytical_variance = True @@ -42,7 +42,7 @@ def exponential(gp_link=None): analytical_variance = False return noise_models.exponential_noise.Exponential(gp_link,analytical_mean,analytical_variance) -def gaussian(gp_link=None,variance=1.): +def gaussian_ep(gp_link=None,variance=1.): """ Construct a gaussian likelihood diff --git a/GPy/likelihoods/noise_models/binomial_noise.py b/GPy/likelihoods/noise_models/binomial_noise.py index 9ceacf79..256eaa3c 100644 --- a/GPy/likelihoods/noise_models/binomial_noise.py +++ b/GPy/likelihoods/noise_models/binomial_noise.py @@ -49,15 +49,30 @@ class Binomial(NoiseDistribution): mu_hat = v_i/tau_i + data_i*phi/(Z_hat*np.sqrt(tau_i**2 + tau_i)) sigma2_hat = 1./tau_i - (phi/((tau_i**2+tau_i)*Z_hat))*(z+phi/Z_hat) - elif isinstance(self.gp_link,gp_transformations.Step): - Z_hat = None - mu_hat = None - sigma2_hat = None + elif isinstance(self.gp_link,gp_transformations.Heaviside): + a = data_i*v_i/np.sqrt(tau_i) + Z_hat = std_norm_cdf(a) + N = std_norm_pdf(a) + mu_hat = v_i/tau_i + data_i*N/Z_hat/np.sqrt(tau_i) + sigma2_hat = (1. - a*N/Z_hat - np.square(N/Z_hat))/tau_i + if np.any(np.isnan([Z_hat, mu_hat, sigma2_hat])): + stop return Z_hat, mu_hat, sigma2_hat def _predictive_mean_analytical(self,mu,sigma): - return stats.norm.cdf(mu/np.sqrt(1+sigma**2)) + if isinstance(self.gp_link,gp_transformations.Probit): + return stats.norm.cdf(mu/np.sqrt(1+sigma**2)) + elif isinstance(self.gp_link,gp_transformations.Heaviside): + return stats.norm.cdf(mu/sigma) + else: + raise NotImplementedError + + def _predictive_variance_analytical(self,mu,sigma, pred_mean): + if isinstance(self.gp_link,gp_transformations.Heaviside): + return 0. + else: + raise NotImplementedError def _mass(self,gp,obs): #NOTE obs must be in {0,1} diff --git a/GPy/likelihoods/noise_models/gp_transformations.py b/GPy/likelihoods/noise_models/gp_transformations.py index 5f337aa4..ccf965d9 100644 --- a/GPy/likelihoods/noise_models/gp_transformations.py +++ b/GPy/likelihoods/noise_models/gp_transformations.py @@ -108,7 +108,7 @@ class Reciprocal(GPTransformation): def d2transf_df2(self,f): return 2./f**3 -class Step(GPTransformation): +class Heaviside(GPTransformation): """ $$ g(f) = I_{x \in A} @@ -116,10 +116,10 @@ class Step(GPTransformation): """ def transf(self,f): #transformation goes here - return np.where(f>0, 1, -1) + return np.where(f>0, 1, 0) def dtransf_df(self,f): - pass + raise NotImplementedError, "This function is not differentiable!" def d2transf_df2(self,f): - pass + raise NotImplementedError, "This function is not differentiable!" diff --git a/GPy/likelihoods/noise_models/noise_distributions.py b/GPy/likelihoods/noise_models/noise_distributions.py index 9d4eedfb..4fd9c97f 100644 --- a/GPy/likelihoods/noise_models/noise_distributions.py +++ b/GPy/likelihoods/noise_models/noise_distributions.py @@ -107,7 +107,7 @@ class NoiseDistribution(object): :param mu: cavity distribution mean :param sigma: cavity distribution standard deviation """ - return sp.optimize.fmin_ncg(self._nlog_product_scaled,x0=mu,fprime=self._dnlog_product_dgp,fhess=self._d2nlog_product_dgp2,args=(obs,mu,sigma)) + return sp.optimize.fmin_ncg(self._nlog_product_scaled,x0=mu,fprime=self._dnlog_product_dgp,fhess=self._d2nlog_product_dgp2,args=(obs,mu,sigma),disp=False) def _moments_match_analytical(self,obs,tau,v): """ @@ -244,7 +244,7 @@ class NoiseDistribution(object): :param mu: cavity distribution mean :param sigma: cavity distribution standard deviation """ - maximum = sp.optimize.fmin_ncg(self._nlog_conditional_mean_scaled,x0=self._mean(mu),fprime=self._dnlog_conditional_mean_dgp,fhess=self._d2nlog_conditional_mean_dgp2,args=(mu,sigma)) + maximum = sp.optimize.fmin_ncg(self._nlog_conditional_mean_scaled,x0=self._mean(mu),fprime=self._dnlog_conditional_mean_dgp,fhess=self._d2nlog_conditional_mean_dgp2,args=(mu,sigma),disp=False) mean = np.exp(-self._nlog_conditional_mean_scaled(maximum,mu,sigma))/(np.sqrt(self._d2nlog_conditional_mean_dgp2(maximum,mu,sigma))*sigma) """ @@ -267,7 +267,7 @@ class NoiseDistribution(object): :param mu: cavity distribution mean :param sigma: cavity distribution standard deviation """ - maximum = sp.optimize.fmin_ncg(self._nlog_exp_conditional_mean_sq_scaled,x0=self._mean(mu),fprime=self._dnlog_exp_conditional_mean_sq_dgp,fhess=self._d2nlog_exp_conditional_mean_sq_dgp2,args=(mu,sigma)) + maximum = sp.optimize.fmin_ncg(self._nlog_exp_conditional_mean_sq_scaled,x0=self._mean(mu),fprime=self._dnlog_exp_conditional_mean_sq_dgp,fhess=self._d2nlog_exp_conditional_mean_sq_dgp2,args=(mu,sigma),disp=False) mean_squared = np.exp(-self._nlog_exp_conditional_mean_sq_scaled(maximum,mu,sigma))/(np.sqrt(self._d2nlog_exp_conditional_mean_sq_dgp2(maximum,mu,sigma))*sigma) return mean_squared @@ -280,7 +280,7 @@ class NoiseDistribution(object): :predictive_mean: output's predictive mean, if None _predictive_mean function will be called. """ # E( V(Y_star|f_star) ) - maximum = sp.optimize.fmin_ncg(self._nlog_exp_conditional_variance_scaled,x0=self._variance(mu),fprime=self._dnlog_exp_conditional_variance_dgp,fhess=self._d2nlog_exp_conditional_variance_dgp2,args=(mu,sigma)) + maximum = sp.optimize.fmin_ncg(self._nlog_exp_conditional_variance_scaled,x0=self._variance(mu),fprime=self._dnlog_exp_conditional_variance_dgp,fhess=self._d2nlog_exp_conditional_variance_dgp2,args=(mu,sigma),disp=False) exp_var = np.exp(-self._nlog_exp_conditional_variance_scaled(maximum,mu,sigma))/(np.sqrt(self._d2nlog_exp_conditional_variance_dgp2(maximum,mu,sigma))*sigma) """ @@ -357,7 +357,7 @@ class NoiseDistribution(object): :param mu: latent variable's predictive mean :param sigma: latent variable's predictive standard deviation """ - return sp.optimize.fmin_ncg(self._nlog_joint_predictive_scaled,x0=(mu,self.gp_link.transf(mu)),fprime=self._gradient_nlog_joint_predictive,fhess=self._hessian_nlog_joint_predictive,args=(mu,sigma)) + return sp.optimize.fmin_ncg(self._nlog_joint_predictive_scaled,x0=(mu,self.gp_link.transf(mu)),fprime=self._gradient_nlog_joint_predictive,fhess=self._hessian_nlog_joint_predictive,args=(mu,sigma),disp=False) def predictive_values(self,mu,var): """ diff --git a/GPy/models/bayesian_gplvm.py b/GPy/models/bayesian_gplvm.py index ae74e5f2..e094d915 100644 --- a/GPy/models/bayesian_gplvm.py +++ b/GPy/models/bayesian_gplvm.py @@ -8,7 +8,7 @@ from .. import kern import itertools from matplotlib.colors import colorConverter from GPy.inference.optimization import SCG -from GPy.util import plot_latent +from GPy.util import plot_latent, linalg from GPy.models.gplvm import GPLVM from GPy.util.plot_latent import most_significant_input_dimensions from matplotlib import pyplot @@ -66,8 +66,8 @@ class BayesianGPLVM(SparseGP, GPLVM): S_names = sum([['X_variance_%i_%i' % (n, q) for q in range(self.input_dim)] for n in range(self.num_data)], []) return (X_names + S_names + SparseGP._get_param_names(self)) - def _get_print_names(self): - return SparseGP._get_print_names(self) + #def _get_print_names(self): + # return SparseGP._get_print_names(self) def _get_params(self): """ @@ -140,12 +140,20 @@ class BayesianGPLVM(SparseGP, GPLVM): dpsi0 = -0.5 * self.input_dim * self.likelihood.precision dpsi2 = self.dL_dpsi2[0][None, :, :] # TODO: this may change if we ignore het. likelihoods V = self.likelihood.precision * Y + + #compute CPsi1V + if self.Cpsi1V is None: + psi1V = np.dot(self.psi1.T, self.likelihood.V) + tmp, _ = linalg.dtrtrs(self._Lm, np.asfortranarray(psi1V), lower=1, trans=0) + tmp, _ = linalg.dpotrs(self.LB, tmp, lower=1) + self.Cpsi1V, _ = linalg.dtrtrs(self._Lm, tmp, lower=1, trans=1) + dpsi1 = np.dot(self.Cpsi1V, V.T) start = np.zeros(self.input_dim * 2) for n, dpsi1_n in enumerate(dpsi1.T[:, :, None]): - args = (self.kern, self.Z, dpsi0, dpsi1_n, dpsi2) + args = (self.kern, self.Z, dpsi0, dpsi1_n.T, dpsi2) xopt, fopt, neval, status = SCG(f=latent_cost, gradf=latent_grad, x=start, optargs=args, display=False) mu, log_S = xopt.reshape(2, 1, -1) diff --git a/GPy/models/gp_classification.py b/GPy/models/gp_classification.py index 73d492fe..fce51cfa 100644 --- a/GPy/models/gp_classification.py +++ b/GPy/models/gp_classification.py @@ -14,7 +14,7 @@ class GPClassification(GP): This is a thin wrapper around the models.GP class, with a set of sensible defaults :param X: input observations - :param Y: observed values + :param Y: observed values, can be None if likelihood is not None :param likelihood: a GPy likelihood, defaults to Binomial with probit link_function :param kernel: a GPy kernel, defaults to rbf :param normalize_X: whether to normalize the input data before computing (predictions will be in original scales) diff --git a/GPy/models/gp_multioutput_regression.py b/GPy/models/gp_multioutput_regression.py index d51f3bae..20d839ce 100644 --- a/GPy/models/gp_multioutput_regression.py +++ b/GPy/models/gp_multioutput_regression.py @@ -6,7 +6,6 @@ import numpy as np from ..core import GP from .. import likelihoods from .. import kern -#from ..util import multioutput class GPMultioutputRegression(GP): """ diff --git a/GPy/models/mrd.py b/GPy/models/mrd.py index 4c7fa167..99e50a19 100644 --- a/GPy/models/mrd.py +++ b/GPy/models/mrd.py @@ -25,11 +25,11 @@ class MRD(Model): :param input_dim: latent dimensionality :type input_dim: int :param initx: initialisation method for the latent space : - + * 'concat' - PCA on concatenation of all datasets * 'single' - Concatenation of PCA on datasets, respectively * 'random' - Random draw from a normal - + :type initx: ['concat'|'single'|'random'] :param initz: initialisation method for inducing inputs :type initz: 'permute'|'random' @@ -163,28 +163,31 @@ class MRD(Model): self._init_X(initx, self.likelihood_list) self._init_Z(initz, self.X) - def _get_latent_param_names(self): + #def _get_latent_param_names(self): + def _get_param_names(self): n1 = self.gref._get_param_names() n1var = n1[:self.NQ * 2 + self.MQ] - return n1var - - - def _get_kernel_names(self): + # return n1var + # + #def _get_kernel_names(self): map_names = lambda ns, name: map(lambda x: "{1}_{0}".format(*x), itertools.izip(ns, itertools.repeat(name))) - kernel_names = (map_names(SparseGP._get_param_names(g)[self.MQ:], n) for g, n in zip(self.bgplvms, self.names)) - return kernel_names + return list(itertools.chain(n1var, *(map_names(\ + SparseGP._get_param_names(g)[self.MQ:], n) \ + for g, n in zip(self.bgplvms, self.names)))) + # kernel_names = (map_names(SparseGP._get_param_names(g)[self.MQ:], n) for g, n in zip(self.bgplvms, self.names)) + # return kernel_names - def _get_param_names(self): + #def _get_param_names(self): # X_names = sum([['X_%i_%i' % (n, q) for q in range(self.input_dim)] for n in range(self.num_data)], []) # S_names = sum([['X_variance_%i_%i' % (n, q) for q in range(self.input_dim)] for n in range(self.num_data)], []) - n1var = self._get_latent_param_names() - kernel_names = self._get_kernel_names() - return list(itertools.chain(n1var, *kernel_names)) + # n1var = self._get_latent_param_names() + # kernel_names = self._get_kernel_names() + # return list(itertools.chain(n1var, *kernel_names)) - def _get_print_names(self): - return list(itertools.chain(*self._get_kernel_names())) + #def _get_print_names(self): + # return list(itertools.chain(*self._get_kernel_names())) def _get_params(self): """ diff --git a/GPy/testing/kernel_tests.py b/GPy/testing/kernel_tests.py index 12fdaf33..e67649f4 100644 --- a/GPy/testing/kernel_tests.py +++ b/GPy/testing/kernel_tests.py @@ -4,7 +4,7 @@ import unittest import numpy as np import GPy - + verbose = False class KernelTests(unittest.TestCase): @@ -18,11 +18,11 @@ class KernelTests(unittest.TestCase): self.assertTrue(m.checkgrad()) def test_rbfkernel(self): - kern = GPy.kern.rbf(5) + kern = GPy.kern.rbf(5) self.assertTrue(GPy.kern.kern_test(kern, verbose=verbose)) def test_rbf_invkernel(self): - kern = GPy.kern.rbf_inv(5) + kern = GPy.kern.rbf_inv(5) self.assertTrue(GPy.kern.kern_test(kern, verbose=verbose)) def test_Matern32kernel(self): @@ -79,7 +79,7 @@ class KernelTests(unittest.TestCase): kern = GPy.kern.poly(5, degree=4) self.assertTrue(GPy.kern.kern_test(kern, verbose=verbose)) - def test_coregionalisation(self): + def test_coregionalization(self): X1 = np.random.rand(50,1)*8 X2 = np.random.rand(30,1)*5 index = np.vstack((np.zeros_like(X1),np.ones_like(X2))) diff --git a/GPy/util/__init__.py b/GPy/util/__init__.py index c205548b..99548268 100644 --- a/GPy/util/__init__.py +++ b/GPy/util/__init__.py @@ -14,4 +14,3 @@ import visualize import decorators import classification import latent_space_visualizations -#import multioutput diff --git a/GPy/util/linalg.py b/GPy/util/linalg.py index 19cf6545..1effa9ce 100644 --- a/GPy/util/linalg.py +++ b/GPy/util/linalg.py @@ -51,7 +51,7 @@ def dpotri(A, lower=0): :param A: Matrix A :param lower: is matrix lower (true) or upper (false) - :returns: + :returns: A inverse """ return lapack.dpotri(A, lower=lower) diff --git a/README.md b/README.md index 09bc78f5..0ff3d890 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,57 @@ GPy === -A Gaussian processes framework in python +A Gaussian processes framework in Python. * [Online documentation](https://gpy.readthedocs.org/en/latest/) * [Unit tests (Travis-CI)](https://travis-ci.org/SheffieldML/GPy) Continuous integration status: ![CI status](https://travis-ci.org/SheffieldML/GPy.png) + + +Compiling documentation: +======================== + +The documentation is stored in doc/ and is compiled with the Sphinx Python documentation generator, and is written in the reStructuredText format. + +The Sphinx documentation is available here: http://sphinx-doc.org/latest/contents.html + + +Installing dependencies: +------------------------ + +To compile the documentation, first ensure that Sphinx is installed. On Debian-based systems, this can be achieved as follows: + + sudo apt-get install python-pip + sudo pip install sphinx + +A LaTeX distribution is also required to compile the equations. Note that the extra packages are necessary to install the unicode packages. To compile the equations to PNG format for use in HTML pages, the package *dvipng* must be installed. IPython is also required. On Debian-based systems, this can be achieved as follows: + + sudo apt-get install texlive texlive-latex-extra texlive-base texlive-recommended + sudo apt-get install dvipng + sudo apt-get install ipython + + +Compiling documentation: +------------------------ + +The documentation can be compiled as follows: + + cd doc + make html + +The HTML files are then stored in doc/_build/ + + +Running unit tests: +=================== + +Ensure nose is installed via pip: + + pip install nose + +Run nosetests from the root directory of the repository: + + nosetests -v + diff --git a/doc/GPy.core.rst b/doc/GPy.core.rst index 0590450f..c4f1849d 100644 --- a/doc/GPy.core.rst +++ b/doc/GPy.core.rst @@ -1,91 +1,102 @@ -core Package -============ +GPy.core package +================ -:mod:`core` Package -------------------- +Submodules +---------- -.. automodule:: GPy.core - :members: - :undoc-members: - :show-inheritance: - -:mod:`domains` Module ---------------------- +GPy.core.domains module +----------------------- .. automodule:: GPy.core.domains :members: :undoc-members: :show-inheritance: -:mod:`fitc` Module ------------------- +GPy.core.fitc module +-------------------- .. automodule:: GPy.core.fitc :members: :undoc-members: :show-inheritance: -:mod:`gp` Module ----------------- +GPy.core.gp module +------------------ .. automodule:: GPy.core.gp :members: :undoc-members: :show-inheritance: -:mod:`gp_base` Module ---------------------- +GPy.core.gp_base module +----------------------- .. automodule:: GPy.core.gp_base :members: :undoc-members: :show-inheritance: -:mod:`model` Module -------------------- +GPy.core.mapping module +----------------------- + +.. automodule:: GPy.core.mapping + :members: + :undoc-members: + :show-inheritance: + +GPy.core.model module +--------------------- .. automodule:: GPy.core.model :members: :undoc-members: :show-inheritance: -:mod:`parameterized` Module ---------------------------- +GPy.core.parameterized module +----------------------------- .. automodule:: GPy.core.parameterized :members: :undoc-members: :show-inheritance: -:mod:`priors` Module --------------------- +GPy.core.priors module +---------------------- .. automodule:: GPy.core.priors :members: :undoc-members: :show-inheritance: -:mod:`sparse_gp` Module ------------------------ +GPy.core.sparse_gp module +------------------------- .. automodule:: GPy.core.sparse_gp :members: :undoc-members: :show-inheritance: -:mod:`svigp` Module -------------------- +GPy.core.svigp module +--------------------- .. automodule:: GPy.core.svigp :members: :undoc-members: :show-inheritance: -:mod:`transformations` Module ------------------------------ +GPy.core.transformations module +------------------------------- .. automodule:: GPy.core.transformations :members: :undoc-members: :show-inheritance: + +Module contents +--------------- + +.. automodule:: GPy.core + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/GPy.examples.rst b/doc/GPy.examples.rst index fedfd4b9..4fd3528f 100644 --- a/doc/GPy.examples.rst +++ b/doc/GPy.examples.rst @@ -1,51 +1,54 @@ -examples Package -================ +GPy.examples package +==================== -:mod:`examples` Package ------------------------ +Submodules +---------- -.. automodule:: GPy.examples - :members: - :undoc-members: - :show-inheritance: - -:mod:`classification` Module ----------------------------- +GPy.examples.classification module +---------------------------------- .. automodule:: GPy.examples.classification :members: :undoc-members: :show-inheritance: -:mod:`dimensionality_reduction` Module --------------------------------------- +GPy.examples.dimensionality_reduction module +-------------------------------------------- .. automodule:: GPy.examples.dimensionality_reduction :members: :undoc-members: :show-inheritance: -:mod:`regression` Module ------------------------- +GPy.examples.regression module +------------------------------ .. automodule:: GPy.examples.regression :members: :undoc-members: :show-inheritance: -:mod:`stochastic` Module ------------------------- +GPy.examples.stochastic module +------------------------------ .. automodule:: GPy.examples.stochastic :members: :undoc-members: :show-inheritance: -:mod:`tutorials` Module ------------------------ +GPy.examples.tutorials module +----------------------------- .. automodule:: GPy.examples.tutorials :members: :undoc-members: :show-inheritance: + +Module contents +--------------- + +.. automodule:: GPy.examples + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/GPy.inference.rst b/doc/GPy.inference.rst index 6a1bef4a..28f42994 100644 --- a/doc/GPy.inference.rst +++ b/doc/GPy.inference.rst @@ -1,51 +1,62 @@ -inference Package -================= +GPy.inference package +===================== -:mod:`conjugate_gradient_descent` Module ----------------------------------------- +Submodules +---------- + +GPy.inference.conjugate_gradient_descent module +----------------------------------------------- .. automodule:: GPy.inference.conjugate_gradient_descent :members: :undoc-members: :show-inheritance: -:mod:`gradient_descent_update_rules` Module -------------------------------------------- +GPy.inference.gradient_descent_update_rules module +-------------------------------------------------- .. automodule:: GPy.inference.gradient_descent_update_rules :members: :undoc-members: :show-inheritance: -:mod:`optimization` Module --------------------------- +GPy.inference.optimization module +--------------------------------- .. automodule:: GPy.inference.optimization :members: :undoc-members: :show-inheritance: -:mod:`samplers` Module ----------------------- +GPy.inference.samplers module +----------------------------- .. automodule:: GPy.inference.samplers :members: :undoc-members: :show-inheritance: -:mod:`scg` Module ------------------ +GPy.inference.scg module +------------------------ .. automodule:: GPy.inference.scg :members: :undoc-members: :show-inheritance: -:mod:`sgd` Module ------------------ +GPy.inference.sgd module +------------------------ .. automodule:: GPy.inference.sgd :members: :undoc-members: :show-inheritance: + +Module contents +--------------- + +.. automodule:: GPy.inference + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/GPy.kern.parts.rst b/doc/GPy.kern.parts.rst new file mode 100644 index 00000000..ec0661b4 --- /dev/null +++ b/doc/GPy.kern.parts.rst @@ -0,0 +1,246 @@ +GPy.kern.parts package +====================== + +Submodules +---------- + +GPy.kern.parts.Brownian module +------------------------------ + +.. automodule:: GPy.kern.parts.Brownian + :members: + :undoc-members: + :show-inheritance: + +GPy.kern.parts.Matern32 module +------------------------------ + +.. automodule:: GPy.kern.parts.Matern32 + :members: + :undoc-members: + :show-inheritance: + +GPy.kern.parts.Matern52 module +------------------------------ + +.. automodule:: GPy.kern.parts.Matern52 + :members: + :undoc-members: + :show-inheritance: + +GPy.kern.parts.bias module +-------------------------- + +.. automodule:: GPy.kern.parts.bias + :members: + :undoc-members: + :show-inheritance: + +GPy.kern.parts.coregionalize module +----------------------------------- + +.. automodule:: GPy.kern.parts.coregionalize + :members: + :undoc-members: + :show-inheritance: + +GPy.kern.parts.exponential module +--------------------------------- + +.. automodule:: GPy.kern.parts.exponential + :members: + :undoc-members: + :show-inheritance: + +GPy.kern.parts.finite_dimensional module +---------------------------------------- + +.. automodule:: GPy.kern.parts.finite_dimensional + :members: + :undoc-members: + :show-inheritance: + +GPy.kern.parts.fixed module +--------------------------- + +.. automodule:: GPy.kern.parts.fixed + :members: + :undoc-members: + :show-inheritance: + +GPy.kern.parts.gibbs module +--------------------------- + +.. automodule:: GPy.kern.parts.gibbs + :members: + :undoc-members: + :show-inheritance: + +GPy.kern.parts.hetero module +---------------------------- + +.. automodule:: GPy.kern.parts.hetero + :members: + :undoc-members: + :show-inheritance: + +GPy.kern.parts.hierarchical module +---------------------------------- + +.. automodule:: GPy.kern.parts.hierarchical + :members: + :undoc-members: + :show-inheritance: + +GPy.kern.parts.independent_outputs module +----------------------------------------- + +.. automodule:: GPy.kern.parts.independent_outputs + :members: + :undoc-members: + :show-inheritance: + +GPy.kern.parts.kernpart module +------------------------------ + +.. automodule:: GPy.kern.parts.kernpart + :members: + :undoc-members: + :show-inheritance: + +GPy.kern.parts.linear module +---------------------------- + +.. automodule:: GPy.kern.parts.linear + :members: + :undoc-members: + :show-inheritance: + +GPy.kern.parts.mlp module +------------------------- + +.. automodule:: GPy.kern.parts.mlp + :members: + :undoc-members: + :show-inheritance: + +GPy.kern.parts.periodic_Matern32 module +--------------------------------------- + +.. automodule:: GPy.kern.parts.periodic_Matern32 + :members: + :undoc-members: + :show-inheritance: + +GPy.kern.parts.periodic_Matern52 module +--------------------------------------- + +.. automodule:: GPy.kern.parts.periodic_Matern52 + :members: + :undoc-members: + :show-inheritance: + +GPy.kern.parts.periodic_exponential module +------------------------------------------ + +.. automodule:: GPy.kern.parts.periodic_exponential + :members: + :undoc-members: + :show-inheritance: + +GPy.kern.parts.poly module +-------------------------- + +.. automodule:: GPy.kern.parts.poly + :members: + :undoc-members: + :show-inheritance: + +GPy.kern.parts.prod module +-------------------------- + +.. automodule:: GPy.kern.parts.prod + :members: + :undoc-members: + :show-inheritance: + +GPy.kern.parts.prod_orthogonal module +------------------------------------- + +.. automodule:: GPy.kern.parts.prod_orthogonal + :members: + :undoc-members: + :show-inheritance: + +GPy.kern.parts.rational_quadratic module +---------------------------------------- + +.. automodule:: GPy.kern.parts.rational_quadratic + :members: + :undoc-members: + :show-inheritance: + +GPy.kern.parts.rbf module +------------------------- + +.. automodule:: GPy.kern.parts.rbf + :members: + :undoc-members: + :show-inheritance: + +GPy.kern.parts.rbf_inv module +----------------------------- + +.. automodule:: GPy.kern.parts.rbf_inv + :members: + :undoc-members: + :show-inheritance: + +GPy.kern.parts.rbfcos module +---------------------------- + +.. automodule:: GPy.kern.parts.rbfcos + :members: + :undoc-members: + :show-inheritance: + +GPy.kern.parts.spline module +---------------------------- + +.. automodule:: GPy.kern.parts.spline + :members: + :undoc-members: + :show-inheritance: + +GPy.kern.parts.symmetric module +------------------------------- + +.. automodule:: GPy.kern.parts.symmetric + :members: + :undoc-members: + :show-inheritance: + +GPy.kern.parts.sympykern module +------------------------------- + +.. automodule:: GPy.kern.parts.sympykern + :members: + :undoc-members: + :show-inheritance: + +GPy.kern.parts.white module +--------------------------- + +.. automodule:: GPy.kern.parts.white + :members: + :undoc-members: + :show-inheritance: + + +Module contents +--------------- + +.. automodule:: GPy.kern.parts + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/GPy.kern.rst b/doc/GPy.kern.rst index 35d9ec00..b4b9d9aa 100644 --- a/doc/GPy.kern.rst +++ b/doc/GPy.kern.rst @@ -1,29 +1,5 @@ -kern Package -============ - -:mod:`kern` Package -------------------- - -.. automodule:: GPy.kern - :members: - :undoc-members: - :show-inheritance: - -:mod:`constructors` Module --------------------------- - -.. automodule:: GPy.kern.constructors - :members: - :undoc-members: - :show-inheritance: - -:mod:`kern` Module ------------------- - -.. automodule:: GPy.kern.kern - :members: - :undoc-members: - :show-inheritance: +GPy.kern package +================ Subpackages ----------- @@ -32,3 +8,30 @@ Subpackages GPy.kern.parts +Submodules +---------- + +GPy.kern.constructors module +---------------------------- + +.. automodule:: GPy.kern.constructors + :members: + :undoc-members: + :show-inheritance: + +GPy.kern.kern module +-------------------- + +.. automodule:: GPy.kern.kern + :members: + :undoc-members: + :show-inheritance: + + +Module contents +--------------- + +.. automodule:: GPy.kern + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/GPy.likelihoods.noise_models.rst b/doc/GPy.likelihoods.noise_models.rst new file mode 100644 index 00000000..d1a4f451 --- /dev/null +++ b/doc/GPy.likelihoods.noise_models.rst @@ -0,0 +1,70 @@ +GPy.likelihoods.noise_models package +==================================== + +Submodules +---------- + +GPy.likelihoods.noise_models.binomial_noise module +-------------------------------------------------- + +.. automodule:: GPy.likelihoods.noise_models.binomial_noise + :members: + :undoc-members: + :show-inheritance: + +GPy.likelihoods.noise_models.exponential_noise module +----------------------------------------------------- + +.. automodule:: GPy.likelihoods.noise_models.exponential_noise + :members: + :undoc-members: + :show-inheritance: + +GPy.likelihoods.noise_models.gamma_noise module +----------------------------------------------- + +.. automodule:: GPy.likelihoods.noise_models.gamma_noise + :members: + :undoc-members: + :show-inheritance: + +GPy.likelihoods.noise_models.gaussian_noise module +-------------------------------------------------- + +.. automodule:: GPy.likelihoods.noise_models.gaussian_noise + :members: + :undoc-members: + :show-inheritance: + +GPy.likelihoods.noise_models.gp_transformations module +------------------------------------------------------ + +.. automodule:: GPy.likelihoods.noise_models.gp_transformations + :members: + :undoc-members: + :show-inheritance: + +GPy.likelihoods.noise_models.noise_distributions module +------------------------------------------------------- + +.. automodule:: GPy.likelihoods.noise_models.noise_distributions + :members: + :undoc-members: + :show-inheritance: + +GPy.likelihoods.noise_models.poisson_noise module +------------------------------------------------- + +.. automodule:: GPy.likelihoods.noise_models.poisson_noise + :members: + :undoc-members: + :show-inheritance: + + +Module contents +--------------- + +.. automodule:: GPy.likelihoods.noise_models + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/GPy.likelihoods.rst b/doc/GPy.likelihoods.rst index 9fec38f8..c3da2650 100644 --- a/doc/GPy.likelihoods.rst +++ b/doc/GPy.likelihoods.rst @@ -1,51 +1,69 @@ -likelihoods Package -=================== +GPy.likelihoods package +======================= -:mod:`likelihoods` Package --------------------------- +Subpackages +----------- -.. automodule:: GPy.likelihoods - :members: - :undoc-members: - :show-inheritance: +.. toctree:: -:mod:`ep` Module ----------------- + GPy.likelihoods.noise_models + +Submodules +---------- + +GPy.likelihoods.ep module +------------------------- .. automodule:: GPy.likelihoods.ep :members: :undoc-members: :show-inheritance: -:mod:`gaussian` Module ----------------------- +GPy.likelihoods.ep_mixed_noise module +------------------------------------- + +.. automodule:: GPy.likelihoods.ep_mixed_noise + :members: + :undoc-members: + :show-inheritance: + +GPy.likelihoods.gaussian module +------------------------------- .. automodule:: GPy.likelihoods.gaussian :members: :undoc-members: :show-inheritance: -:mod:`likelihood` Module ------------------------- +GPy.likelihoods.gaussian_mixed_noise module +------------------------------------------- + +.. automodule:: GPy.likelihoods.gaussian_mixed_noise + :members: + :undoc-members: + :show-inheritance: + +GPy.likelihoods.likelihood module +--------------------------------- .. automodule:: GPy.likelihoods.likelihood :members: :undoc-members: :show-inheritance: -:mod:`likelihood_functions` Module ----------------------------------- +GPy.likelihoods.noise_model_constructors module +----------------------------------------------- -.. automodule:: GPy.likelihoods.likelihood_functions +.. automodule:: GPy.likelihoods.noise_model_constructors :members: :undoc-members: :show-inheritance: -:mod:`link_functions` Module ----------------------------- -.. automodule:: GPy.likelihoods.link_functions +Module contents +--------------- + +.. automodule:: GPy.likelihoods :members: :undoc-members: :show-inheritance: - diff --git a/doc/GPy.mappings.rst b/doc/GPy.mappings.rst new file mode 100644 index 00000000..c48cb06e --- /dev/null +++ b/doc/GPy.mappings.rst @@ -0,0 +1,38 @@ +GPy.mappings package +==================== + +Submodules +---------- + +GPy.mappings.kernel module +-------------------------- + +.. automodule:: GPy.mappings.kernel + :members: + :undoc-members: + :show-inheritance: + +GPy.mappings.linear module +-------------------------- + +.. automodule:: GPy.mappings.linear + :members: + :undoc-members: + :show-inheritance: + +GPy.mappings.mlp module +----------------------- + +.. automodule:: GPy.mappings.mlp + :members: + :undoc-members: + :show-inheritance: + + +Module contents +--------------- + +.. automodule:: GPy.mappings + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/GPy.models.rst b/doc/GPy.models.rst index 4d227642..4440513e 100644 --- a/doc/GPy.models.rst +++ b/doc/GPy.models.rst @@ -1,99 +1,134 @@ -models Package -============== +GPy.models package +================== -:mod:`models` Package ---------------------- +Submodules +---------- -.. automodule:: GPy.models - :members: - :undoc-members: - :show-inheritance: - -:mod:`bayesian_gplvm` Module ----------------------------- +GPy.models.bayesian_gplvm module +-------------------------------- .. automodule:: GPy.models.bayesian_gplvm :members: :undoc-members: :show-inheritance: -:mod:`fitc_classification` Module ---------------------------------- +GPy.models.bcgplvm module +------------------------- + +.. automodule:: GPy.models.bcgplvm + :members: + :undoc-members: + :show-inheritance: + +GPy.models.fitc_classification module +------------------------------------- .. automodule:: GPy.models.fitc_classification :members: :undoc-members: :show-inheritance: -:mod:`gp_classification` Module -------------------------------- +GPy.models.gp_classification module +----------------------------------- .. automodule:: GPy.models.gp_classification :members: :undoc-members: :show-inheritance: -:mod:`gp_regression` Module ---------------------------- +GPy.models.gp_multioutput_regression module +------------------------------------------- + +.. automodule:: GPy.models.gp_multioutput_regression + :members: + :undoc-members: + :show-inheritance: + +GPy.models.gp_regression module +------------------------------- .. automodule:: GPy.models.gp_regression :members: :undoc-members: :show-inheritance: -:mod:`gplvm` Module -------------------- +GPy.models.gplvm module +----------------------- .. automodule:: GPy.models.gplvm :members: :undoc-members: :show-inheritance: -:mod:`mrd` Module ------------------ +GPy.models.gradient_checker module +---------------------------------- + +.. automodule:: GPy.models.gradient_checker + :members: + :undoc-members: + :show-inheritance: + +GPy.models.mrd module +--------------------- .. automodule:: GPy.models.mrd :members: :undoc-members: :show-inheritance: -:mod:`sparse_gp_classification` Module --------------------------------------- +GPy.models.sparse_gp_classification module +------------------------------------------ .. automodule:: GPy.models.sparse_gp_classification :members: :undoc-members: :show-inheritance: -:mod:`sparse_gp_regression` Module ----------------------------------- +GPy.models.sparse_gp_multioutput_regression module +-------------------------------------------------- + +.. automodule:: GPy.models.sparse_gp_multioutput_regression + :members: + :undoc-members: + :show-inheritance: + +GPy.models.sparse_gp_regression module +-------------------------------------- .. automodule:: GPy.models.sparse_gp_regression :members: :undoc-members: :show-inheritance: -:mod:`sparse_gplvm` Module --------------------------- +GPy.models.sparse_gplvm module +------------------------------ .. automodule:: GPy.models.sparse_gplvm :members: :undoc-members: :show-inheritance: -:mod:`svigp_regression` Module ------------------------------- +GPy.models.svigp_regression module +---------------------------------- .. automodule:: GPy.models.svigp_regression :members: :undoc-members: :show-inheritance: -:mod:`warped_gp` Module ------------------------ +GPy.models.warped_gp module +--------------------------- .. automodule:: GPy.models.warped_gp :members: :undoc-members: :show-inheritance: + +Module contents +--------------- + +.. automodule:: GPy.models + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/GPy.rst b/doc/GPy.rst index e56e48e1..60092e91 100644 --- a/doc/GPy.rst +++ b/doc/GPy.rst @@ -1,14 +1,6 @@ -GPy Package +GPy package =========== -:mod:`GPy` Package ------------------- - -.. automodule:: GPy.__init__ - :members: - :undoc-members: - :show-inheritance: - Subpackages ----------- @@ -19,7 +11,15 @@ Subpackages GPy.inference GPy.kern GPy.likelihoods + GPy.mappings GPy.models GPy.testing GPy.util +Module contents +--------------- + +.. automodule:: GPy + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/GPy.testing.rst b/doc/GPy.testing.rst index 6c461177..bd5258b7 100644 --- a/doc/GPy.testing.rst +++ b/doc/GPy.testing.rst @@ -1,107 +1,110 @@ -testing Package -=============== +GPy.testing package +=================== -:mod:`testing` Package ----------------------- +Submodules +---------- -.. automodule:: GPy.testing - :members: - :undoc-members: - :show-inheritance: - -:mod:`bgplvm_tests` Module --------------------------- +GPy.testing.bgplvm_tests module +------------------------------- .. automodule:: GPy.testing.bgplvm_tests :members: :undoc-members: :show-inheritance: -:mod:`cgd_tests` Module ------------------------ +GPy.testing.cgd_tests module +---------------------------- .. automodule:: GPy.testing.cgd_tests :members: :undoc-members: :show-inheritance: -:mod:`checkgrad` Module ------------------------ - -.. automodule:: GPy.testing.checkgrad - :members: - :undoc-members: - :show-inheritance: - -:mod:`examples_tests` Module ----------------------------- +GPy.testing.examples_tests module +--------------------------------- .. automodule:: GPy.testing.examples_tests :members: :undoc-members: :show-inheritance: -:mod:`gplvm_tests` Module -------------------------- +GPy.testing.gplvm_tests module +------------------------------ .. automodule:: GPy.testing.gplvm_tests :members: :undoc-members: :show-inheritance: -:mod:`kernel_tests` Module --------------------------- +GPy.testing.kernel_tests module +------------------------------- .. automodule:: GPy.testing.kernel_tests :members: :undoc-members: :show-inheritance: -:mod:`mrd_tests` Module ------------------------ +GPy.testing.mapping_tests module +-------------------------------- + +.. automodule:: GPy.testing.mapping_tests + :members: + :undoc-members: + :show-inheritance: + +GPy.testing.mrd_tests module +---------------------------- .. automodule:: GPy.testing.mrd_tests :members: :undoc-members: :show-inheritance: -:mod:`prior_tests` Module -------------------------- +GPy.testing.prior_tests module +------------------------------ .. automodule:: GPy.testing.prior_tests :members: :undoc-members: :show-inheritance: -:mod:`psi_stat_expactation_tests` Module ----------------------------------------- +GPy.testing.psi_stat_expectation_tests module +--------------------------------------------- -.. automodule:: GPy.testing.psi_stat_expactation_tests +.. automodule:: GPy.testing.psi_stat_expectation_tests :members: :undoc-members: :show-inheritance: -:mod:`psi_stat_gradient_tests` Module -------------------------------------- +GPy.testing.psi_stat_gradient_tests module +------------------------------------------ .. automodule:: GPy.testing.psi_stat_gradient_tests :members: :undoc-members: :show-inheritance: -:mod:`sparse_gplvm_tests` Module --------------------------------- +GPy.testing.sparse_gplvm_tests module +------------------------------------- .. automodule:: GPy.testing.sparse_gplvm_tests :members: :undoc-members: :show-inheritance: -:mod:`unit_tests` Module ------------------------- +GPy.testing.unit_tests module +----------------------------- .. automodule:: GPy.testing.unit_tests :members: :undoc-members: :show-inheritance: + +Module contents +--------------- + +.. automodule:: GPy.testing + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/GPy.util.latent_space_visualizations.controllers.rst b/doc/GPy.util.latent_space_visualizations.controllers.rst new file mode 100644 index 00000000..a88c1f5c --- /dev/null +++ b/doc/GPy.util.latent_space_visualizations.controllers.rst @@ -0,0 +1,30 @@ +GPy.util.latent_space_visualizations.controllers package +======================================================== + +Submodules +---------- + +GPy.util.latent_space_visualizations.controllers.axis_event_controller module +----------------------------------------------------------------------------- + +.. automodule:: GPy.util.latent_space_visualizations.controllers.axis_event_controller + :members: + :undoc-members: + :show-inheritance: + +GPy.util.latent_space_visualizations.controllers.imshow_controller module +------------------------------------------------------------------------- + +.. automodule:: GPy.util.latent_space_visualizations.controllers.imshow_controller + :members: + :undoc-members: + :show-inheritance: + + +Module contents +--------------- + +.. automodule:: GPy.util.latent_space_visualizations.controllers + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/GPy.util.latent_space_visualizations.rst b/doc/GPy.util.latent_space_visualizations.rst new file mode 100644 index 00000000..d8cbd843 --- /dev/null +++ b/doc/GPy.util.latent_space_visualizations.rst @@ -0,0 +1,17 @@ +GPy.util.latent_space_visualizations package +============================================ + +Subpackages +----------- + +.. toctree:: + + GPy.util.latent_space_visualizations.controllers + +Module contents +--------------- + +.. automodule:: GPy.util.latent_space_visualizations + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/GPy.util.rst b/doc/GPy.util.rst index e66329b6..c86280a7 100644 --- a/doc/GPy.util.rst +++ b/doc/GPy.util.rst @@ -1,123 +1,133 @@ -util Package -============ +GPy.util package +================ -:mod:`util` Package -------------------- +Subpackages +----------- -.. automodule:: GPy.util - :members: - :undoc-members: - :show-inheritance: +.. toctree:: -:mod:`Tango` Module -------------------- + GPy.util.latent_space_visualizations + +Submodules +---------- + +GPy.util.Tango module +--------------------- .. automodule:: GPy.util.Tango :members: :undoc-members: :show-inheritance: -:mod:`classification` Module ----------------------------- +GPy.util.classification module +------------------------------ .. automodule:: GPy.util.classification :members: :undoc-members: :show-inheritance: -:mod:`datasets` Module ----------------------- +GPy.util.datasets module +------------------------ .. automodule:: GPy.util.datasets :members: :undoc-members: :show-inheritance: -:mod:`decorators` Module ------------------------- +GPy.util.decorators module +-------------------------- .. automodule:: GPy.util.decorators :members: :undoc-members: :show-inheritance: -:mod:`linalg` Module --------------------- +GPy.util.linalg module +---------------------- .. automodule:: GPy.util.linalg :members: :undoc-members: :show-inheritance: -:mod:`misc` Module ------------------- +GPy.util.misc module +-------------------- .. automodule:: GPy.util.misc :members: :undoc-members: :show-inheritance: -:mod:`mocap` Module -------------------- +GPy.util.mocap module +--------------------- .. automodule:: GPy.util.mocap :members: :undoc-members: :show-inheritance: -:mod:`pca` Module ------------------ +GPy.util.multioutput module +--------------------------- -.. automodule:: GPy.util.pca +.. automodule:: GPy.util.multioutput :members: :undoc-members: :show-inheritance: -:mod:`plot` Module ------------------- +GPy.util.plot module +-------------------- .. automodule:: GPy.util.plot :members: :undoc-members: :show-inheritance: -:mod:`plot_latent` Module -------------------------- +GPy.util.plot_latent module +--------------------------- .. automodule:: GPy.util.plot_latent :members: :undoc-members: :show-inheritance: -:mod:`squashers` Module ------------------------ +GPy.util.squashers module +------------------------- .. automodule:: GPy.util.squashers :members: :undoc-members: :show-inheritance: -:mod:`univariate_Gaussian` Module ---------------------------------- +GPy.util.univariate_Gaussian module +----------------------------------- .. automodule:: GPy.util.univariate_Gaussian :members: :undoc-members: :show-inheritance: -:mod:`visualize` Module ------------------------ +GPy.util.visualize module +------------------------- .. automodule:: GPy.util.visualize :members: :undoc-members: :show-inheritance: -:mod:`warping_functions` Module -------------------------------- +GPy.util.warping_functions module +--------------------------------- .. automodule:: GPy.util.warping_functions :members: :undoc-members: :show-inheritance: + +Module contents +--------------- + +.. automodule:: GPy.util + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/conf.py b/doc/conf.py index b6dad7fd..42def116 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -83,6 +83,7 @@ print "finished importing" ############################################################################# class Mock(object): + __all__ = [] def __init__(self, *args, **kwargs): pass @@ -105,8 +106,7 @@ class Mock(object): print "Mocking" MOCK_MODULES = ['sympy', 'sympy.utilities', 'sympy.utilities.codegen', 'sympy.core.cache', - 'sympy.core', 'sympy.parsing', 'sympy.parsing.sympy_parser', - 'matplotlib.pyplot' + 'sympy.core', 'sympy.parsing', 'sympy.parsing.sympy_parser' ] for mod_name in MOCK_MODULES: sys.modules[mod_name] = Mock() diff --git a/setup.py b/setup.py index 90645e71..9ccf3990 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ setup(name = 'GPy', license = "BSD 3-clause", keywords = "machine-learning gaussian-processes kernels", url = "http://sheffieldml.github.com/GPy/", - packages = ['GPy', 'GPy.core', 'GPy.kern', 'GPy.util', 'GPy.models', 'GPy.inference', 'GPy.examples', 'GPy.likelihoods', 'GPy.testing'], + packages = ['GPy', 'GPy.core', 'GPy.kern', 'GPy.util', 'GPy.models', 'GPy.inference', 'GPy.examples', 'GPy.likelihoods', 'GPy.testing', 'GPy.util.latent_space_visualizations', 'GPy.util.latent_space_visualizations.controllers', 'GPy.likelihoods.noise_models', 'GPy.kern.parts', 'GPy.mappings'], package_dir={'GPy': 'GPy'}, package_data = {'GPy': ['GPy/examples']}, py_modules = ['GPy.__init__'],