如何使用TensorFlow创建循环变量

时间:2016-07-11 16:43:54

标签: tensorflow recurrence

这听起来非常简单但我在互联网上找不到任何信息。我可能缺乏一些基本的理解。

我想做一些简单的事情:一个循环变量。说:

 1       6       1  0.5004E+02
 2     487       1  0.3495E+02
 3      34       1  0.0344E+02
 ....

有一些固定的(但可训练的)#!/bin/bash input='input.txt' i=1 sort -nk 1 $input > 'temp.txt' while read line; do awk -v var="$i" '$1 == var' temp.txt > "cluster${i}.txt" until [[$i -lt 20]]; do i=$((i+1)) done done for f in *.txt; do sort -nk 4 > temp2.txt head -1 temp2.txt rm temp2.txt done > output.txt

我尝试过这样的事情:

Z(t) = W * Z(t-1)

但是,当然,在会话中,如果我W,则会提供initializer = tf.random_uniform_initializer(0., 1.) with tf.variable_scope('recurrent', initializer=initializer): Z = tf.get_variable('Z', shape=[...]) Z = tf.matmul(W, Z) 的连贯值,但Z.eval()本身不会更新。

因此我的问题是:如何创建一个在使用TensorFlow运行图形时更新的循环变量?

非常感谢你的帮助!

1 个答案:

答案 0 :(得分:1)

当你写一个像

这样的陈述时
Z = tf.matmul(W, Z)

您正在更新 python 变量Z,而不是与TensorFlow变量Z关联的TensorFlow内部存储。请查看TensorFlow中有状态操作的section,了解TensorFlow如何管理状态。要回答您的具体问题,您必须使用tf.assign操作更新TensorFlow的Z变量,如下所示:

Z = tf.assign(Z, tf.matmul(W, Z))