阅读(3497)
赞(17)
TensorFlow的集成(contrib)
2017-08-22 14:28:39 更新
TensorFlow 的集成和 ODE 求解器。
示例:洛伦兹吸引力
我们可以用 odeint 求解常微分方程的洛伦兹系统,这是一个典型的混沌动力学例子:
rho = 28.0
sigma = 10.0
beta = 8.0/3.0
def lorenz_equation(state, t):
x, y, z = tf.unstack(state)
dx = sigma * (y - x)
dy = x * (rho - z) - y
dz = x * y - beta * z
return tf.stack([dx, dy, dz])
init_state = tf.constant([0, 2, 20], dtype=tf.float64)
t = np.linspace(0, 50, num=5000)
tensor_state, tensor_info = tf.contrib.integrate.odeint(
lorenz_equation, init_state, t, full_output=True)
sess = tf.Session()
state, info = sess.run([tensor_state, tensor_info])
x, y, z = state.T
plt.plot(x, z)
操作
- tf.contrib.integrate.odeint