Skip to content

Commit

Permalink
add tests, fix typo in README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
allentran committed Dec 24, 2017
1 parent e3277fb commit e5355ee
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ppca.fit(d=100, verbose=True)
The model parameters and components will be attached to the ppca object.
```
variance_explained = ppca.var_exp
components = ppca.X
components = ppca.data
model_params = ppca.C
```
If you want the principal components, call `transform`.
Expand Down
5 changes: 1 addition & 4 deletions ppca/_ppca.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def __init__(self):
self.C = None
self.means = None
self.stds = None
self.eig_vals = None

def _standardize(self, X):

Expand Down Expand Up @@ -107,10 +108,6 @@ def fit(self, data, d=None, tol=1e-4, min_obs=10, verbose=False):
self.eig_vals = vals
self._calc_var()

import IPython
IPython.embed()
assert False

def transform(self, data=None):

if self.C is None:
Expand Down
28 changes: 28 additions & 0 deletions tests/unittests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import unittest
import random

import numpy as np
from ppca import PPCA


class NaNTest(unittest.TestCase):

def remove_nan_test(self):

N = 101
k = 23
p_nan = 0.02
n_components = 3

data = np.random.random((N, k))
for n in xrange(N):
for _k in xrange(k):
if random.random() < p_nan:
data[n, _k] = np.nan

pca = PPCA()
pca.fit(data, n_components)

self.assertEqual(pca.data[np.isnan(pca.data)].shape, (0, ))
self.assertEqual(pca.C.shape, (k, n_components))
self.assertEqual(pca.transform().shape, (N, n_components))

0 comments on commit e5355ee

Please sign in to comment.