diff --git a/GPy/util/initialization.py b/GPy/util/initialization.py index 61837606..1cf9e846 100644 --- a/GPy/util/initialization.py +++ b/GPy/util/initialization.py @@ -5,12 +5,12 @@ Created on 24 Feb 2014 ''' import numpy as np -from GPy.util.pca import pca +from GPy.util.pca import PCA def initialize_latent(init, input_dim, Y): Xr = np.asfortranarray(np.random.randn(Y.shape[0], input_dim)) if init == 'PCA': - p = pca(Y) + p = PCA(Y) PC = p.project(Y, min(input_dim, Y.shape[1])) Xr[:PC.shape[0], :PC.shape[1]] = PC var = .1*p.fracs[:input_dim] diff --git a/GPy/util/pca.py b/GPy/util/pca.py index 996e6f48..f87b9807 100644 --- a/GPy/util/pca.py +++ b/GPy/util/pca.py @@ -14,9 +14,9 @@ from numpy.linalg.linalg import LinAlgError from operator import setitem import itertools -class pca(object): +class PCA(object): """ - pca module with automatic primal/dual determination. + PCA module with automatic primal/dual determination. """ def __init__(self, X): self.mu = None @@ -39,7 +39,7 @@ class pca(object): def center(self, X): """ - Center `X` in pca space. + Center `X` in PCA space. """ X = X.copy() inan = numpy.isnan(X) @@ -66,7 +66,7 @@ class pca(object): def project(self, X, Q=None): """ - Project X into pca space, defined by the Q highest eigenvalues. + Project X into PCA space, defined by the Q highest eigenvalues. Y = X dot V """ if Q is None: @@ -80,13 +80,16 @@ class pca(object): """ Plot fractions of Eigenvalues sorted in descending order. """ + from GPy.plotting.matplot_dep import Tango + Tango.reset() + col = Tango.nextMedium() if ax is None: fig = pylab.figure(fignum) ax = fig.add_subplot(111) if Q is None: Q = self.Q ticks = numpy.arange(Q) - bar = ax.bar(ticks - .4, self.fracs[:Q]) + bar = ax.bar(ticks - .4, self.fracs[:Q], color=col) ax.set_xticks(ticks, map(lambda x: r"${}$".format(x), ticks + 1)) ax.set_ylabel("Eigenvalue fraction") ax.set_xlabel("PC")