m - 1 ) #attention to this (L)term, which should be (1:L) in case of more obs(??) #print 'idxs', idxs S[:, idxs:idxs + L] = np.dot(h, xx) #####MORE OBS##### #print 'S at m', m, 'is', S #idy = n+(m-1)*nTau Y[:, idxs:idxs + L] = y[0:L, n + (m - 1) * nTau] #####MORE OBS##### #print 'Y at m', m, 'is', Y dsdx[idxs:idxs + L, :] = np.dot(h, Jac) #####MORE OBS##### #print 'dsdx', dsdx #print 'dsdx', dsdx ########dxds = np.linalg.pinv(dsdx,rcond=pinv_tol) #dxds = dxds.round(decimals=4) # Applied this as it was appearing in matlab code (1st row 1 0 0 0...) U, G, V = mod.svd(dsdx) #print 'U', U.shape #print 'G', G.shape # All positive values, for good or bad runs. #print 'V', V.shape #print 'ln(G)', np.log(G) ################### Calculating singular values, condition number, observability and ratios ######################## svmin = np.min(G) #print 'Smallest sing value:', svmin #no influence until now...(around e-03) svmax = np.max(G) #print 'Largest sing value:', svmax svmaxvec[:, n] = svmax svmaxvec2[:, n] = G[1] difmax = abs(svmaxvec[:, n] - svmaxvec[:, n - 1]) difmax2 = abs(svmaxvec2[:, n] - svmaxvec2[:, n - 1]) ###difmax = svmaxvec[:,n] - svmaxvec[:,n-1]
#Defining S (map from physical space to a delay embedding space) and Y(data vector) idxs = L*(m-1) #+ (L) # attention to this (L)term, which should be (1:L) in case of more obs #print 'idxs', idxs S[:,idxs] = np.dot(h,xx) #print 'S at m', m, 'is', S.shape #idy = n+(m-1)*nTau Y[:,idxs] = y[:,n+(m-1)*nTau] # attention to y(0,...), which should increase in case of more obs dsdx[idxs,:] = np.dot(h,Jac) #print 'dsdx', dsdx #Calculating the pseudoinverse through python function dxds = np.linalg.pinv(dsdx,rcond=pinv_tol) #rcond from python function already does Matlab's code job #dxds = dxds.round(decimals=4) # Applied this as it was appearing in matlab code (1st row 1 0 0 0...) #Calculating the pseudoinverse through svd calculation U, G, V = mod.svd(dsdx) #print 'U', U.shape #print 'G', G # All positive values, for good or bad runs. #print 'V', V.shape #print 'ln(G)', np.log(G) mask = np.ones(len(G)) for k in range(len(G)): #mask = np.ones(len(G)) if G[k] >= pinv_tol: mask[k] = 1 else: mask[k] = 0 #print 'mask', mask r = min(max_pinv_rank,sum(mask)) #print 'r is', r g = G[:r]**(-1)
newinv = (11.*R) #print 'R', R #print 'newinv', newinv for i in range(len(R)): newinv[i,i]=(newinv[i,i])**(-1) #print 'newinv', newinv ####HKHT = np.dot(dsdx,np.dot(K,(np.transpose(dsdx)))) ####HPHT = np.dot(dsdx,np.dot(P,(np.transpose(dsdx)))) ####HKHT = np.dot(dsdx,np.dot(K,(np.transpose(dsdx))))+R ####HPHT = np.dot(dsdx,np.dot(P,(np.transpose(dsdx))))+R #### Calculating the inverse of HPHT (KF structure) through SVD #### U, G, V = mod.svd(HHT) # considering P=1 ####U, G, V = mod.svd(HKHT) ####U, G, V = mod.svd(HPHT) ####U, G, V = mod.svd(gama) ################### Last 3 singular values ######################### svmin = np.min(G) svmin2 = G[M-2] #svmin3 = G[M-3] ################## Modifying G to use the max_pinv_rank ############ mask = np.ones(len(G)) for k in range(len(G)):
######Y[:,t] = y[:,n+(t*nTau)] ####Y[:,t] = y[:,n+t] #Y[:,idxs] = y[:,s*nTau] #print 'S', S #print 'Y', Y #print 'P1HT', P1HT[0,:] #print 'HPHT_KS', HPHT_KS[0,:] #HPHT_KS = HPHT_KS + R #print 'HPHT_KS After', HPHT_KS ########## Calculating the equivalent for KS structure############## #### Calculating the inverse of HPHT through SVD #### U, G, V = mod.svd(HPHT_KS) # considering R=0 #print 'G', G #### Modifying G to use the max_pinv_rank ########### mask = np.ones(len(G)) for k in range(len(G)): if G[k] >= pinv_tol: mask[k] = 1 else: mask[k] = 0 rr = min(max_pinv_rank, sum(mask)) g = G[:rr]**(-1) #print 'g', g Ginv = np.zeros((M, M)) Ginv[:rr, :rr] = np.diag(g)
######Y[:,t] = y[:,n+(t*nTau)] ####Y[:,t] = y[:,n+t] #Y[:,idxs] = y[:,s*nTau] #print 'S', S #print 'Y', Y #print 'P1HT', P1HT[0,:] #print 'HPHT_KS', HPHT_KS[0,:] #HPHT_KS = HPHT_KS + R #print 'HPHT_KS After', HPHT_KS ########## Calculating the equivalent for KS structure############## #### Calculating the inverse of HPHT through SVD #### U, G, V = mod.svd(HPHT_KS) # considering R=0 #print 'G', G #### Modifying G to use the max_pinv_rank ########### mask = np.ones(len(G)) for k in range(len(G)): if G[k] >= pinv_tol: mask[k] = 1 else: mask[k] = 0 rr = min(max_pinv_rank,sum(mask)) g = G[:rr]**(-1) #print 'g', g Ginv = np.zeros((M, M)) Ginv[:rr, :rr] = np.diag(g)
#####for i in range(len(R)): #####newinv[i,i]=(newinv[i,i])**(-1) #print 'newinv', newinv ####HKHT = np.dot(dsdx,np.dot(K,(np.transpose(dsdx)))) ####HPHT = np.dot(dsdx,np.dot(P,(np.transpose(dsdx)))) ####HKHT = np.dot(dsdx,np.dot(K,(np.transpose(dsdx))))+R ####HPHT = np.dot(dsdx,np.dot(P,(np.transpose(dsdx))))+R #### Calculating the inverse of HPHT (KF structure) through SVD #### ####U, G, V = mod.svd(HHT) # considering P=1 ####U, G, V = mod.svd(HKHT) ####U, G, V = mod.svd(HPHT) U, G, V = mod.svd(gama) ################### Last 3 singular values ######################### svmin = np.min(G) svmin2 = G[M-2] #svmin3 = G[M-3] ################## Modifying G to use the max_pinv_rank ############ mask = np.ones(len(G)) for k in range(len(G)): if G[k] >= pinv_tol: mask[k] = 1 else:
#####for i in range(len(R)): #####newinv[i,i]=(newinv[i,i])**(-1) #print 'newinv', newinv ####HKHT = np.dot(dsdx,np.dot(K,(np.transpose(dsdx)))) ####HPHT = np.dot(dsdx,np.dot(P,(np.transpose(dsdx)))) ####HKHT = np.dot(dsdx,np.dot(K,(np.transpose(dsdx))))+R ####HPHT = np.dot(dsdx,np.dot(P,(np.transpose(dsdx))))+R #### Calculating the inverse of HPHT (KF structure) through SVD #### ####U, G, V = mod.svd(HHT) # considering P=1 ####U, G, V = mod.svd(HKHT) ####U, G, V = mod.svd(HPHT) U, G, V = mod.svd(gama) ################### Last 3 singular values ######################### svmin = np.min(G) svmin2 = G[M - 2] #svmin3 = G[M-3] ################## Modifying G to use the max_pinv_rank ############ mask = np.ones(len(G)) for k in range(len(G)): if G[k] >= pinv_tol: mask[k] = 1 else: mask[k] = 0
#dxds = dxds.round(decimals=4) # Applied this as it was appearing in matlab code (1st row 1 0 0 0...) ### Constructing Sherman-Morrison-Woodbury format of calculating the Kalman gain to compare with synch ### Pinverse = np.linalg.pinv(Jac0) #print 'Pinverse', Pinverse sigmaP = np.dot(sigma2,Pinverse) SS = np.dot(np.transpose(dsdx),dsdx) sigmaPSS = sigmaP + SS #print 'sigmaPSS shape', sigmaPSS.shape ############ Calculating the inverse using SVD decomposition ################ #U, G, V = mod.svd(dsdx) U, G, V = mod.svd(sigmaPSS) #print 'U', U #print 'G', G # All positive values, for good or bad runs. #print 'V', V #print 'ln(G)', np.log(G) ##### Calculating singular values, condition number, observability and ratios ###### svmin = np.min(G) #svminrank = svmin #print 'Smallest sing value:', svmin #no influence until now...(around e-03) svmax = np.max(G) #print 'Largest sing value:', svmax svmaxvec[:,n] = svmax svmaxvec2[:,n] = G[1] difmax = abs(svmaxvec[:,n] - svmaxvec[:,n-1]) difmax2 = abs(svmaxvec2[:,n] - svmaxvec2[:,n-1])
#print 'idxs', idxs S[:,idxs] = np.dot(h,xx) #print 'S at m', m, 'is', S.shape #idy = n+(m-1)*nTau Y[:,idxs] = y[:,n+(m-1)*nTau] # attention to y(0,...), which should increase in case of more obs dsdx[idxs,:] = np.dot(h,Jac) #print 'dsdx', dsdx ########dxds = np.linalg.pinv(dsdx,rcond=pinv_tol) #dxds = dxds.round(decimals=4) # Applied this as it was appearing in matlab code (1st row 1 0 0 0...) ###HHT = np.dot(dsdx,(np.transpose(dsdx))) HP = np.dot(dsdx,K) HPHT = np.dot(HP,(np.transpose(dsdx))) #print 'HPHT', HPHT U, G, V = mod.svd(HPHT) #print 'V', V.shape mask = np.ones(len(G)) for k in range(len(G)): if G[k] >= pinv_tol: mask[k] = 1 else: mask[k] = 0 rr = min(max_pinv_rank,sum(mask)) g = G[:rr]**(-1) Ginv = np.zeros((M, M)) Ginv[:rr, :rr] = np.diag(g)
#print 'S at m', m, 'is', S.shape #idy = n+(m-1)*nTau Y[:, idxs] = y[:, n + ( m - 1 ) * nTau] # attention to y(0,...), which should increase in case of more obs dsdx[idxs, :] = np.dot(h, Jac) #print 'dsdx', dsdx ########dxds = np.linalg.pinv(dsdx,rcond=pinv_tol) #dxds = dxds.round(decimals=4) # Applied this as it was appearing in matlab code (1st row 1 0 0 0...) ###HHT = np.dot(dsdx,(np.transpose(dsdx))) HP = np.dot(dsdx, K) HPHT = np.dot(HP, (np.transpose(dsdx))) #print 'HPHT', HPHT U, G, V = mod.svd(HPHT) #print 'V', V.shape mask = np.ones(len(G)) for k in range(len(G)): if G[k] >= pinv_tol: mask[k] = 1 else: mask[k] = 0 rr = min(max_pinv_rank, sum(mask)) g = G[:rr]**(-1) Ginv = np.zeros((M, M)) Ginv[:rr, :rr] = np.diag(g)
newinv = (11. * R) #print 'R', R #print 'newinv', newinv for i in range(len(R)): newinv[i, i] = (newinv[i, i])**(-1) #print 'newinv', newinv ####HKHT = np.dot(dsdx,np.dot(K,(np.transpose(dsdx)))) ####HPHT = np.dot(dsdx,np.dot(P,(np.transpose(dsdx)))) ####HKHT = np.dot(dsdx,np.dot(K,(np.transpose(dsdx))))+R ####HPHT = np.dot(dsdx,np.dot(P,(np.transpose(dsdx))))+R #### Calculating the inverse of HPHT (KF structure) through SVD #### U, G, V = mod.svd(HHT) # considering P=1 ####U, G, V = mod.svd(HKHT) ####U, G, V = mod.svd(HPHT) ####U, G, V = mod.svd(gama) ################### Last 3 singular values ######################### svmin = np.min(G) svmin2 = G[M - 2] #svmin3 = G[M-3] ################## Modifying G to use the max_pinv_rank ############ mask = np.ones(len(G)) for k in range(len(G)): if G[k] >= pinv_tol: