<jupyter_start><jupyter_text>A convolution is essentially a correlation after mirroring the kernel. As a result, the origin parameter behaves differently than in the case of a correlation: the results is shifted in the opposite direction.  卷积的物理意义f(t) 是信号相对于时间的函数, g(t) 是系统对于信号的响应相对于时间的函数那么在某个时刻, 系统对于信号的响应的叠加, 即为 f(t)*g(t-x), 在 x 上的积分卷积公式只适用于 **线性时不变系统**, 线性表示系统的响应相对于信号是线性的, 时不变表示信号和系统对信号的响应的函数与时刻无关<jupyter_code>convtop = convolve(images[0], np.rot90(top,2))
plot(convtop)
np.allclose(convtop, corrtop)
straights=[np.rot90(top,i) for i in range(4)]
plots(straights)
br=[[ 0, 0, 1],
    [ 0, 1,-1.5],
    [ 1,-1.5, 0]]

diags = [np.rot90(br,i) for i in range(4)]
plots(diags)
rots = straights + diags
plots(rots)
corrs = [correlate(images[0], rot) for rot in rots]
plots(corrs)
def pool(im): return block_reduce(im, (7,7), np.max)

plots([pool(im) for im in corrs])
eights=[images[i] for i in xrange(n) if labels[i]==8]
ones=[images[i] for i in xrange(n) if labels[i]==1]
plots(eights[:5])
plots(ones[:5])
pool8 = [np.array([pool(correlate(im, rot)) for im in eights]) for rot in rots]
len(pool8), pool8[0].shape
plots(pool8[0][0:5])
def normalize(arr): return (arr-arr.mean())/arr.std()
filts8 = np.array([ims.mean(axis=0) for ims in pool8])
filts8 = normalize(filts8)
plots(filts8)
pool1 = [np.array([pool(correlate(im, rot)) for im in ones]) for rot in rots]
filts1 = np.array([ims.mean(axis=0) for ims in pool1])
filts1 = normalize(filts1)
plots(filts1)
def pool_corr(im): return np.array([pool(correlate(im, rot)) for rot in rots])
plots(pool_corr(eights[0]))
def sse(a,b): return ((a-b)**2).sum()
def is8_n2(im): return 1 if sse(pool_corr(im),filts1) > sse(pool_corr(im),filts8) else 0
sse(pool_corr(eights[0]), filts8), sse(pool_corr(eights[0]), filts1)
[np.array([is8_n2(im) for im in ims]).sum() for ims in [eights,ones]]
[np.array([(1-is8_n2(im)) for im in ims]).sum() for ims in [eights,ones]]
def n1(a,b): return (np.fabs(a-b)).sum()
def is8_n1(im): return 1 if n1(pool_corr(im),filts1) > n1(pool_corr(im),filts8) else 0
[np.array([is8_n1(im) for im in ims]).sum() for ims in [eights,ones]]
[np.array([(1-is8_n1(im)) for im in ims]).sum() for ims in [eights,ones]]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17798913043478262, 'fraction_numerical': 0.036231884057971016, 'mean_word_length': 6.3879598662207355, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '401147', 'license': 'Apache-2.0', 'n_tokens_mistral': 1054, 'n_tokens_neox': 1037, 'n_words': 234, 'path': 'deeplearning1/nbs/convolution-intro.ipynb', 'repo_name': 'taot/fastai-courses', 'size': '2208'}