:py:mod:`pycmtensor.models.layers`
==================================

.. py:module:: pycmtensor.models.layers

.. autoapi-nested-parse::

   Model layers



Module Contents
---------------

.. py:class:: Layer


   Default class type


.. py:class:: DenseLayer(w, bias, activation=None)


   Bases: :py:obj:`Layer`

   Default class type

   Class object for dense layer

   :param w: layer weights with ndim=2
   :type w: TensorSharedVariable
   :param bias: layer bias with ndim=1
   :type bias: TensorSharedVariable
   :param activation: the activation function, possible options are ``tanh``,
                      ``relu``, ``sigm``, ``None``

   .. note::

      Layer activation function is set based on the type of weight initialization.
      If weight init is "he", the activation is relu, if "glorot", the activation
      is tanh, otherwise the activation defaults to sigm.
      Setting activation to other than ``None`` overrides this.

   .. py:property:: updates

      Returns a list of update tuple pairs

   .. py:property:: output

      Returns the output of this layer

   .. py:method:: apply(input)

      Function to apply the input to the computational graph



.. py:class:: BatchNormLayer(gamma, beta, batch_size, factor=0.05, epsilon=1e-06)


   Bases: :py:obj:`Layer`

   Default class type

   Class object for Batch Normalization layer

   :param gamma: gamma variable for variance
   :type gamma: TensorSharedVariable
   :param beta: beta variable for mean
   :type beta: TensorSharedVariable
   :param batch_size: batch size indicator
   :type batch_size: int
   :param factor: exponential moving average factor
   :type factor: float, optional
   :param epsilon: small value to prevent floating point error
   :type epsilon: float, optional

   .. rubric:: Notes

   The ema factor controls how fast/slow the running average is changed.
   Higher ``factor`` value discounts older values faster.

   .. py:property:: mv_mean

      Returns the stored running mean

   .. py:property:: mv_var

      Return the stored running variance

   .. py:property:: updates

      Returns a list of update tuple pairs

   .. py:property:: output

      Returns the output of this layer

      .. note::

         Returns the full normalized layer using the running mean if the input
         length is not equivalent to the batch size

   .. py:method:: apply(input)

      Function to apply the input to the computational graph



.. py:class:: ResidualLayer(layers: list)


   
   Definition of the Residual layer block

   :param layers: a list of layers that defines the residual block
   :type layers: list

   .. rubric:: Example

   .. code-block:: python

       res_layer = ResidualLayer(layers=[
           DenseLayer(w_1, b_1, activation=relu),
           DenseLayer(w_2, b_2, activation=relu)
       ])

   .. py:property:: updates

      Returns a list of update tuple pairs

   .. py:method:: apply(input)

      Function to apply the input to the computational graph


   .. py:method:: output()

      Returns the output of this layer



