Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def systematic_resample(sess, weights):
- N = len(weights)
- # make N subdivisions and choose positions with a random offset
- positions = (sess.run(tf.random.uniform((1, ))) + np.arange(N)) / N
- indexes = np.zeros(N, 'i')
- cum_sum = np.cumsum(weights)
- i, j = 0, 0
- while i < N:
- if positions[i] < cum_sum[j]:
- indexes[i] = j
- i = i + 1
- else:
- j = j + 1
- return indexes
- def resample_from_index(particles, weights, indexes):
- particles = particles[:, indexes]
- weights = weights[indexes]
- weights.fill(1.0 / len(weights))
- return particles, weights, indexes
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement