Skip to content

Commit

Permalink
update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
foolnotion committed Feb 14, 2024
1 parent 34727e6 commit 75a148a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
10 changes: 7 additions & 3 deletions example/operon-bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pyoperon as Operon
from pmlb import fetch_data


# get some training data - see https://epistasislab.github.io/pmlb/
D = fetch_data('1027_ESL', return_X_y=False, local_cache_dir='./datasets').to_numpy()

Expand Down Expand Up @@ -82,7 +83,8 @@
evaluator = Operon.Evaluator(problem, dtable, error_metric, True) # initialize evaluator, use linear scaling = True
evaluator.Budget = 1000 * 1000 # computational budget

optimizer = Operon.LMOptimizer(dtable, problem, max_iter=10)
optimizer = Operon.LMOptimizer(dtable, problem, max_iter=3)
evaluator.Optimizer = optimizer

# define how new offspring are created
generator = Operon.BasicOffspringGenerator(evaluator, crossover, mutation, selector, selector)
Expand All @@ -102,11 +104,11 @@ def report():
best = gp.BestModel
bestfit = best.GetFitness(0)
sys.stdout.write('\r')
cursor = int(np.round(gen / config.Generations * max_ticks))
cursor = int(np.round(evaluator.TotalEvaluations/config.Evaluations * max_ticks))
for i in range(cursor):
sys.stdout.write('\u2588')
sys.stdout.write(' ' * (max_ticks-cursor))
sys.stdout.write(f'{100 * gen/config.Generations:.1f}%, generation {gen}/{config.Generations}, train quality: {-bestfit:.6f}, elapsed: {time.time()-t0:.2f}s')
sys.stdout.write(f'{100 * evaluator.TotalEvaluations/config.Evaluations:.1f}%, generation {gen}/{config.Generations}, train quality: {-bestfit:.6f}, elapsed: {time.time()-t0:.2f}s')
sys.stdout.flush()
gen += 1

Expand All @@ -116,4 +118,6 @@ def report():
# get the best solution and print it
best = gp.BestModel
model_string = Operon.InfixFormatter.Format(best.Genotype, ds, 6)
fit = evaluator(rng, gp.BestModel)
print('\nfit=', fit)
print(f'\n{model_string}')

0 comments on commit 75a148a

Please sign in to comment.