Skip to content

lit_sb3.algorithms.tqc.policies

source module lit_sb3.algorithms.tqc.policies

Classes

  • Actor — Actor network (policy) for TQC.

  • Critic — Critic network (q-value function) for TQC.

  • TQCPolicy — Policy class (with both actor and critic) for TQC.

  • CnnPolicy — Policy class (with both actor and critic) for TQC.

  • MultiInputPolicy — Policy class (with both actor and critic) for TQC.

source class Actor(observation_space: spaces.Space, action_space: spaces.Box, net_arch: list[int], features_extractor: nn.Module, features_dim: int, activation_fn: type[nn.Module] = nn.ReLU, use_sde: bool = False, log_std_init: float = -3, full_std: bool = True, use_expln: bool = False, clip_mean: float = 2.0, normalize_images: bool = True)

Bases : BasePolicy

Actor network (policy) for TQC.

Parameters

  • observation_space : spaces.Space — Obervation space

  • action_space : spaces.Box — Action space

  • net_arch : list[int] — Network architecture

  • features_extractor : nn.Module — Network to extract features (a CNN when using images, a nn.Flatten() layer otherwise)

  • features_dim : int — Number of features

  • activation_fn : type[nn.Module] — Activation function

  • use_sde : bool — Whether to use State Dependent Exploration or not

  • log_std_init : float — Initial value for the log standard deviation

  • full_std : bool — Whether to use (n_features x n_actions) parameters for the std instead of only (n_features,) when using gSDE.

  • use_expln : bool — Use expln() function instead of exp() when using gSDE to ensure a positive standard deviation (cf paper). It allows to keep variance above zero and prevent it from growing too fast. In practice, exp() is usually enough.

  • clip_mean : float — Clip the mean output when using gSDE to avoid numerical instability.

  • normalize_images : bool — Whether to normalize images or not, dividing by 255.0 (True by default)

Attributes

  • device : torch.device — Infer which device this policy lives on by inspecting its parameters.

  • squash_output : bool — (bool) Getter for squash_output.

Methods

source method Actor.get_std() → torch.Tensor

Retrieve the standard deviation of the action distribution.

Only useful when using gSDE. It corresponds to torch.exp(log_std) in the normal case, but is slightly different when using expln function (cf StateDependentNoiseDistribution doc).

source method Actor.reset_noise(batch_size: int = 1) → None

Sample new weights for the exploration matrix, when using gSDE.

Parameters

  • batch_size : int

  • batch_size : int — The number of samples in the batch.

source method Actor.get_action_dist_params(obs: PyTorchObs) → tuple[torch.Tensor, torch.Tensor, dict[str, torch.Tensor]]

Get the parameters for the action distribution.

Parameters

  • obs : PyTorchObs

  • obs : PyTorchObs — The current observation.

Returns

  • tuple[torch.Tensor, torch.Tensor, dict[str, torch.Tensor]] — Mean, standard deviation and optional keyword arguments.

source method Actor.forward(obs: PyTorchObs, deterministic: bool = False) → torch.Tensor

source method Actor.action_log_prob(obs: PyTorchObs) → tuple[torch.Tensor, torch.Tensor]

source class Critic(observation_space: spaces.Space, action_space: spaces.Box, net_arch: list[int], features_extractor: BaseFeaturesExtractor, features_dim: int, activation_fn: type[nn.Module] = nn.ReLU, normalize_images: bool = True, n_quantiles: int = 25, n_critics: int = 2, share_features_extractor: bool = False)

Bases : BaseModel

Critic network (q-value function) for TQC.

Parameters

  • observation_space : spaces.Space — Obervation space

  • action_space : spaces.Box — Action space

  • net_arch : list[int] — Network architecture

  • features_extractor : BaseFeaturesExtractor — Network to extract features (a CNN when using images, a nn.Flatten() layer otherwise)

  • features_dim : int — Number of features

  • activation_fn : type[nn.Module] — Activation function

  • normalize_images : bool — Whether to normalize images or not, dividing by 255.0 (True by default)

  • share_features_extractor : bool — Whether the features extractor is shared or not between the actor and the critic (this saves computation time)

