|
- import numpy as np
- import numpy.linalg as la
- import re
- import math
- import tensorflow as tf
-
-
- def estimate_A(X_,Y_):
- # convert numpy array
- X_=np.array(X_)
- Y_=np.array(Y_)
- #convert to complex
- shape_x=[X_.shape[0], X_.shape[1],X_.shape[2]]
- shape_y = [Y_.shape[0], Y_.shape[1], Y_.shape[2]]
- X_c=np.zeros(shape=shape_x)*1j
- Y_c=np.zeros(shape=shape_y)*1j
- X_c=X_[:,:,:,0]+X_[:,:,:,1]*1j
- Y_c=Y_[:,:,:,0]+Y_[:,:,:,1]*1j
-
- batch_t=X_.shape[0]
-
- #---- X_1, X_2 ->[X_1, X_2, X_3]
- X_l=X_c[0]
- Y_l=Y_c[0]
- for batch in range(batch_t-1):
- X_l=np.concatenate((X_l,X_c[batch+1]),axis=-1)
- Y_l=np.concatenate((Y_l,Y_c[batch+1]),axis=-1)
-
- assert X_l.shape==(X_.shape[1], X_.shape[2]*X_.shape[0])
-
- x_inv=np.linalg.pinv(X_l)
-
- A=np.dot(Y_l,x_inv)
- return A
-
- def oracle_function(A,h_label,inputs,h_real,M):
- batch,D,ante,_=inputs.shape
- _,num=h_label.shape
- user_num=num/(M+1)
- A=np.array(A)
- MSE=[]
- h_label=np.array(h_label)
- h_real=np.array(h_real)
-
- for t in range(batch):
- index=[]
- y=tf.complex(inputs[t,:,:,0],inputs[t,:,:,1])
- h = tf.complex(h_real[t,:,:,0],h_real[t,:,:,1])
-
- y=np.array(y)
- h=np.array(h)
-
- for tt in range(int(user_num)): # find the index of A_O
- if h_label[t,(M+1)*tt]==0.0:
- index.append(tt)
-
- A_O=A[:,index]
-
- A_O_H=np.real(np.transpose(A_O))-np.imag(np.transpose(A_O))*1j
- inv=np.linalg.inv(np.dot(A_O_H,A_O))
- x_esti=np.dot(np.dot(inv,A_O_H),y) # oracl performance (A_OTA_O)-1A_OTy
- mse=np.sum(np.abs(x_esti-h[index,:])**2)/user_num/ante
- MSE.append(mse)
-
- return np.mean(MSE)
|