Created
October 31, 2018 17:42
-
-
Save smspillaz/ca9abed4bcf0d4f0dd4eb39c0d610c2d to your computer and use it in GitHub Desktop.
Random Search in Pyton
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def random_search(array, iterations, objective, *args): | |
"""Do a random search over the array for :iterations:.""" | |
best = array[0] | |
best_value = objective(best, *args) | |
for i in range(iterations): | |
candidate = random.sample(best, len(best)) | |
value = objective(candidate, *args) | |
if value < best_value: | |
best = candidate | |
best_value = value | |
return best, best_value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment