[pca] pca -> PCA

This commit is contained in:
Max Zwiessele 2014-10-17 11:45:04 +01:00
parent e12329c626
commit 5ac7b2c524
2 changed files with 10 additions and 7 deletions

View file

@ -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]

View file

@ -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")