Skip to content

Instantly share code, notes, and snippets.

@fedden
Created November 27, 2017 14:23
Show Gist options
  • Save fedden/1e8860543c44fe717cec976d37952ee4 to your computer and use it in GitHub Desktop.
Save fedden/1e8860543c44fe717cec976d37952ee4 to your computer and use it in GitHub Desktop.
def mutate(dna, mutation_sigma, mutation_rate):
# If random dice roll (between zero and one) is less than mutation
# rate (between zero and one) then inject noise into the dna.
if np.random.random_sample() < mutation_rate:
# The noise is scaled by the mutation_sigma.
dna += np.random.standard_normal(size=dna.shape) * mutation_sigma
return dna
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment