Advertisement
Guest User

Untitled

a guest
May 21st, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. def systematic_resample(sess, weights):
  2. N = len(weights)
  3.  
  4. # make N subdivisions and choose positions with a random offset
  5. positions = (sess.run(tf.random.uniform((1, ))) + np.arange(N)) / N
  6.  
  7. indexes = np.zeros(N, 'i')
  8. cum_sum = np.cumsum(weights)
  9. i, j = 0, 0
  10. while i < N:
  11. if positions[i] < cum_sum[j]:
  12. indexes[i] = j
  13. i = i + 1
  14. else:
  15. j = j + 1
  16. return indexes
  17.  
  18. def resample_from_index(particles, weights, indexes):
  19. particles = particles[:, indexes]
  20. weights = weights[indexes]
  21. weights.fill(1.0 / len(weights))
  22.  
  23. return particles, weights, indexes
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement