我試圖用Theano計算兩個信號的circular cross-correlation,以便進一步計算我將優化的損耗。但我不太確定如何做到這一點。Theano中的圓形相關
它被定義爲以下:
(f * g)[n] = sum_k f[k]g[k+n]
ccc[n] = \sum_k (f*g)[n-kN]
- 「週期性」 求和或類似的 「對於每個k個分量」。
我可以做一個普通的相關性,然後定期進行總結,但它不是很清楚該怎麼做(定期和)象徵性地(使用掃描,大概?)
conv2d = T.signal.conv.conv2d
x = T.dmatrix()
y = T.dmatrix()
veclen = x.shape[1]
corr_expr = conv2d(x, y[:, ::-1], image_shape=(1, veclen), border_mode='full')
# circ_corr = T.sum([corr_expr[k::veclen] for k in T.arange(veclen)])
corr = theano.function([x, y], outputs=circ_corr)
corr(np.array([[2, 3, 5]]), np.array([[7, 11, 13]]))
或使用圓形截面-correlation定理和計算的IFFT(FFT(X)* FFT(Y)):
import theano.sandbox.fourier as dft
x = T.dmatrix()
y = T.dvector()
veclen = x.shape[1]
exp = T.real(
dft.ifft(
dft.fft(x, veclen, axis=1)
* dft.fft(y[::-1], y.shape[0], axis=1).reshape((1, -1)),
veclen, axis=1
)
)[:, ::-1]
f = theano.function([x, y], outputs=exp)
f(np.array([[2, 3, 5], [3, 4, 4], [5, 6, 7]]), np.array([7, 11, 13]))
但在這種情況下,我不能實際計算梯度,因爲梯度IFFT(和具有的東西全部功能與一般複數相關人,據我所知)是尚未實現,我想(中止同一個錯誤:Elemwise{real,no_inplace}.grad illegally returned an integer-valued variable. (Input index 0, dtype complex128)
)
StackOverflow是一個問答網站,但您沒有提出任何問題。目前還不清楚你和你的代碼試圖實現什麼。有什麼意義?這段代碼有什麼問題?如果適用,您收到了哪些錯誤消息?什麼是示例輸入及其預期輸出? –
@DanielRenshaw,好吧,我認爲標題「Theano中的圓形相關性」是相當不言自明的:) –
我認爲找到StackOverflow上熟悉循環相關,熟悉Theano並有時間閱讀和解釋你的代碼,很渺茫!提供更多輔助材料/鏈接/等。將幫助那些僅僅部分滿足這些要求的人提供幫助。 –