Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions nimfa/examples/gene_func_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ class information exploiting properties of Functional Catalogue hierarchy.
if line_type == "@DATA":
section = 'd'
idxs = set(range(idx)).intersection(used_idx)
attr_data = np.mat(np.zeros((1e4, len(attr2idx))))
class_data = np.mat(np.zeros((1e4, len(class2idx))))
attr_data = np.asmatrix(np.zeros((1e4, len(attr2idx))))
class_data = np.asmatrix(np.zeros((1e4, len(class2idx))))
elif section == 'd':
d, _, comment = line.strip().partition("%")
values = d.split(",")
Expand Down Expand Up @@ -287,10 +287,10 @@ def compute_correlations(train, test):
# alternative, it is time consuming - can be used for partial evaluation
"""corrs = {}
for i in xrange(test['W'].shape[0]):
corrs.setdefault(i, np.mat(np.zeros((train['W'].shape[0], 1))))
corrs.setdefault(i, np.asmatrix(np.zeros((train['W'].shape[0], 1))))
for j in xrange(train['W'].shape[0]):
corrs[i][j, 0] = _corr(test['W'][i, :], train['W'][j, :])"""
return np.mat(corrs)
return np.asmatrix(corrs)


def _corr(x, y):
Expand Down
6 changes: 3 additions & 3 deletions nimfa/examples/orl_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def read():
im = open(join(dir + str(subject + 1), str(image + 1) + ".pgm"))
# reduce the size of the image
im = im.resize((46, 56))
V[:, 10 * subject + image] = np.mat(np.asarray(im).flatten()).T
V[:, 10 * subject + image] = np.asmatrix(np.asarray(im).flatten()).T
return V


