Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. import tensorflow as tf
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. %matplotlib inline
  5.  
  6. samples = 1000
  7. domain = np.array([float(i)*0.01 for i in range(samples + 1)], np.float32)
  8. sin = np.sin(domain)
  9.  
  10. tf.reset_default_graph()
  11.  
  12. time_step = 5
  13. features = 1
  14. state_size = 15
  15.  
  16. x_reshaped = tf.reshape(sin[:-1], [-1, time_step, features])
  17. y_reshaped = tf.reshape(sin[1:], [-1, time_step, features])
  18.  
  19. x = tf.unstack(x_reshaped, axis=1)
  20. y_ = tf.unstack(y_reshaped, axis=1)
  21.  
  22. rnn_cell = tf.nn.rnn_cell.BasicRNNCell(num_units=state_size)
  23. output, state = tf.nn.static_rnn(cell=rnn_cell, inputs=x, dtype=tf.float32)
  24.  
  25. kernel_init = tf.truncated_normal(shape=[time_step, state_size, features])
  26. bias_init = tf.zeros(features)
  27.  
  28. output_w = tf.Variable(kernel_init)
  29. output_b = tf.Variable(bias_init)
  30.  
  31. y = tf.matmul(output, output_w) + output_b
  32.  
  33. print(y.shape)
  34. print(len(y_), y_[0].shape)
  35.  
  36.  
  37. for t in range(time_step):
  38. print(y[t].shape, y_[t].shape)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement