-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathf_mr.py
28 lines (23 loc) · 858 Bytes
/
f_mr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import numpy as np
from scipy import sparse
def mr(self, M, M1, M2):
delta_E = np.ones((self.image_size,self.size_n))
Wt = np.zeros((self.image_size,self.size_n))
for i in range(self.image_size):
ind = M[i].indices
cou = ind.size
for indi in range(cou):
delta_E[i,ind[indi]] = sum(M2[:,i]*M1[:,ind[indi]])
indices = []
for m in range(self.image_size):
ind = M[m].indices
indices.append(ind)
for i in range(self.image_size):
cou = indices[i].size
ATA = np.dot(M1[:,indices[i]].T, M1[:,indices[i]])
A = np.linalg.inv(ATA+self.lamda*np.eye(cou))
B = delta_E[i,indices[i]].T
Wt[i,indices[i]] = np.dot(A,B).T
# print(i)
Wt = sparse.csr_matrix(Wt)
return Wt