move fib and prune_results
into utilities
This commit is contained in:
parent
665910b70c
commit
03a25e010a
3 changed files with 38 additions and 35 deletions
|
@ -2,7 +2,6 @@ from .go_benchmark_lists import *
|
|||
from .go_benchmarks import problems_2d, problems_3d, problems_4d
|
||||
from .parties import parties
|
||||
from .utilities import OWrap, COWrap, m1, m33, m36, prog
|
||||
from .utilities import perform_another_experimental_scoring_method
|
||||
import numpy as np
|
||||
|
||||
all_problems = {
|
||||
|
@ -155,12 +154,11 @@ for problem_list in GO_BENCHMARKS.values():
|
|||
|
||||
|
||||
def main(argv, display=True):
|
||||
from .utilities import fib
|
||||
from .utilities import prune_results, perform_another_experimental_scoring_method
|
||||
from tqdm import tqdm
|
||||
import sys
|
||||
|
||||
def fib(n):
|
||||
return pow(2 << n, n + 1, (4 << 2 * n) - (2 << n) - 1) % (2 << n)
|
||||
|
||||
def optimizer_filter(name):
|
||||
# worst scoring optimizers: (awards=(5, 3, 2, 1)) (obj=146, opt=389) (dims=2, evals=80)
|
||||
# evosax_pbt with (score: 0, price: 593) -593
|
||||
|
@ -262,36 +260,6 @@ def main(argv, display=True):
|
|||
|
||||
return s
|
||||
|
||||
def prune_results(results, multiple):
|
||||
# if there are more than `multiple` results for one optimizer+objective pair,
|
||||
# then trim the bottom and top until there are only `multiple` left.
|
||||
new_results = {}
|
||||
for obj_name, obj_res in results.items():
|
||||
new_res = {}
|
||||
for fopt, opt_name, extra in sorted(obj_res):
|
||||
l = new_res.setdefault(opt_name, [[], []])
|
||||
l[0].append(fopt)
|
||||
l[1].append(extra)
|
||||
slices = {}
|
||||
for opt_name, res in new_res.items():
|
||||
# in the event that an odd number of results needs to be trimmed,
|
||||
# prefer trimming from the bottom (i.e. worse solutions get removed first).
|
||||
fopts, extras = res
|
||||
down = (len(fopts) - multiple) // 2
|
||||
up = len(fopts) - (len(fopts) - multiple + 1) // 2
|
||||
slices[opt_name] = slice(down, up)
|
||||
for opt_name, res in new_res.items():
|
||||
fopts, extras = res
|
||||
s = slices[opt_name]
|
||||
fopts, extras = fopts[s], extras[s]
|
||||
if not no_summary:
|
||||
assert len(fopts) == multiple, (len(fopts), multiple)
|
||||
if len(fopts) == multiple:
|
||||
for fopt, extra in zip(fopts, extras):
|
||||
result = (fopt, opt_name, extra)
|
||||
new_results.setdefault(obj_name, []).append(result)
|
||||
return results
|
||||
|
||||
reset = "\033[m"
|
||||
|
||||
quieter = True
|
||||
|
@ -388,7 +356,7 @@ def main(argv, display=True):
|
|||
run += 1
|
||||
|
||||
all_results = results
|
||||
results = prune_results(results, multiple)
|
||||
results = prune_results(results, multiple, _check=not no_summary)
|
||||
|
||||
scores, prices = {}, {}
|
||||
all_opt_names = set()
|
||||
|
|
|
@ -21,3 +21,7 @@ def phi(d):
|
|||
for i in range(30 if d == 1 else max(10, 28 - d)):
|
||||
x = pow(1 + x, 1 / (d + 1))
|
||||
return x
|
||||
|
||||
|
||||
def fib(n):
|
||||
return pow(2 << n, n + 1, (4 << 2 * n) - (2 << n) - 1) % (2 << n)
|
||||
|
|
|
@ -1,3 +1,34 @@
|
|||
def prune_results(results, multiple, _check=False):
|
||||
# if there are more than `multiple` results for one optimizer+objective pair,
|
||||
# then trim the bottom and top until there are only `multiple` left.
|
||||
new_results = {}
|
||||
for obj_name, obj_res in results.items():
|
||||
new_res = {}
|
||||
for fopt, opt_name, extra in sorted(obj_res):
|
||||
l = new_res.setdefault(opt_name, [[], []])
|
||||
l[0].append(fopt)
|
||||
l[1].append(extra)
|
||||
slices = {}
|
||||
for opt_name, res in new_res.items():
|
||||
# in the event that an odd number of results needs to be trimmed,
|
||||
# prefer trimming from the bottom (i.e. worse solutions get removed first).
|
||||
fopts, extras = res
|
||||
down = (len(fopts) - multiple) // 2
|
||||
up = len(fopts) - (len(fopts) - multiple + 1) // 2
|
||||
slices[opt_name] = slice(down, up)
|
||||
for opt_name, res in new_res.items():
|
||||
fopts, extras = res
|
||||
s = slices[opt_name]
|
||||
fopts, extras = fopts[s], extras[s]
|
||||
if _check:
|
||||
assert len(fopts) == multiple, (len(fopts), multiple)
|
||||
if len(fopts) == multiple:
|
||||
for fopt, extra in zip(fopts, extras):
|
||||
result = (fopt, opt_name, extra)
|
||||
new_results.setdefault(obj_name, []).append(result)
|
||||
return results
|
||||
|
||||
|
||||
def perform_another_experimental_scoring_method(results):
|
||||
if len(results) and len(something := next(iter(results.values()))[0]) == 3:
|
||||
history_length = len(something[2])
|
||||
|
|
Loading…
Reference in a new issue