Created
December 23, 2019 06:26
-
-
Save hccho2/44f93fb34ff0470b8c2eec3214c84e7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import tensorflow as tf | |
import matplotlib.pyplot as plt | |
tf.compat.v1.reset_default_graph() | |
x = np.sin(np.linspace(0,3*np.pi,30))+ np.random.randn(30)*0.1 | |
filter = np.sin(np.linspace(np.pi/2-np.pi/6,np.pi/2+np.pi/6,5)) | |
x = np.array([ 0.15056179, 0.30541199, 0.72807816, 0.940651 , 0.97211703, | |
1.01255197, 0.86129876, 0.71344136, 0.56986685, 0.24477384, | |
-0.01567925, -0.29397656, -0.7427353 , -0.96051523, -0.92409656, | |
-1.09632185, -1.03468747, -0.70415137, -0.43263368, -0.10620422, | |
0.00126833, 0.50176941, 0.74617082, 1.01136882, 1.01184374, | |
1.02194784, 0.81796091, 0.4132255 , 0.38143445, 0.07454849]) | |
filter = np.array([0.8660254 , 0.96592583, 1. , 0.96592583, 0.8660254 ]) | |
x_ = tf.reshape(tf.convert_to_tensor(x),[1,-1,1]) | |
filter_ = tf.reshape(tf.convert_to_tensor(filter),[-1,1,1]) | |
y_ = tf.squeeze(tf.nn.conv1d(x_,filter_,stride=1,padding='VALID')) | |
sess= tf.Session() | |
y=sess.run(y_) | |
z1, = plt.plot(np.arange(30),x,label='data',marker='o') | |
z2, = plt.plot(np.arange(5),filter*3,label='filter',marker='o') | |
z3, =plt.plot(np.arange(1,27),y*0.5,label='result',marker='o') | |
plt.legend(handles=[z1,z2,z3],loc='upper center') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
비대칭 filter인 경우, 결과가 일치하는 patten에서 최대치를 형성하지는 않는다.
예를 들어, sin곡선의 앞부분을 filter로 했을 때, 원래 sin곡선보다 약간 왼쪽으로 shift된 결과를 얻는다.