Attributes

  • device : torch.device — Infer which device this policy lives on by inspecting its parameters.

Methods

source method Critic.forward(obs: PyTorchObs, action: torch.Tensor) → torch.Tensor

source class TQCPolicy(observation_space: spaces.Space, action_space: spaces.Box, lr_schedule: Schedule, net_arch: list[int] | dict[str, list[int]] | None = None, activation_fn: type[nn.Module] = nn.ReLU, use_sde: bool = False, log_std_init: float = -3, use_expln: bool = False, clip_mean: float = 2.0, features_extractor_class: type[BaseFeaturesExtractor] = FlattenExtractor, features_extractor_kwargs: dict[str, Any] | None = None, normalize_images: bool = True, optimizer_class: type[torch.optim.Optimizer] = torch.optim.Adam, optimizer_kwargs: dict[str, Any] | None = None, n_quantiles: int = 25, n_critics: int = 2, share_features_extractor: bool = False)

Bases : BasePolicy

Policy class (with both actor and critic) for TQC.

Parameters

  • observation_space : spaces.Space — Observation space

  • action_space : spaces.Box — Action space

  • lr_schedule : Schedule — Learning rate schedule (could be constant)

  • net_arch : list[int] | dict[str, list[int]] | None — The specification of the policy and value networks.

  • activation_fn : type[nn.Module] — Activation function

  • use_sde : bool — Whether to use State Dependent Exploration or not

  • log_std_init : float — Initial value for the log standard deviation

  • use_expln : bool — Use expln() function instead of exp() when using gSDE to ensure a positive standard deviation (cf paper). It allows to keep variance above zero and prevent it from growing too fast. In practice, exp() is usually enough.

  • clip_mean : float — Clip the mean output when using gSDE to avoid numerical instability.

  • features_extractor_class : type[BaseFeaturesExtractor] — Features extractor to use.

  • features_extractor_kwargs : dict[str, Any] | None — Keyword arguments to pass to the feature extractor.

  • normalize_images : bool — Whether to normalize images or not, dividing by 255.0 (True by default)

  • optimizer_class : type[torch.optim.Optimizer] — The optimizer to use, torch.optim.Adam by default

  • optimizer_kwargs : dict[str, Any] | None — Additional keyword arguments, excluding the learning rate, to pass to the optimizer

  • n_quantiles : int — Number of quantiles for the critic.

  • n_critics : int — Number of critic networks to create.

  • share_features_extractor : bool — Whether to share or not the features extractor between the actor and the critic (this saves computation time)

Attributes

  • device : torch.device — Infer which device this policy lives on by inspecting its parameters.

  • squash_output : bool — (bool) Getter for squash_output.

Methods

source method TQCPolicy.reset_noise(batch_size: int = 1) → None

Sample new weights for the exploration matrix, when using gSDE.

Parameters

  • batch_size : int

  • batch_size : int — The number of samples in the batch.

source method TQCPolicy.make_actor(features_extractor: BaseFeaturesExtractor | None = None) → Actor

source method TQCPolicy.make_critic(features_extractor: BaseFeaturesExtractor | None = None) → Critic

source method TQCPolicy.forward(obs: PyTorchObs, deterministic: bool = False) → torch.Tensor

source method TQCPolicy.set_training_mode(mode: bool) → None

Put the policy in either training or evaluation mode.

This affects certain modules, such as batch normalisation and dropout.

Parameters

  • mode : bool — if true, set to training mode, else set to evaluation mode

source class CnnPolicy(observation_space: spaces.Space, action_space: spaces.Box, lr_schedule: Schedule, net_arch: list[int] | dict[str, list[int]] | None = None, activation_fn: type[nn.Module] = nn.ReLU, use_sde: bool = False, log_std_init: float = -3, use_expln: bool = False, clip_mean: float = 2.0, features_extractor_class: type[BaseFeaturesExtractor] = NatureCNN, features_extractor_kwargs: dict[str, Any] | None = None, normalize_images: bool = True, optimizer_class: type[torch.optim.Optimizer] = torch.optim.Adam, optimizer_kwargs: dict[str, Any] | None = None, n_quantiles: int = 25, n_critics: int = 2, share_features_extractor: bool = False)

