python – 具有numpy的参数方程
|
我目前正在 python中实现一个称为回声状态网络(ESN)的回归神经网络(RNN),用于时间序列分类(TSC). 我想使用参数方程生成轨迹,然后训练我的神经网络对这些轨迹进行分类,就像本文中的Mickael Hüsken & Peter Stagge,Recurrent Neural Networks for Time Series Classification一样.最后,我想比较我的ESN和它们的RNN之间的性能. 以下是根据本文的三个类: 哪个应该生成这样的东西: 我生成每个类的50个轨迹,alpha是固定为0.7的浮点数,beta和t0是在0和2 * pi之间随机选择的.轨迹包含30个点,因此时间步长为(2 * pi)/ 30. 这是我的代码,我知道它不是最pythonic的方式,但它完成了第一和第三类的工作.但是,第二类仍然被窃听:( import numpy as np
import sys,getopt,random
timestep = 2.0*np.pi / 30.0
alpha = 0.7
def class1(t,beta):
return alpha*np.sin(t+beta)*np.abs(np.sin(t)),alpha*np.cos(t+beta)*np.abs(np.sin(t))
def class2(t,beta):
return alpha*np.sin(t/2.0+beta)*np.sin(3.0/2.0*t),alpha*np.cos(t+beta)*np.sin(2.0*t)
def class3(t,beta):
return alpha*np.sin(t+beta)*np.sin(2.0*t),alpha*np.cos(t+beta)*np.sin(2.0*t)
def generate():
clazz = {
'1' : class1,'2' : class2,'3' : class3
}
for classID in clazz :
for i in xrange(50):
fd = open("dataset/%s_%s"%(classID,i+1),'w')
beta = 2*np.pi*np.random.random()
t = 2*np.pi*np.random.random()
for _ in xrange(30):
fd.write("%s %sn"%clazz[classID](t,beta))
t += timestep
fd.close()
当我绘制第二类的轨迹(使用matplotlib)时,我得到一个奇怪的结果……例如: 解决方法第二个等式对我来说很奇怪,确实是 does not seem to produce the picture shown.观察第1类和第3类的等式,很容易猜出一个参数方程,它会产生一个带有三个“花瓣”的图形: def class2(t,beta):
return alpha*np.sin(t+beta)*np.sin(3*t),alpha*np.cos(t+beta)*np.sin(3*t)
然后做: for beta in [0,np.pi/3,np.pi/2]:
pylab.plot(*class2(np.linspace(0,np.pi,100),beta),label='$beta={:.3f}$'.format(beta))
pylab.legend()
得到: (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
