def foward_error (n,m,ans,NN): data=np.load('data.npy') #from loadone1 import load_sample as load w1=np.zeros((5,5,1,3,5)) w2=np.zeros((5,5,3,6,5)) wf1=np.zeros((7*7*2*3, 1024,5)) bf1=np.zeros((1024,5)) T=0 #m=np.array([0,3,6]) #M12,a12=load(data[:,:,m,12]) i=0 while i<5: w,ww,Num=train_cov(data[:,:,m,n],200,3,8) if Num==1: w1[:,:,:,:,i]=w w2[:,:,:,:,i]=ww i+=1 for i in range (0,5): wf1[:,:,i],bf1[:,i],Num=train_fcon(data[:,:,:,n],w1[:,:,:,:,i],w2[:,:,:,:,i],50,8) if Num==1: T=T+1 EE=np.zeros((8,5)) for j in range (0,5): II=forward(data[:,:,:,n],w1[:,:,:,:,j],w2[:,:,:,:,j]) error01=II[1,:]-II[0,:] error12=II[2,:]-II[1,:] error34=II[4,:]-II[3,:] error54=II[5,:]-II[4,:] error67=II[7,:]-II[6,:] error78=np.zeros((8,294)) for i in range (0,8): error78[i,:]=II[8+i,:]-II[7,:] O1=np.dot(error67.reshape(1,294),wf1[:,:,j])+bf1[:,j] O2=np.zeros((8,1024)) for i in range (0,8): O2[i,:]=np.dot(error78[i,:].reshape(1,294),wf1[:,:,j])+bf1[:,j] E=np.zeros(8) for i in range (0,8): E[i]=abs(O2[i,:]-O1).sum() EE[:,j]=E N=np.zeros(5) for i in range (0,5): N[i]=np.argmin(EE[:,i]) print(np.argmin(np.average(EE,axis=1))) print(np.argsort(np.average(EE,axis=1))) print(np.average(EE,axis=1)[ans]/np.average(EE,axis=1).mean()) print(N) print(T) np.save('Data/'+str(NN)+'weight1_no_rotation_rerun_v.npy',w1) np.save('Data/'+str(NN)+'weight2_no_rotation_rerun_v.npy',w2) np.save('Data/'+str(NN)+'weightf_no_rotation_rerun_v.npy',wf1) np.save('Data/'+str(NN)+'biasf_no_rotation_rerun_v.npy',bf1) np.save('Data/'+str(NN)+'Error_no_rotation_rerun_v.npy',EE) np.save('Data/'+str(NN)+'Termination_no_rotation_rerun_v.npy',T)
def foward_error (n,m,ans,N_str): data=np.load('data_4.npy') #from loadone1 import load_sample as load w1=np.zeros((5,5,1,3,5)) w2=np.zeros((5,5,3,6,5)) wf1=np.zeros((180, 1024,5)) bf1=np.zeros((1024,5)) T=0 #m=np.array([0,3,6]) #M12,a12=load(data[:,:,m,12]) i=0 while i<5: w,ww,Num=train_cov(data[:,:,m,n],200,3,8) if Num==1: w1[:,:,:,:,i]=w w2[:,:,:,:,i]=ww i+=1 for i in range (0,5): wf1[:,:,i],bf1[:,i],Num=train_fcon(data[:,:,:,n],w1[:,:,:,:,i],w2[:,:,:,:,i],50,8) if Num==1: T=T+1 # EE=np.zeros((6,5)) # EE2=np.zeros((6,5)) # for j in range (0,5): # II=forward(data[:,:,:,n],w1[:,:,:,:,j],w2[:,:,:,:,j]) # error01=II[1,:]-II[0,:] # error02=II[2,:]-II[0,:] # error23=np.zeros((6,180)) # error13=np.zeros((6,180)) # for i in range (1,7): # error23[i-1,:]=II[2+i,:]-II[2,:] # for i in range (1,7): # error13[i-1,:]=II[2+i,:]-II[1,:] # O1=np.dot(error01.reshape(1,180),wf1[:,:,j])+bf1[:,j] # O2=np.zeros((6,1024)) # for i in range (0,6): # O2[i,:]=np.dot(error23[i,:].reshape(1,180),wf1[:,:,j])+bf1[:,j] # E=np.zeros(6) # for i in range (0,6): # E[i]=abs(O2[i,:]-O1).sum() # EE[:,j]=E # O3=np.dot(error02.reshape(1,180),wf1[:,:,j])+bf1[:,j] # O4=np.zeros((6,1024)) # for i in range (0,6): # O4[i,:]=np.dot(error13[i,:].reshape(1,180),wf1[:,:,j])+bf1[:,j] # EEE=np.zeros(6) # for i in range (0,6): # EEE[i]=abs(O4[i,:]-O3).sum() # EE2[:,j]=EEE # N=np.zeros(5) # for i in range (0,5): # N[i]=np.argmin(EE[:,i]) # NN=np.zeros(5) # for i in range (0,5): # NN[i]=np.argmin(EE2[:,i]) # NNN=np.zeros(5) # for i in range (0,5): # NNN[i]=np.argmin(EE2[:,i]+EE[:,i]) # print('x direction error:',np.argsort(np.average(EE,axis=1))) # print('y direction error:',np.argsort(np.average(EE2,axis=1))) # print('normalized correct x direction error:',np.average(EE,axis=1)[ans]/np.average(EE,axis=1).mean()) # print('normalized correct y direction error:',np.average(EE2,axis=1)[ans]/np.average(EE2,axis=1).mean()) # print('sum error:',np.argsort(np.average(EE2+EE,axis=1))) # print('normalized correct sum error:',np.average(EE2+EE,axis=1)[ans]/np.average(EE+EE2,axis=1).mean()) # print('number of correct trials, x:',N) # print('number of correct trials, y:',NN) # print(T) np.save('Data/'+str(N_str)+'weight1_t.npy',w1) np.save('Data/'+str(N_str)+'weight2_t.npy',w2) np.save('Data/'+str(N_str)+'weightf_t.npy',wf1) np.save('Data/'+str(N_str)+'biasf_t.npy',bf1) # np.save('Data/'+str(N_str)+'Error.npy',EE) # np.save('Data/'+str(N_str)+'Error.npy',EE2) # np.save('Data/'+str(N_str)+'Termination.npy',T)