Skip to content

Commit

Permalink
Imp 2
Browse files Browse the repository at this point in the history
  • Loading branch information
nicl-nno committed Mar 28, 2024
1 parent 3799d8c commit 267f37c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
11 changes: 6 additions & 5 deletions golem/core/optimisers/adaptive/agent_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def fit(self, histories: Iterable[OptHistory], validate_each: int = -1) -> Opera
# Preliminary validity check
# This allows to filter out histories with different objectives automatically
if history.objective.metric_names != self.objective.metric_names:
self._log.warning(f'History #{i+1} has different objective! '
self._log.warning(f'History #{i + 1} has different objective! '
f'Expected {self.objective}, got {history.objective}.')
continue

Expand All @@ -67,13 +67,13 @@ def fit(self, histories: Iterable[OptHistory], validate_each: int = -1) -> Opera
experience, val_experience = experience.split(ratio=0.8, shuffle=True)

# Train
self._log.info(f'Training on history #{i+1} with {len(history.generations)} generations')
self._log.info(f'Training on history #{i + 1} with {len(history.generations)} generations')
self.agent.partial_fit(experience)

# Validate
if val_experience:
reward_loss, reward_target = self.validate_agent(experience=val_experience)
self._log.info(f'Agent validation for history #{i+1} & {experience}: '
self._log.info(f'Agent validation for history #{i + 1} & {experience}: '
f'Reward target={reward_target:.3f}, loss={reward_loss:.3f}')

# Reset mutation probabilities to default
Expand Down Expand Up @@ -163,9 +163,10 @@ def _apply_best_action(self, inds: Sequence[Individual]) -> TrajectoryStep:
return best_step

def _apply_action(self, action: Any, ind: Individual) -> TrajectoryStep:
new_graph, applied = self.mutation._adapt_and_apply_mutation(ind.graph, action)
new_graph = self.mutation._apply_mutations(ind.graph, action)
applied = new_graph is not None
fitness = self._eval_objective(new_graph) if applied else None
parent_op = ParentOperator(type_='mutation', operators=applied, parent_individuals=ind)
parent_op = ParentOperator(type_='mutation', operators=applied, parent_individuals=[ind])
new_ind = Individual(new_graph, fitness=fitness, parent_operator=parent_op)

prev_fitness = ind.fitness or self._eval_objective(ind.graph)
Expand Down
3 changes: 1 addition & 2 deletions golem/utilities/utilities.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import logging
import random
from typing import Optional

import numpy as np
from joblib import cpu_count

import random
from golem.utilities.random import RandomStateHandler


Expand Down

0 comments on commit 267f37c

Please sign in to comment.