mirror of
https://github.com/saymrwulf/stable-baselines3.git
synced 2026-11-18 09:54:10 +00:00
Add with_bias parameter to create_mlp (#1188)
* Add with_bias arg * Update changelog * move torch_layers to the last position * Update version Co-authored-by: Antonin Raffin <antonin.raffin@ensta.org>
This commit is contained in:
parent
6902fac5e7
commit
5cd891317e
3 changed files with 8 additions and 5 deletions
|
|
@ -4,7 +4,7 @@ Changelog
|
||||||
==========
|
==========
|
||||||
|
|
||||||
|
|
||||||
Release 1.7.0a3 (WIP)
|
Release 1.7.0a4 (WIP)
|
||||||
--------------------------
|
--------------------------
|
||||||
|
|
||||||
Breaking Changes:
|
Breaking Changes:
|
||||||
|
|
@ -17,6 +17,7 @@ Breaking Changes:
|
||||||
New Features:
|
New Features:
|
||||||
^^^^^^^^^^^^^
|
^^^^^^^^^^^^^
|
||||||
- Introduced mypy type checking
|
- Introduced mypy type checking
|
||||||
|
- Added ``with_bias`` argument to ``create_mlp``
|
||||||
|
|
||||||
SB3-Contrib
|
SB3-Contrib
|
||||||
^^^^^^^^^^^
|
^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
|
@ -99,6 +99,7 @@ def create_mlp(
|
||||||
net_arch: List[int],
|
net_arch: List[int],
|
||||||
activation_fn: Type[nn.Module] = nn.ReLU,
|
activation_fn: Type[nn.Module] = nn.ReLU,
|
||||||
squash_output: bool = False,
|
squash_output: bool = False,
|
||||||
|
with_bias: bool = True,
|
||||||
) -> List[nn.Module]:
|
) -> List[nn.Module]:
|
||||||
"""
|
"""
|
||||||
Create a multi layer perceptron (MLP), which is
|
Create a multi layer perceptron (MLP), which is
|
||||||
|
|
@ -113,21 +114,22 @@ def create_mlp(
|
||||||
to use after each layer.
|
to use after each layer.
|
||||||
:param squash_output: Whether to squash the output using a Tanh
|
:param squash_output: Whether to squash the output using a Tanh
|
||||||
activation function
|
activation function
|
||||||
|
:param with_bias: If set to False, the layers will not learn an additive bias
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if len(net_arch) > 0:
|
if len(net_arch) > 0:
|
||||||
modules = [nn.Linear(input_dim, net_arch[0]), activation_fn()]
|
modules = [nn.Linear(input_dim, net_arch[0], bias=with_bias), activation_fn()]
|
||||||
else:
|
else:
|
||||||
modules = []
|
modules = []
|
||||||
|
|
||||||
for idx in range(len(net_arch) - 1):
|
for idx in range(len(net_arch) - 1):
|
||||||
modules.append(nn.Linear(net_arch[idx], net_arch[idx + 1]))
|
modules.append(nn.Linear(net_arch[idx], net_arch[idx + 1], bias=with_bias))
|
||||||
modules.append(activation_fn())
|
modules.append(activation_fn())
|
||||||
|
|
||||||
if output_dim > 0:
|
if output_dim > 0:
|
||||||
last_layer_dim = net_arch[-1] if len(net_arch) > 0 else input_dim
|
last_layer_dim = net_arch[-1] if len(net_arch) > 0 else input_dim
|
||||||
modules.append(nn.Linear(last_layer_dim, output_dim))
|
modules.append(nn.Linear(last_layer_dim, output_dim, bias=with_bias))
|
||||||
if squash_output:
|
if squash_output:
|
||||||
modules.append(nn.Tanh())
|
modules.append(nn.Tanh())
|
||||||
return modules
|
return modules
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
1.7.0a3
|
1.7.0a4
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue