Source code for pynol.learner.specification.optimism_base

from abc import ABC, abstractmethod


[docs]class OptimismBase(ABC): """The abstract class defines the optimism for base-learners. Attributes: is_external (bool): Indicates the optimism is given by the environment or computed by the algorithm itself. The default is True. """ def __init__(self, is_external: bool = True): self.is_external = is_external
[docs] @abstractmethod def compute_optimism_base(self): """Compute the optimism for base-learners.""" raise NotImplementedError()
[docs]class EnvironmentalOptimismBase(OptimismBase): """The class indicates the base-learner will use the environmental optimism. """ def __init__(self): super().__init__()
[docs] def compute_optimism_base(self, variables): return variables['optimism_env']
[docs]class LastGradOptimismBase(OptimismBase): """The class will set the optimism :math:`m_{t+1}` of the base-learners as :math:`m_t = \\nabla f_{t-1}(x_{t-1})`, where :math:`x_{t-1}` is the submitted decision at round :math:`t-1`.""" def __init__(self): super().__init__(is_external=False)
[docs] def compute_optimism_base(self, variables): return variables['grad']