Skip to content

Commit

Permalink
Fixup: Basis and coefficient matrix have the same data type
Browse files Browse the repository at this point in the history
  • Loading branch information
marinkaz committed Jul 20, 2015
1 parent 5560279 commit 4d6a695
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
5 changes: 3 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ Documentation and examples on real-world data are at `Nimfa website`_.
****

`Hidden patients and hidden genes - Understanding cancer data with matrix factorization`_ is
a tutorial on how one can use Nimfa to analyze breast cancer transcriptome data sets from The
International Cancer Genome Consortium (ICGC).
a tutorial-like IPython notebook on how one can use Nimfa to analyze breast cancer transcriptome data sets from The
International Cancer Genome Consortium (`ICGC`_).

.. _Hidden patients and hidden genes - Understanding cancer data with matrix factorization: http://nbviewer.ipython.org/github/marinkaz/nimfa-ipynb/blob/master/ICGC%20and%20Nimfa.ipynb
.. _ICGC: https://dcc.icgc.org

Usage
-----
Expand Down
8 changes: 2 additions & 6 deletions nimfa/methods/factorization/nsnmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,7 @@ def factorize(self):
for run in range(self.n_run):
self.W, self.H = self.seed.initialize(
self.V, self.rank, self.options)
self.S = sop(
(1 - self.theta) * sp.spdiags(
[1 for _ in range(
self.rank)], 0, self.rank, self.rank, 'csr'),
self.theta / self.rank, add)
self.S = np.diag(np.ones(self.rank) - self.theta) + self.theta / self.rank
p_obj = c_obj = sys.float_info.max
best_obj = c_obj if run == 0 else best_obj
iter = 0
Expand Down Expand Up @@ -229,8 +225,8 @@ def update(self):
H1 = repmat(W.sum(0).T, 1, self.V.shape[1])
self.H = multiply(
self.H, elop(dot(W.T, elop(self.V, dot(W, self.H), div)), H1, div))
# update basis matrix W
H = dot(self.S, self.H)
# update basis matrix W
W1 = repmat(H.sum(1).T, self.V.shape[0], 1)
self.W = multiply(
self.W, elop(dot(elop(self.V, dot(self.W, H), div), H.T), W1, div))
Expand Down
3 changes: 1 addition & 2 deletions nimfa/methods/factorization/pmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ def factorize(self):
self.H, repmat(self.H.sum(axis=1), 1, self.V.shape[1]), div)
self.v_factor = self.V.sum()
self.V_n = sop(self.V.copy(), self.v_factor, div)
self.P = sp.spdiags(
[1. / self.rank for _ in range(self.rank)], 0, self.rank, self.rank, 'csr')
self.P = np.diag([1. / self.rank for _ in range(self.rank)])
self.sqrt_P = sop(self.P, s=None, op=np.sqrt)
p_obj = c_obj = sys.float_info.max
best_obj = c_obj if run == 0 else best_obj
Expand Down
2 changes: 1 addition & 1 deletion nimfa/models/nmf_ns.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def distance(self, metric='euclidean', idx=None):
return power(R, 2).sum()
elif metric.lower() == 'kl':
Va = dot(dot(self.W, self.S), self.H)
return (multiply(self.V, sop(elop(self.V, Va, div), op=log)) - self.V + Va).sum()
return (multiply(self.V, sop(elop(self.V, Va, div), op=np.log)) - self.V + Va).sum()
else:
raise utils.MFError("Unknown distance metric.")

Expand Down

0 comments on commit 4d6a695

Please sign in to comment.