-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSCAN.py
More file actions
33 lines (24 loc) · 971 Bytes
/
SCAN.py
File metadata and controls
33 lines (24 loc) · 971 Bytes
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
29
30
31
32
33
import numpy as np
def scan(X,Y):
'''
Calculates the solution for the constrained regression called SCAN
given in the publication: Maag et al. "SCAN: Multi-Hop Calibration for Mobile Sensor Arrays".
In particuluar it solves: min_B trace( (Y-BX)(Y-BX)^T ) subject to BXX^TB^T = YY^T
Inputs:
X: size [n x m] (n: nUmber of sensors, m: nUmber of samples)
Y: size [n x m]
returns B: [n x n]
'''
Ux,Dx,Vx = np.linalg.svd(X,full_matrices=False)
Uy,Dy,Vy = np.linalg.svd(Y,full_matrices=False)
Dx = np.diag(Dx)
Dy = np.diag(Dy)
Vx = np.transpose(Vx)
Vy = np.transpose(Vy)
M = np.matmul( np.transpose(Vx), np.matmul(Vy, np.matmul(Dy,np.transpose(Dy))))
Um,_,Vm = np.linalg.svd(M,full_matrices=False)
Vm = np.transpose(Vm)
U = np.matmul(Vm,np.transpose(Um))
L = np.matmul(Uy,Dy)
T = np.matmul(U,np.linalg.inv(Dx))
return np.matmul(L,np.matmul(T,np.transpose(Ux)))