-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathER2.py
84 lines (80 loc) · 2.71 KB
/
ER2.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import numpy
SIN = numpy.sin
COS = numpy.cos
#_______________________________________________________________________________
def TRIG(LX, X, W):
"""
TRIG computes one value of Fourier transform by the sum of angles TRIGonometric formula for sine and cosine.
"""
COSNW = 1.
SINNW = 1.
SINW = SIN(W)
COSW = COS(W)
S = 0.0
C = 0.0
for I in range(LX):
C += COSNW * X[I]
S += SINNW * X[I]
T = COSW * COSNW - SINW * SINNW
SINNW = COSW * SINNW + SINW * COSNW
COSNW = T
return (S, C)
#_______________________________________________________________________________
#_______________________________________________________________________________
def BRAINY(NRA, NCA, LA, A, NRB, NCB, LB, B, C):
"""
BRAINY performs matrix polynomial multiplication.
It is the multichannel counterpart of FOLD in the single channel case.
Comes from the analogy with convolution in the brain.
p. 154
"""
LC = LA + LB - 1
# ZERO(NRA*NRB*LC,C)
C = numpy.zeros((NRA * NRB * LC, ))
for I in range(LA):
for J in range(LB):
K = I + J
for M in range(NRA):
for N in range(NCB):
MNK = M + N * NRA + K * NRA * NCB
for L in range(NCA):
MLI = M + L * NRA + I * NRA * NCA
LNJ = L + N * NCA + J * NCA * NCB
C[MNK] += A[MLI] * B[LNJ]
return (C, LC)
#_______________________________________________________________________________
#_______________________________________________________________________________
def POMAIN(N, LA, A, ADJ, P, DET, S):
"""
POMAIN Polynomial matrix inversion
p. 162
"""
# complex A, ADJ, P, DET, S
MOVE(N * N * LA, A, S)
J = LA
for L in range(N):
# Calculate coefficients P[., K] of characteristic polynomial
for K in range(J):
LK = L + K * N
P[LK] = 0.
for I in range(N):
IIK = I + I * N + K * N * N
P[LK] += S[IIK] / float(L)
if (L != N):
# Substract P[., K]*identity matrix
MOVE(N * N * J, S, ADJ)
for I in range(N):
for K in range(J):
IIK = I + I * N + K * N * N
LK = L + K * N
ADJ[IIK] -= P[LK]
# Multiply by input matrix
BRAINY(N, N, LA, A, N, N, J, ADJ, S)
#J += LA - 1
J += LA
# Give determinant and adjugate correct sign
SCALE(float(2 * MOD(N, 2)), N * N * (J - LA + 1), ADJ)
for L in range(J):
NL = N + L * N
DET[L] = P[NL] * float(2 * MOD(N, 2) - 1)
return (ADJ, P, DET, S)