Skip to content

Instantly share code, notes, and snippets.

@smspillaz
Created October 31, 2018 18:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save smspillaz/760fbbeece1e477202397cd2e1af52a8 to your computer and use it in GitHub Desktop.
def both_objectives(layout, columns, *args):
return (frequency_objective(layout,*args),
similarity_objective(layout,*args))
def random_evaluated_design(seed_design, objective_function, *args):
"""Return a new random design, evaluated by objective_function"""
candidate = random.sample(seed_design, len(seed_design))
return (candidate, *objective_function(candidate, *args))
def yield_pareto_optimal_designs_by_biobjectives(evaluated_designs,
x_objective_index,
y_objective_index):
"""Yield pareto optimal designs by biobjectives.
Walk through the evaluated designs in ascending order
of their x_objective and keep track of what minimizes
the y_objective."""
evaluated_designs_sorted_by_x_objective = sorted(
evaluated_designs,
key=lambda t: t[x_objective_index]
)
best_y_objective = 100000000
for t in evaluated_designs_sorted_by_x_objective:
y_objective = t[y_objective_index]
if y_objective < best_y_objective:
best_y_objective = y_objective
yield t
def biobjective_random_search(max_iters, objective_function, *args):
seed_design = args[0]
# Take designs and sort them by the first objective function
designs = [
random_evaluated_design(seed_design, objective_function, *o_inputs) for i in range(max_iters)
]
optimal_designs = [
d for d in yield_pareto_optimal_designs_by_biobjectives(designs,
1,
2)
]
return optimal_designs, designs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment