Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ def weighted_replicate(seq, weights, n):
wholes = [int(w * n) for w in weights]
fractions = [(w * n) % 1 for w in weights]
return (flatten([x] * nx for x, nx in zip(seq, wholes)) +
weighted_sample_with_replacement(seq, fractions, n - sum(wholes)))
weighted_sample_with_replacement(n - sum(wholes),seq, fractions, ))


def flatten(seqs): return sum(seqs, [])
Expand Down
2 changes: 1 addition & 1 deletion probability.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,5 +651,5 @@ def particle_filtering(e, N, HMM):
w[i] = float("{0:.4f}".format(w[i]))

# STEP 2
s = weighted_sample_with_replacement(s, w, N)
s = weighted_sample_with_replacement(N,s,w)
return s
2 changes: 1 addition & 1 deletion search.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ def genetic_algorithm(population, fitness_fn, ngen=1000, pmut=0.1):
new_population = []
for i in range(len(population)):
fitnesses = map(fitness_fn, population)
p1, p2 = weighted_sample_with_replacement(population, fitnesses, 2)
p1, p2 = weighted_sample_with_replacement(2,population, fitnesses)
child = p1.mate(p2)
if random.uniform(0, 1) < pmut:
child.mutate()
Expand Down
2 changes: 1 addition & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def probability(p):
return p > random.uniform(0.0, 1.0)


def weighted_sample_with_replacement(seq, weights, n):
def weighted_sample_with_replacement(n,seq, weights):
"""Pick n samples from seq at random, with replacement, with the
probability of each element in proportion to its corresponding
weight."""
Expand Down