Skip to content

Commit

Permalink
extract loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi-Gau committed Feb 19, 2024
1 parent ae24d9d commit 664b2d7
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions neurodesign/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,17 @@ def clear(self):

return self

def _run_optimisation_loop(self, weights):
with progress_bar(text="Optimizing") as progress:
task = progress.add_task(
description="optimize", total=len(range(self.preruncycles))
)
for _ in range(self.preruncycles):
self.to_next_generation(seed=self.seed, weights=weights)
progress.update(task, advance=1)
if self.finished:
continue

def optimise(self):
"""Run design optimization."""
if self.exp.FcMax == 1 and self.exp.FfMax == 1:
Expand All @@ -1005,35 +1016,13 @@ def optimise(self):
# add new designs
self.clear()
self.add_new_designs(weights=[1, 0, 0, 0])

# loop
with progress_bar(text="Optimizing") as progress:
task = progress.add_task(
description="optimize", total=len(range(self.preruncycles))
)
for _ in range(self.preruncycles):
self.to_next_generation(seed=self.seed, weights=[1, 0, 0, 0])
progress.update(task, advance=1)
if self.finished:
continue

self._run_optimisation_loop(self, weights=[1, 0, 0, 0])
self.exp.FeMax = np.max(self.bestdesign.F)

if self.exp.FdMax == 1 and self.weights[1] > 0:
self.clear()
self.add_new_designs(weights=[0, 1, 0, 0])

# loop
with progress_bar(text="Optimizing") as progress:
task = progress.add_task(
description="optimize", total=len(range(self.preruncycles))
)
for _ in range(self.preruncycles):
self.to_next_generation(seed=self.seed, weights=[0, 1, 0, 0])
progress.update(task, advance=1)
if self.finished:
continue

self._run_optimisation_loop(self, weights=[0, 1, 0, 0])
self.exp.FdMax = np.max(self.bestdesign.F)

# clear all attributes
Expand Down

0 comments on commit 664b2d7

Please sign in to comment.