Bases : TQCPolicy

Policy class (with both actor and critic) for TQC.

Parameters

  • observation_space : spaces.Space — Observation space

  • action_space : spaces.Box — Action space

  • lr_schedule : Schedule — Learning rate schedule (could be constant)

  • net_arch : list[int] | dict[str, list[int]] | None — The specification of the policy and value networks.

  • activation_fn : type[nn.Module] — Activation function

  • use_sde : bool — Whether to use State Dependent Exploration or not

  • log_std_init : float — Initial value for the log standard deviation

  • use_expln : bool — Use expln() function instead of exp() when using gSDE to ensure a positive standard deviation (cf paper). It allows to keep variance above zero and prevent it from growing too fast. In practice, exp() is usually enough.

  • clip_mean : float — Clip the mean output when using gSDE to avoid numerical instability.

  • features_extractor_class : type[BaseFeaturesExtractor] — Features extractor to use.

  • normalize_images : bool — Whether to normalize images or not, dividing by 255.0 (True by default)

  • optimizer_class : type[torch.optim.Optimizer] — The optimizer to use, torch.optim.Adam by default

  • optimizer_kwargs : dict[str, Any] | None — Additional keyword arguments, excluding the learning rate, to pass to the optimizer

  • n_quantiles : int — Number of quantiles for the critic.

  • n_critics : int — Number of critic networks to create.

  • share_features_extractor : bool — Whether to share or not the features extractor between the actor and the critic (this saves computation time)

Attributes

  • device : torch.device — Infer which device this policy lives on by inspecting its parameters.

  • squash_output : bool — (bool) Getter for squash_output.

source class MultiInputPolicy(observation_space: spaces.Space, action_space: spaces.Box, lr_schedule: Schedule, net_arch: list[int] | dict[str, list[int]] | None = None, activation_fn: type[nn.Module] = nn.ReLU, use_sde: bool = False, log_std_init: float = -3, use_expln: bool = False, clip_mean: float = 2.0, features_extractor_class: type[BaseFeaturesExtractor] = CombinedExtractor, features_extractor_kwargs: dict[str, Any] | None = None, normalize_images: bool = True, optimizer_class: type[torch.optim.Optimizer] = torch.optim.Adam, optimizer_kwargs: dict[str, Any] | None = None, n_quantiles: int = 25, n_critics: int = 2, share_features_extractor: bool = False)

Bases : TQCPolicy

Policy class (with both actor and critic) for TQC.

Parameters

  • observation_space : spaces.Space — Observation space

  • action_space : spaces.Box — Action space

  • lr_schedule : Schedule — Learning rate schedule (could be constant)

  • net_arch : list[int] | dict[str, list[int]] | None — The specification of the policy and value networks.

  • activation_fn : type[nn.Module] — Activation function

  • use_sde : bool — Whether to use State Dependent Exploration or not

  • log_std_init : float — Initial value for the log standard deviation

  • use_expln : bool — Use expln() function instead of exp() when using gSDE to ensure a positive standard deviation (cf paper). It allows to keep variance above zero and prevent it from growing too fast. In practice, exp() is usually enough.

  • clip_mean : float — Clip the mean output when using gSDE to avoid numerical instability.

  • features_extractor_class : type[BaseFeaturesExtractor] — Features extractor to use.

  • normalize_images : bool — Whether to normalize images or not, dividing by 255.0 (True by default)

  • optimizer_class : type[torch.optim.Optimizer] — The optimizer to use, torch.optim.Adam by default

  • optimizer_kwargs : dict[str, Any] | None — Additional keyword arguments, excluding the learning rate, to pass to the optimizer

  • n_quantiles : int — Number of quantiles for the critic.

  • n_critics : int — Number of critic networks to create.

  • share_features_extractor : bool — Whether to share or not the features extractor between the actor and the critic (this saves computation time)

Attributes

  • device : torch.device — Infer which device this policy lives on by inspecting its parameters.

  • squash_output : bool — (bool) Getter for squash_output.