class_docstr: A multi-layer perceptron module.
class_docstr_tok: ["A","multi-layer","perceptron","module","."]
docstr: Returns a new MLP which is the layer-wise reverse of this MLP.
  
  NOTE: Since computing the reverse of an MLP requires knowing the input size
  of each linear layer this method will fail if the module has not been called
  at least once.
  
  The contract of reverse is that the reversed module will accept the output
  of the parent module as input and produce an output which is the input size
  of the parent.
  
  >>> mlp = hk.nets.MLP([1, 2, 3])
  >>> mlp_in = jnp.ones([1, 2])
  >>> y = mlp(mlp_in)
  >>> rev = mlp.reverse()
  >>> rev_mlp_out = rev(y)
  >>> mlp_in.shape == rev_mlp_out.shape
  True
  
  Args:
    activate_final: Whether the final layer of the MLP should be activated.
    name: Optional name for the new module. The default name will be the name
      of the current module prefixed with ``"reversed_"``.
  
  Returns:
    An MLP instance which is the reverse of the current instance. Note these
    instances do not share weights and, apart from being symmetric to each
    other, are not coupled in any way.
docstr_tok: ["Returns","a","new","MLP","which","is","the","layer-wise","reverse","of","this","MLP",".","NOTE",":","Since","computing","the","reverse","of","an","MLP","requires","knowing","the","input","size","of","each","linear","layer","this","method","will","fail","if","the","module","has","not","been","called","at","least","once",".","The","contract","of","reverse","is","that","the","reversed","module","will","accept","the","output","of","the","parent","module","as","input","and","produce","an","output","which","is","the","input","size","of","the","parent",".",">",">",">","mlp","=","hk.nets.MLP","(","[","1",",","2",",","3","]",")",">",">",">","mlp_in","=","jnp.ones","(","[","1",",","2","]",")",">",">",">","y","=","mlp","(","mlp_in",")",">",">",">","rev","=","mlp.reverse","(",")",">",">",">","rev_mlp_out","=","rev","(","y",")",">",">",">","mlp_in.shape","==","rev_mlp_out.shape","True","Args",":","activate_final",":","Whether","the","final","layer","of","the","MLP","should","be","activated",".","name",":","Optional","name","for","the","new","module",".","The","default","name","will","be","the","name","of","the","current","module","prefixed","with","``","``","reversed_","''","``",".","Returns",":","An","MLP","instance","which","is","the","reverse","of","the","current","instance",".","Note","these","instances","do","not","share","weights","and",",","apart","from","being","symmetric","to","each","other",",","are","not","coupled","in","any","way","."]
code: def reverse(
      self,
      activate_final: Optional[bool] = None,
      name: Optional[str] = None,
  ) -> "MLP":
      """Returns a new MLP which is the layer-wise reverse of this MLP.
  
      NOTE: Since computing the reverse of an MLP requires knowing the input size
      of each linear layer this method will fail if the module has not been called
      at least once.
  
      The contract of reverse is that the reversed module will accept the output
      of the parent module as input and produce an output which is the input size
      of the parent.
  
      >>> mlp = hk.nets.MLP([1, 2, 3])
      >>> mlp_in = jnp.ones([1, 2])
      >>> y = mlp(mlp_in)
      >>> rev = mlp.reverse()
      >>> rev_mlp_out = rev(y)
      >>> mlp_in.shape == rev_mlp_out.shape
      True
  
      Args:
        activate_final: Whether the final layer of the MLP should be activated.
        name: Optional name for the new module. The default name will be the name
          of the current module prefixed with ``"reversed_"``.
  
      Returns:
        An MLP instance which is the reverse of the current instance. Note these
        instances do not share weights and, apart from being symmetric to each
        other, are not coupled in any way.
      """
  
      if activate_final is None:
          activate_final = self.activate_final
      if name is None:
          name = self.name + "_reversed"
  
      output_sizes = tuple(
          layer.input_size
          for layer in reversed(self.layers)
          if layer.input_size is not None
      )
      if len(output_sizes) != len(self.layers):
          raise ValueError(
              "You cannot reverse an MLP until it has been called."
          )
      return MLP(
          output_sizes=output_sizes,
          w_init=self.w_init,
          b_init=self.b_init,
          with_bias=self.with_bias,
          activation=self.activation,
          activate_final=activate_final,
          name=name,
      )
  
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 3 for calling the MLP obj's underlying member method code with example usage: obj.reverse(activate_final, name) and returns: MLP