def mult_test(self, xhat_re, xhat_im, shat_re, shat_im): # log layer of xhat: Xhat Xhat_re, Xhat_im = clog(xhat_re, xhat_im) # log layer of shat: Shat Shat_re, Shat_im = clog(shat_re, shat_im) # multiplication of Xhat and Shat in log space: Yhat Yhat1_re, Yhat1_im = cdot(self.Xhat_to_Yhat_re, self.Xhat_to_Yhat_im, Xhat_re, Xhat_im) Yhat2_re, Yhat2_im = cdot(self.Shat_to_Yhat_re, self.Shat_to_Yhat_im, Shat_re, Shat_im) Yhat_re = Yhat1_re + Yhat2_re Yhat_im = Yhat1_im + Yhat2_im # exp layer of Yhat: yhat yhat_re, yhat_im = cexp(Yhat_re, Yhat_im) return yhat_re, yhat_im
def output(self, x, output_y_im=False): # DFT layer of x: xhat xhat_re, xhat_im = cdot(self.x_to_xhat_re, self.x_to_xhat_im, x, T.zeros_like(x)) # log layer of xhat: Xhat Xhat_re, Xhat_im = clog(xhat_re, xhat_im) # multiplication of Xhat and Shat in log space: Yhat Yhat_re, Yhat_im = cdot(self.Xhat_to_Yhat_re, self.Xhat_to_Yhat_im, Xhat_re, Xhat_im) # exp layer of Yhat: yhat yhat_re, yhat_im = cexp(Yhat_re, Yhat_im) # inverse DFT layer of yhat: y y_re, y_im = cdot(self.yhat_to_y_re, self.yhat_to_y_im, yhat_re, yhat_im) if not output_y_im: # output is real part of y return y_re else: return y_re, y_im
def output(self, x, s, s_weight): # DFT layer of x: xhat xhat_re, xhat_im = cdot(self.x_to_xhat_re, self.x_to_xhat_im, x, T.zeros_like(x)) # DFT layer of s / shift calculation: shat shat_re, shat_im = cdot(self.s_to_shat_re, self.s_to_shat_im, s, T.zeros_like(s)) # log layer of xhat: Xhat Xhat_re, Xhat_im = clog(xhat_re, xhat_im) if self.arch == 'conv': # log layer of shat: Shat Shat_re, Shat_im = clog(shat_re, shat_im) elif self.arch == 'comp': # linear transfer function for shat Shat_re, Shat_im = shat_re, shat_im else: assert False # multiplication of Xhat and Shat in log space: Yhat Yhat1_re, Yhat1_im = cdot(self.Xhat_to_Yhat_re, self.Xhat_to_Yhat_im, Xhat_re, Xhat_im) Yhat2_re, Yhat2_im = cdot(self.Shat_to_Yhat_re, self.Shat_to_Yhat_im, Shat_re, Shat_im) Yhat_re = Yhat1_re + s_weight * Yhat2_re Yhat_im = Yhat1_im + s_weight * Yhat2_im # exp layer of Yhat: yhat yhat_re, yhat_im = cexp(Yhat_re, Yhat_im) # inverse DFT layer of yhat: y y_re, y_im = cdot(self.yhat_to_y_re, self.yhat_to_y_im, yhat_re, yhat_im) return y_re, y_im
def output(self, x, s, output_y_im=False): # DFT layer of x: xhat xhat_re, xhat_im = cdot(self.x_to_xhat_re, self.x_to_xhat_im, x, T.zeros_like(x)) # DFT layer of s: shat shat_re, shat_im = cdot(self.s_to_shat_re, self.s_to_shat_im, s, T.zeros_like(s)) # log layer of xhat: Xhat Xhat_re, Xhat_im = clog(xhat_re, xhat_im) # log layer of shat: Shat #Shat_re, Shat_im = shat_re, shat_im Shat_re, Shat_im = clog(shat_re, shat_im) # multiplication of Xhat and Shat in log space: Yhat Yhat1_re, Yhat1_im = cdot(self.Xhat_to_Yhat_re, self.Xhat_to_Yhat_im, Xhat_re, Xhat_im) Yhat2_re, Yhat2_im = cdot(self.Shat_to_Yhat_re, self.Shat_to_Yhat_im, Shat_re, Shat_im) Yhat_re = Yhat1_re + Yhat2_re Yhat_im = Yhat1_im + Yhat2_im # exp layer of Yhat: yhat yhat_re, yhat_im = cexp(Yhat_re, Yhat_im) # inverse DFT layer of yhat: y y_re, y_im = cdot(self.yhat_to_y_re, self.yhat_to_y_im, yhat_re, yhat_im) if not output_y_im: # output is real part of y return y_re else: return y_re, y_im