Skip to content

Commit

Permalink
Fix action name
Browse files Browse the repository at this point in the history
  • Loading branch information
YamLyubov committed Jun 5, 2024
1 parent f4b82cf commit 54e5cd1
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions golem/core/optimisers/adaptive/mab_agents/mab_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import _pickle as pickle
import random
import re
from typing import Union, Sequence, Optional
from functools import partial
from typing import Union, Sequence, Optional, Callable

from mabwiser.mab import MAB, LearningPolicy
from scipy.special import softmax
Expand All @@ -26,7 +27,7 @@ def __init__(self,
self.actions = list(actions)
self._indices = list(range(len(actions)))
# str because parent operator for mutation is stored as string for custom mutations serialisation
self._arm_by_action = dict(map(lambda x, y: (x.__name__, y), actions, self._indices))
self._arm_by_action = dict(map(lambda x, y: (self._get_callable_name(x), y), actions, self._indices))
self._agent = MAB(arms=self._indices,
learning_policy=LearningPolicy.EpsilonGreedy(epsilon=0.4),
n_jobs=n_jobs)
Expand All @@ -35,6 +36,16 @@ def __init__(self,
self._initial_fit()
self._path_to_save = path_to_save

@staticmethod
def _get_callable_name(action: Callable):
if isinstance(action, partial):
return action.func.__name__
else:
try:
return action.__name__
except AttributeError:
return str(action)

def _initial_fit(self):
n = len(self.actions)
uniform_rewards = [1. / n] * n
Expand Down

0 comments on commit 54e5cd1

Please sign in to comment.