Holomorphism, also called analyticity, ensures that a complex-valued function is complex differentiable in the neighborhood of every point in its domain. This means that the derivative, of , exists at every point in the domain of where is a complex-valued function of a complex variable such that 。和均为实值函数,所以可以使用 表达。可以从不同的方向逼近0(实轴、虚轴、实轴与虚轴之间)。为了复数可微分,不管从哪个方向逼近0,值应该都相同。当从实轴逼近0的时候,可以写成:
# we compare the correct and incorrect back propagation defnaive_backward(df_z, df_zc): ''' naive back propagation meta formula, df_z and df_zc are dirivatives about variables and variables' conjugate. ''' returnlambda x, y, dy: df_z(x, y) * dy
defcorrect_backward(df_z, df_zc): '''the correct version.''' returnlambda x, y, dy: df_z(x, y) * dy +\ df_zc(x, y).conj() * dy.conj()
# the version in naive bp f1_backward_naive = naive_backward(df1_z, df1_zc) f2_backward_naive = naive_backward(df2_z, df2_zc)
defforward(x): '''forward pass''' yl = [x] for i in range(num_layers): if i == num_layers - 1: x = f2_forward(x) else: x = f1_forward(x) yl.append(x) return yl
defbackward(yl, version):# version = 'correct' or 'naive' ''' back propagation, yl is a list of outputs. ''' dy = 1 * np.ones(num_input, dtype='complex128') for i in range(num_layers): y = yl[num_layers - i] x = yl[num_layers - i - 1] if i == 0: dy = eval('f2_backward_%s' % version)(x, y, dy) else: dy = eval('f1_backward_%s' % version)(x, y, dy) return dy.conj() if version == 'correct'else dy
defoptimize_run(version, alpha=0.1): '''simple optimization for target loss function.''' cost_histo = [] x = a0.copy() num_run = 2000 for i in range(num_run): yl = forward(x) g_a = backward(yl, version) x[:num_input] = (x - alpha * g_a)[:num_input] cost_histo.append(yl[-1].sum().real) return np.array(cost_histo)
[1] Akira Hirose and Shotaro Yoshida. Generalization characteristics of complex-valued feedforward neural networks in relation to signal coherence. IEEE Transactions on Neural Networks and learning systems, 23(4): 541–551, 2012.
Gitalking ...