如何解决作为联合对角化参数传递的数组结构错误
我正在尝试使用以下函数中的 ffdiag
(pybss) :
def ffdiag(X,max_lag = 10,eps = 1.0e-10,max_iter = 100):
'''
Blind source separation using FFDIAG. This version does not require that
the estimated mixing matrix be orthogonal.
INPUT:
------
X : array,required
N_sig x t matrix of signal mixtures
max_lag : int,optional
maximum lag (in samples) for covariance matrix calculation
eps : double,optional
convergence criterion for matrix updates
max_iter : int,optional
maximum number of iterations/updates
'''
R_tau = linalg.lagged_covariance(X,max_lag)
dim = len(R_tau[0])
n_lags = len(R_tau.keys())
W = zeros((dim,dim))
V = eye(dim)
C = R_tau
niter = 0
theta = 0.9
iter_eps = 1.0
用 lagged_covariance
定义:
def lagged_covariance(X,max_lag):
'''
Generates a dictionary of lagged covariance matrices of matrix X,for
lags 0,1,2,...,max_lag.
INPUT:
------
X : array,required
N x t data matrix
max_lag : integer,required
covariance matrices will be computed for lags 0,max_lag
OUTPUT:
------
R_tau : dictionary,keyed on the lag,with values equal to the lagged
covariance of X with the lagged version of itself.
'''
R_tau = {}
t = X.shape[1]
dim = X.shape[0]
R_tau[0] = cov(X,X)[0:dim,dim::]
for tau in range(1,max_lag+1):
for i in range(tau,t):
# create X(t) and X(t-tau)
X_t = X[:,0:t-tau]
我收到以下错误:
/Users/henry/pybss/linalg.py",line 92,in lagged_covariance
R_tau[0] = cov(X,dim::]
File "<__array_function__ internals>",line 6,in cov
File "/opt/intel/intelpython3/lib/python3.7/site-packages/numpy/lib/function_base.py",line 2371,in cov
raise ValueError("m has more than 2 dimensions")
ValueError: m has more than 2 dimensions
在我的脚本中,我像这样调用 ffdiag
:
# dimension
m=7
# number of matrices
n=2
# Load spectro and WL+GCph+XC
FISH_GCsp = np.loadtxt('Fisher_GCsp_flat.txt')
FISH_XC = np.loadtxt('Fisher_XC_GCph_WL_flat.txt')
# Marginalizing over uncommon parameters between the two matrices
COV_GCsp_first = np.linalg.inv(FISH_GCsp)
COV_XC_first = np.linalg.inv(FISH_XC)
COV_GCsp = COV_GCsp_first[0:m,0:m]
COV_XC = COV_XC_first[0:m,0:m]
# Invert to get Fisher matrix
FISH_sp = np.linalg.inv(COV_GCsp)
FISH_xc = np.linalg.inv(COV_XC)
# Drawing a random set of commuting matrices
C=np.zeros((n,m,m));
B=np.zeros((n,m));
C[0,:,:] = np.array(FISH_sp)
C[1,:] = np.array(FISH_xc)
[invV,B,ut] = ffdiag(C,10,1.0e-10,100)
但我不知道数组 C
是否定义良好:在任何情况下,我都必须传递 2 个大小为 7x7 的矩阵,但顺序是:
# dimension
m=7
# number of matrices
n=2
C=np.zeros((n,m));
或
C=np.zeros((m,n));
B=np.zeros((m,n));
或其他东西,因为上述两者似乎都不起作用。
正如你在 ffdiag 的定义中看到的,注意到:
INPUT:
------
X : array,required
N_sig x t matrix of signal mixtures
但我猜不出 X array
的结构是什么。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。