Utilities — rl_mind.nn, rl_mind.notebook¶
Neural-network helpers — rl_mind.nn¶
Neural network helpers.
build_mlpbuilds a multi-layer perceptron from a list of layer sizes.soft_updateperforms the Polyak averaging update of a target network, \(\theta' \leftarrow \tau \theta + (1 - \tau) \theta'\).
- rl_mind.nn.build_mlp(sizes: list[int], activation: Module = nn.ReLU(), output_activation: Module | None = None) Sequential[source]¶
Build a multi-layer perceptron
- Parameters:
sizes – The sizes of the layers, e.g.
[obs_dim, 64, 64, action_dim]activation – The activation module between hidden layers
output_activation – An optional activation after the last layer (e.g.
nn.Tanh()for actions in \([-1, 1]\))
- Returns:
A
torch.nn.Sequentialoflen(sizes) - 1linear layers, separated byactivation
- rl_mind.nn.soft_update(source: Module, target: Module, tau: float) None[source]¶
Update the target network parameters towards the source network
Performs \(\theta' \leftarrow \tau \theta + (1-\tau) \theta'\) for each parameter \(\theta'\) of
target, in place and without tracking gradients. A smalltaumakes the target network lag behind, which is what stabilizes the bootstrapped targets of DDPG/TD3/SAC.- Parameters:
source – The network being trained
target – The target network, updated in place
tau – The interpolation factor, in \([0, 1]\) (\(\tau = 1\) copies the source network)
Notebook helpers — rl_mind.notebook¶
Notebook utilities.
Small helpers that adapt to the execution context (Jupyter notebook, Colab or plain Python script): displaying videos, launching tensorboard, and creating per-run output directories.
- rl_mind.notebook.is_notebook() bool[source]¶
True when running inside a Jupyter notebook or Google Colab
Used by the helpers that must degrade gracefully when a source is run as a plain script (as
make checkdoes).
- rl_mind.notebook.outputs_directory() Path[source]¶
The base directory for all outputs (tensorboard logs, videos, …)
Reads
NOTEBOOK_PROFILEdirectly (rather than importingrl_mind.profiles, which needscs-lab) so this stays available with a barepip install rl-mind;make checksets it tofast-test(see jupytext-notebook-helper’sCHECK_PROFILE).- Returns:
outputs-testingwhenNOTEBOOK_PROFILEisfast-test,outputsotherwise (both relative to the working directory)
- rl_mind.notebook.run_directory(name: str) Path[source]¶
Create (and return) a fresh output directory for a training run
- Parameters:
name – A name for the run, e.g.
"ddpg-CartPoleContinuous-v1-S1"- Returns:
The created directory,
<outputs>/— suitable as a tensorboard log directory and as therun_dirof anEvaluator
- rl_mind.notebook.setup_tensorboard()[source]¶
Show tensorboard in the notebook, or print the command to launch it
In Jupyter, a chooser lets the student pick where the dashboard lives: external (the default: the command to run from a shell is shown) or in the notebook (the dashboard is displayed inline). Colab has no shell to run it from, so the dashboard is always shown inline there; from a plain script (as
make checkruns the sources), the command is printed.The logs of every run are written under
outputs/relative to the working directory of the kernel — the absolute path is printed so that a tensorboard started from a shell watches the right directory.