class_docstr: A multi-layer perceptron module.
class_docstr_tok: ["A","multi-layer","perceptron","module","."]
docstr: Constructs an MLP.
  
  Args:
    output_sizes: Sequence of layer sizes.
    w_init: Initializer for :class:`~haiku.Linear` weights.
    b_init: Initializer for :class:`~haiku.Linear` bias. Must be ``None`` if
      ``with_bias=False``.
    with_bias: Whether or not to apply a bias in each layer.
    activation: Activation function to apply between :class:`~haiku.Linear`
      layers. Defaults to ReLU.
    activate_final: Whether or not to activate the final layer of the MLP.
    name: Optional name for this module.
  
  Raises:
    ValueError: If ``with_bias`` is ``False`` and ``b_init`` is not ``None``.
docstr_tok: ["Constructs","an","MLP",".","Args",":","output_sizes",":","Sequence","of","layer","sizes",".","w_init",":","Initializer","for",":","class",":","`","~haiku.Linear","`","weights",".","b_init",":","Initializer","for",":","class",":","`","~haiku.Linear","`","bias",".","Must","be","``","None","``","if","``","with_bias=False","``",".","with_bias",":","Whether","or","not","to","apply","a","bias","in","each","layer",".","activation",":","Activation","function","to","apply","between",":","class",":","`","~haiku.Linear","`","layers",".","Defaults","to","ReLU",".","activate_final",":","Whether","or","not","to","activate","the","final","layer","of","the","MLP",".","name",":","Optional","name","for","this","module",".","Raises",":","ValueError",":","If","``","with_bias","``","is","``","False","``","and","``","b_init","``","is","not","``","None","``","."]
code: def __init__(
      self,
      output_sizes: Iterable[int],
      w_init: Optional[hk.initializers.Initializer] = None,
      b_init: Optional[hk.initializers.Initializer] = None,
      with_bias: bool = True,
      activation: Callable[[jax.Array], jax.Array] = jax.nn.relu,
      activate_final: bool = False,
      name: Optional[str] = None,
  ):
      """Constructs an MLP.
  
      Args:
        output_sizes: Sequence of layer sizes.
        w_init: Initializer for :class:`~haiku.Linear` weights.
        b_init: Initializer for :class:`~haiku.Linear` bias. Must be ``None`` if
          ``with_bias=False``.
        with_bias: Whether or not to apply a bias in each layer.
        activation: Activation function to apply between :class:`~haiku.Linear`
          layers. Defaults to ReLU.
        activate_final: Whether or not to activate the final layer of the MLP.
        name: Optional name for this module.
  
      Raises:
        ValueError: If ``with_bias`` is ``False`` and ``b_init`` is not ``None``.
      """
      if not with_bias and b_init is not None:
          raise ValueError(
              "When with_bias=False b_init must not be set."
          )
  
      super().__init__(name=name)
      self.with_bias = with_bias
      self.w_init = w_init
      self.b_init = b_init
      self.activation = activation
      self.activate_final = activate_final
      layers = []
      output_sizes = tuple(output_sizes)
      for index, output_size in enumerate(output_sizes):
          layers.append(
              hk.Linear(
                  output_size=output_size,
                  w_init=w_init,
                  b_init=b_init,
                  with_bias=with_bias,
                  name="linear_%d" % index,
              )
          )
      self.layers = tuple(layers)
      self.output_size = output_sizes[-1] if output_sizes else None
  
file_path: dm-haiku/haiku/_src/nets/mlp.py
imports: from collections.abc import Iterable
  from typing import Callable, Optional
  from haiku._src import base
  from haiku._src import basic
  from haiku._src import initializers
  from haiku._src import module
  import jax
label_desc: Use image node_id 1 to create a new MLP object from inherited base classes: hk with example: obj = MLP(output_sizes, w_init, b_init, with_bias, activation, activate_final, name)