Expand All @@ -174,9 +174,9 @@ def preprocess(V):
"""
print("Data preprocessing")
min_val = V.min(axis=0)
V = V - np.mat(np.ones((V.shape[0], 1))) * min_val
V = V - np.asmatrix(np.ones((V.shape[0], 1))) * min_val
max_val = V.max(axis=0) + 1e-4
V = (255. * V) / (np.mat(np.ones((V.shape[0], 1))) * max_val) / 100.
V = (255. * V) / (np.asmatrix(np.ones((V.shape[0], 1))) * max_val) / 100.
return V


Expand Down
2 changes: 1 addition & 1 deletion nimfa/examples/synthetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def run_bd(V):
rank = 10
bd = nimfa.Bd(V, seed="random_c", rank=rank, max_iter=12, alpha=np.zeros((V.shape[0], rank)),
beta=np.zeros((rank, V.shape[1])), theta=.0, k=.0, sigma=1., skip=100,
stride=1, n_w=np.mat(np.zeros((rank, 1))), n_h=np.mat(np.zeros((rank, 1))),
stride=1, n_w=np.asmatrix(np.zeros((rank, 1))), n_h=np.asmatrix(np.zeros((rank, 1))),
n_sigma=False)
fit = bd()
print_info(fit)
Expand Down
4 changes: 2 additions & 2 deletions nimfa/methods/factorization/bd.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ def __init__(self, V, seed=None, W=None, H=None, rank=30, max_iter=30,
nmf_std.Nmf_std.__init__(self, vars())
if self.alpha is None:
self.alpha = sp.csr_matrix((self.V.shape[0], self.rank))
self.alpha = self.alpha.tocsr() if sp.isspmatrix(self.alpha) else np.mat(self.alpha)
self.alpha = self.alpha.tocsr() if sp.isspmatrix(self.alpha) else np.asmatrix(self.alpha)
if self.beta is None:
self.beta = sp.csr_matrix((self.rank, self.V.shape[1]))
self.beta = self.beta.tocsr() if sp.isspmatrix(self.beta) else np.mat(self.beta)
self.beta = self.beta.tocsr() if sp.isspmatrix(self.beta) else np.asmatrix(self.beta)
if self.n_w is None:
self.n_w = np.zeros((self.rank, 1))
if self.n_h is None:
Expand Down
4 changes: 2 additions & 2 deletions nimfa/methods/factorization/icm.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ def __init__(self, V, seed=None, W=None, H=None, H1=None,
nmf_std.Nmf_std.__init__(self, vars())
if self.alpha is None:
self.alpha = sp.rand(self.V.shape[0], self.rank, density=0.8, format='csr')
self.alpha= self.alpha.tocsr() if sp.isspmatrix(self.alpha) else np.mat(self.alpha)
self.alpha= self.alpha.tocsr() if sp.isspmatrix(self.alpha) else np.asmatrix(self.alpha)
if self.beta is None:
self.beta = sp.rand(self.rank, self.V.shape[1], density=0.8, format='csr')
self.beta = self.beta.tocsr() if sp.isspmatrix(self.beta) else np.mat(self.beta)
self.beta = self.beta.tocsr() if sp.isspmatrix(self.beta) else np.asmatrix(self.beta)
self.tracker = mf_track.Mf_track() if self.track_factor and self.n_run > 1 \
or self.track_error else None

Expand Down
8 changes: 4 additions & 4 deletions nimfa/methods/factorization/lfnmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ def factorize(self):
for run in range(self.n_run):
self.W, self.H = self.seed.initialize(
self.V, self.rank, self.options)
self.Sw, self.Sb = np.mat(
np.zeros((1, 1))), np.mat(np.zeros((1, 1)))
self.Sw, self.Sb = np.asmatrix(
np.zeros((1, 1))), np.asmatrix(np.zeros((1, 1)))
p_obj = c_obj = sys.float_info.max
best_obj = c_obj if run == 0 else best_obj
iter = 0
Expand Down Expand Up @@ -244,7 +244,7 @@ def update(self):
# update within class scatter and between class
self.Sw = sum(sum(dot(self.H[:, c2m[i][j]] - avgs[i], (self.H[:, c2m[i][j]] - avgs[i]).T)
for j in range(len(c2m[i]))) for i in c2m)
avgs_t = np.mat(np.zeros((self.rank, 1)))
avgs_t = np.asmatrix(np.zeros((self.rank, 1)))
for k in avgs:
avgs_t += avgs[k]
avgs_t /= len(avgs)
Expand All @@ -259,7 +259,7 @@ def _encoding(self, idxH):
c2m.setdefault(idxH[0, i], [])
c2m[idxH[0, i]].append(i)
# compute mean value of class idx in encoding matrix H
avgs.setdefault(idxH[0, i], np.mat(np.zeros((self.rank, 1))))
avgs.setdefault(idxH[0, i], np.asmatrix(np.zeros((self.rank, 1))))
avgs[idxH[0, i]] += self.H[:, i]
for k in avgs:
avgs[k] /= len(c2m[k])
Expand Down
2 changes: 1 addition & 1 deletion nimfa/methods/factorization/nmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def conn(self):
cons = elop(mat1, mat2, eq)
if not hasattr(self, 'consold'):
self.cons = cons
self.consold = np.mat(np.logical_not(cons))
self.consold = np.asmatrix(np.logical_not(cons))
else:
self.consold = self.cons
self.cons = cons
Expand Down
2 changes: 1 addition & 1 deletion nimfa/methods/factorization/pmfcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def __init__(self, V, seed=None, W=None, H=None, rank=30, max_iter=30,
self.aseeds = ["random", "fixed", "nndsvd", "random_c", "random_vcol"]
smf.Smf.__init__(self, vars())
if not self.Theta:
self.Theta = np.mat(np.zeros((self.V.shape[1], self.V.shape[1])))
self.Theta = np.asmatrix(np.zeros((self.V.shape[1], self.V.shape[1])))
self.tracker = mf_track.Mf_track() if self.track_factor and self.n_run > 1 \
or self.track_error else None

Expand Down
4 changes: 2 additions & 2 deletions nimfa/methods/factorization/psmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ def factorize(self):
self.H = self.V.__class__(
(self.rank, self.V.shape[1]), dtype='d')
else:
self.W = np.mat(np.zeros((self.V.shape[0], self.rank)))
self.H = np.mat(np.zeros((self.rank, self.V.shape[1])))
self.W = np.asmatrix(np.zeros((self.V.shape[0], self.rank)))
self.H = np.asmatrix(np.zeros((self.rank, self.V.shape[1])))
self.s = np.zeros((self.V.shape[0], self.N), int)
self.r = np.zeros((self.V.shape[0], 1), int)
self.psi = np.array(std(self.V, axis=1, ddof=0))
Expand Down
2 changes: 1 addition & 1 deletion nimfa/methods/factorization/sepnmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def norm_axis(X, p=None, axis=None):
if sp.isspmatrix(X):
return sla.norm(X, ord=p, axis=axis)
else:
n = nla.norm(np.mat(X), ord=p, axis=axis)
n = nla.norm(np.asmatrix(X), ord=p, axis=axis)
if axis is None:
return n
else:
Expand Down
36 changes: 18 additions & 18 deletions nimfa/methods/factorization/snmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ def factorize(self):
if sp.isspmatrix(self.H):
self.H = self.H.tolil()
iter = 0
self.idx_w_old = np.mat(np.zeros((self.V.shape[0], 1)))
self.idx_h_old = np.mat(np.zeros((1, self.V.shape[1])))
self.idx_w_old = np.asmatrix(np.zeros((self.V.shape[0], 1)))
self.idx_h_old = np.asmatrix(np.zeros((1, self.V.shape[1])))
c_obj = sys.float_info.max
best_obj = c_obj if run == 0 else best_obj
# count the number of convergence checks that column clusters and
Expand All @@ -200,7 +200,7 @@ def factorize(self):
sp.eye(self.rank, self.rank, format='lil')
else:
self.beta_vec = sqrt(self.beta) * np.ones((1, self.rank))
self.I_k = self.eta * np.mat(np.eye(self.rank))
self.I_k = self.eta * np.asmatrix(np.eye(self.rank))
self.n_restart = 0
if self.callback_init:
self.final_obj = c_obj
Expand Down Expand Up @@ -287,8 +287,8 @@ def update(self):
if self.n_restart >= 100:
raise utils.MFError(
"Too many restarts due to too large beta parameter.")
self.idx_w_old = np.mat(np.zeros((self.V.shape[0], 1)))
self.idx_h_old = np.mat(np.zeros((1, self.V.shape[1])))
self.idx_w_old = np.asmatrix(np.zeros((self.V.shape[0], 1)))
self.idx_h_old = np.asmatrix(np.zeros((1, self.V.shape[1])))
self.inc = 0
self.W, _ = self.seed.initialize(self.V, self.rank, self.options)
# normalize W and convert to lil
Expand Down Expand Up @@ -333,7 +333,7 @@ def objective(self):
resmat1 = elop(self.W, WHHt - VHt + self.eta ** 2 * self.W, min)
res_vec = nz_data(resmat) + nz_data(resmat1)
# L1 norm
self.conv = norm(np.mat(res_vec), 1)
self.conv = norm(np.asmatrix(res_vec), 1)
err_avg = self.conv / len(res_vec)
self.idx_w_old = idx_w
self.idx_h_old = idx_h
Expand Down Expand Up @@ -388,7 +388,7 @@ def _spfcnnls(self, C, A):
# make infeasible solutions feasible (standard NNLS inner loop)
if len(h_set) > 0:
n_h_set = len(h_set)
alpha = np.mat(np.zeros((l_var, n_h_set)))
alpha = np.asmatrix(np.zeros((l_var, n_h_set)))
while len(h_set) > 0 and iter < max_iter:
iter += 1
alpha[:, :n_h_set] = np.Inf
Expand Down Expand Up @@ -465,15 +465,15 @@ def __spcssls(self, CtC, CtA, p_set=None):
# equivalent if CtC is square matrix
for k in range(CtA.shape[1]):
ls = sp.linalg.gmres(CtC, CtA[:, k].toarray())[0]
K[:, k] = sp.lil_matrix(np.mat(ls).T)
K[:, k] = sp.lil_matrix(np.asmatrix(ls).T)
# K = dot(np.linalg.pinv(CtC), CtA)
else:
l_var, p_rhs = p_set.shape
coded_p_set = dot(
sp.lil_matrix(np.mat(2 ** np.array(list(range(l_var - 1, -1, -1))))), p_set)
sp.lil_matrix(np.asmatrix(2 ** np.array(list(range(l_var - 1, -1, -1))))), p_set)
sorted_p_set, sorted_idx_set = sort(coded_p_set.todense())
breaks = diff(np.mat(sorted_p_set))
break_idx = [-1] + find(np.mat(breaks)) + [p_rhs]
breaks = diff(np.asmatrix(sorted_p_set))
break_idx = [-1] + find(np.asmatrix(breaks)) + [p_rhs]
for k in range(len(break_idx) - 1):
cols2solve = sorted_idx_set[
break_idx[k] + 1: break_idx[k + 1] + 1]
Expand All @@ -483,7 +483,7 @@ def __spcssls(self, CtC, CtA, p_set=None):
sol = sp.lil_matrix(K.shape)
for k in range(tmp_ls.shape[1]):
ls = sp.linalg.gmres(CtC[:, vars][vars, :], tmp_ls[:, k].toarray())[0]
sol[:, k] = sp.lil_matrix(np.mat(ls).T)
sol[:, k] = sp.lil_matrix(np.asmatrix(ls).T)
i = 0
for c in cols2solve:
j = 0
Expand Down Expand Up @@ -519,7 +519,7 @@ def _fcnnls(self, C, A):
A = A.todense() if sp.isspmatrix(A) else A
_, l_var = C.shape
p_rhs = A.shape[1]
W = np.mat(np.zeros((l_var, p_rhs)))
W = np.asmatrix(np.zeros((l_var, p_rhs)))
iter = 0
max_iter = 3 * l_var
# precompute parts of pseudoinverse
Expand All @@ -542,7 +542,7 @@ def _fcnnls(self, C, A):
# make infeasible solutions feasible (standard NNLS inner loop)
if len(h_set) > 0:
n_h_set = len(h_set)
alpha = np.mat(np.zeros((l_var, n_h_set)))
alpha = np.asmatrix(np.zeros((l_var, n_h_set)))
while len(h_set) > 0 and iter < max_iter:
iter += 1
alpha[:, :n_h_set] = np.Inf
Expand Down Expand Up @@ -597,18 +597,18 @@ def __cssls(self, CtC, CtA, p_set=None):
Solve the set of equations CtA = CtC * K for variables defined in set p_set
using the fast combinatorial approach (van Benthem and Keenan, 2004).
"""
K = np.mat(np.zeros(CtA.shape))
K = np.asmatrix(np.zeros(CtA.shape))
if p_set is None or p_set.size == 0 or all(p_set):
# equivalent if CtC is square matrix
K = np.linalg.lstsq(CtC, CtA, rcond=-1)[0]
# K = dot(np.linalg.pinv(CtC), CtA)
else:
l_var, p_rhs = p_set.shape
coded_p_set = dot(
np.mat(2 ** np.array(list(range(l_var - 1, -1, -1)))), p_set)
np.asmatrix(2 ** np.array(list(range(l_var - 1, -1, -1)))), p_set)
sorted_p_set, sorted_idx_set = sort(coded_p_set)
breaks = diff(np.mat(sorted_p_set))
break_idx = [-1] + find(np.mat(breaks)) + [p_rhs]
breaks = diff(np.asmatrix(sorted_p_set))
break_idx = [-1] + find(np.asmatrix(breaks)) + [p_rhs]
for k in range(len(break_idx) - 1):
cols2solve = sorted_idx_set[
break_idx[k] + 1: break_idx[k + 1] + 1]
Expand Down
4 changes: 2 additions & 2 deletions nimfa/methods/factorization/snmnmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ def __init__(self, V, V1, seed=None, W=None, H=None, H1=None,
nmf_mm.Nmf_mm.__init__(self, vars())
if self.A is None:
self.A = sp.csr_matrix((self.V1.shape[1], self.V1.shape[1]))
self.A = self.A.tocsr() if sp.isspmatrix(self.A) else np.mat(self.A)
self.A = self.A.tocsr() if sp.isspmatrix(self.A) else np.asmatrix(self.A)
if self.B is None:
self.B = sp.csr_matrix((self.V.shape[1], self.V1.shape[1]))
self.B = self.B.tocsr() if sp.isspmatrix(self.B) else np.mat(self.B)
self.B = self.B.tocsr() if sp.isspmatrix(self.B) else np.asmatrix(self.B)
self.tracker = mf_track.Mf_track() if self.track_factor and self.n_run > 1 \
or self.track_error else None

Expand Down
4 changes: 2 additions & 2 deletions nimfa/methods/seeding/nndsvd.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ def initialize(self, V, rank, options):
E = E.T
if sp.isspmatrix(U):
return self.init_sparse(V, U, S, E)
self.W = np.mat(np.zeros((V.shape[0], self.rank)))
self.H = np.mat(np.zeros((self.rank, V.shape[1])))
self.W = np.asmatrix(np.zeros((V.shape[0], self.rank)))
self.H = np.asmatrix(np.zeros((self.rank, V.shape[1])))
# choose the first singular triplet to be nonnegative
S = np.diagonal(S)
self.W[:, 0] = sqrt(S[0]) * abs(U[:, 0])
Expand Down
2 changes: 1 addition & 1 deletion nimfa/methods/seeding/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def gen_dense(self, dim1, dim2):
:param dim2: Dimension along second axis.
:type dim2: `int`
"""
return np.mat(self.prng.uniform(0, self.max, (dim1, dim2)))
return np.asmatrix(self.prng.uniform(0, self.max, (dim1, dim2)))

def __repr__(self):
return "random.Random()"
Expand Down
8 changes: 4 additions & 4 deletions nimfa/methods/seeding/random_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ def initialize(self, V, rank, options):
top_r = sorted(
enumerate([norm(V[i, :], 2) for i in range(V.shape[0])]), key=itemgetter(1), reverse=True)[:self.l_r]
else:
self.W = np.mat(np.zeros((V.shape[0], self.rank)))
self.H = np.mat(np.zeros((self.rank, V.shape[1])))
self.W = np.asmatrix(np.zeros((V.shape[0], self.rank)))
self.H = np.asmatrix(np.zeros((self.rank, V.shape[1])))
top_c = sorted(enumerate([norm(V[:, i], 2)
for i in range(V.shape[1])]), key=itemgetter(1), reverse=True)[:self.l_c]
top_r = sorted(
enumerate([norm(V[i, :], 2) for i in range(V.shape[0])]), key=itemgetter(1), reverse=True)[:self.l_r]
top_c = np.mat(list(zip(*top_c))[0])
top_r = np.mat(list(zip(*top_r))[0])
top_c = np.asmatrix(list(zip(*top_c))[0])
top_r = np.asmatrix(list(zip(*top_r))[0])
for i in range(self.rank):
self.W[:, i] = V[
:, top_c[0, self.prng.randint(low=0, high=self.l_c, size=self.p_c)].tolist()[0]].mean(axis=1)
Expand Down
4 changes: 2 additions & 2 deletions nimfa/methods/seeding/random_vcol.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def initialize(self, V, rank, options):
self.W = sp.lil_matrix((V.shape[0], self.rank))
self.H = sp.lil_matrix((self.rank, V.shape[1]))
else:
self.W = np.mat(np.zeros((V.shape[0], self.rank)))
self.H = np.mat(np.zeros((self.rank, V.shape[1])))
self.W = np.asmatrix(np.zeros((V.shape[0], self.rank)))
self.H = np.asmatrix(np.zeros((self.rank, V.shape[1])))
for i in range(self.rank):
self.W[:, i] = V[:, self.prng.randint(
low=0, high=V.shape[1], size=self.p_c)].mean(axis=1)
Expand Down
4 changes: 2 additions & 2 deletions nimfa/models/nmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def connectivity(self, H=None, idx=None):
if sp.isspmatrix(conn):
return conn.__class__(conn, dtype='d')
else:
return np.mat(conn, dtype='d')
return np.asmatrix(conn, dtype='d')

def consensus(self, idx=None):
"""
Expand All @@ -204,7 +204,7 @@ def consensus(self, idx=None):
if sp.isspmatrix(V):
cons = V.__class__((V.shape[1], V.shape[1]), dtype=V.dtype)
else:
cons = np.mat(np.zeros((V.shape[1], V.shape[1])))
cons = np.asmatrix(np.zeros((V.shape[1], V.shape[1])))
for i in range(self.n_run):
cons += self.connectivity(
H=self.tracker.get_factor(i).H, idx=idx)
Expand Down
Loading