Source code for tianshou.highlevel.params.env_param

"""Factories for the generation of environment-dependent parameters."""
from abc import ABC, abstractmethod
from typing import Generic, TypeVar

from tianshou.highlevel.env import ContinuousEnvironments, Environments
from tianshou.utils.string import ToStringMixin

TValue = TypeVar("TValue")
TEnvs = TypeVar("TEnvs", bound=Environments)


[docs] class EnvValueFactory(Generic[TValue, TEnvs], ToStringMixin, ABC):
[docs] @abstractmethod def create_value(self, envs: TEnvs) -> TValue: pass
[docs] class FloatEnvValueFactory(EnvValueFactory[float, TEnvs], Generic[TEnvs], ABC): """Serves as a type bound for float value factories."""
[docs] class FloatEnvValueFactoryMaxActionScaled(FloatEnvValueFactory[ContinuousEnvironments]): def __init__(self, value: float): """:param value: value with which to scale the max action value""" self.value = value
[docs] def create_value(self, envs: ContinuousEnvironments) -> float: envs.get_type().assert_continuous(self) return envs.max_action * self.value
[docs] class MaxActionScaled(FloatEnvValueFactoryMaxActionScaled): pass