2016-09-16 4 views
0

への入力を渡すために効率的な方法がある:私はコメントとしてコードでこれを言及しているがTensorflow:私のコードがどのように見えるか、反復プログラムここで

N = 16, num_ckfs = 5 
init_variances = tf.placeholder(tf.float64, shape=[ num_ckfs, N],name='inital_variances') 

init_states = tf.placeholder(tf.float64, shape=[num_ckfs, N], name='init_states') 

#some more code 

predicted_state = prior_state_expanded + kalman_gain * diff_expanded 

error_covariance = sum_cov_cholesky + tf.batch_matmul(kg , kalman_gain, adj_x=True) 


projected_output = tf.batch_matmul(predicted_state,input_vectors_extra, adj_y=True) 

session = tf.Session() 


init_var = [10 for i in range(N)] 
init_var_ckfs = [init_var for i in range(num_ckfs)] 



init_state = [0 for i in range(N)] 
init_state_ckfs = [init_state for i in range(num_ckfs)] 

for timestep in range(10): 

    out= session.run([projected_output, predicted_state, error_covariance], {init_variances:init_var_ckfs, init_states:init_state_ckfs }) 

    #for the next tilmestep, I want to initialize init_state_ckfs with the predicted_state, and the init_var_ckfs with error_covariance. 
    #predicted_state is a tensor with shape (num_ckfs, 1, N) 
    #error_covariance is a tensor with shape (num_ckfs, N, N): I just need the diagonal elements from each of the N X N matrices 

、私はここで再びそれを言及します。私は前のタイムステップから更新されたテンソルをリストに変換し、次のタイムステップの入力としてそれらを供給することによって、どのように更新されたテンソルを使用するかを知りたいと思っています。誰か助けてくれますか?

答えて

1

tf.assignを使用して、変数の最後の値をプレースホルダに割り当てます。セッションがアクティブである限り、状態は保持されます

+0

あなたは簡単な例を提供してください – user1274878

関連する問題