ó
¾÷Xc           @`  s.  d  d l  m Z d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l	 Z	 d d l
 m Z d d l
 m Z d d l
 m Z d d l
 m Z d d	 l
 m Z d d
 l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ  d e f d „  ƒ  YZ! d  e f d! „  ƒ  YZ" d" e f d# „  ƒ  YZ# d$ e f d% „  ƒ  YZ$ d& e f d' „  ƒ  YZ% d( e f d) „  ƒ  YZ& d S(*   i    (   t   absolute_import(   t   divisionNi   (   t   backend(   t   activations(   t   initializers(   t   regularizers(   t   constraints(   t	   InputSpec(   t   Layer(   t	   func_dump(   t	   func_load(   t   deserialize_keras_object(   t
   interfacest   Maskingc           B`  s8   e  Z d  Z d d „ Z d d „ Z d „  Z d „  Z RS(   sÁ  Masks a sequence by using a mask value to skip timesteps.

    For each timestep in the input tensor (dimension #1 in the tensor),
    if all values in the input tensor at that timestep
    are equal to `mask_value`, then the timestep will be masked (skipped)
    in all downstream layers (as long as they support masking).

    If any downstream layer does not support masking yet receives such
    an input mask, an exception will be raised.

    # Example

    Consider a Numpy data array `x` of shape `(samples, timesteps, features)`,
    to be fed to a LSTM layer.
    You want to mask timestep #3 and #5 because you lack data for
    these timesteps. You can:

        - set `x[:, 3, :] = 0.` and `x[:, 5, :] = 0.`
        - insert a `Masking` layer with `mask_value=0.` before the LSTM layer:

    ```python
        model = Sequential()
        model.add(Masking(mask_value=0., input_shape=(timesteps, features)))
        model.add(LSTM(32))
    ```
    g        c         K`  s,   t  t |  ƒ j |   t |  _ | |  _ d  S(   N(   t   superR   t   __init__t   Truet   supports_maskingt
   mask_value(   t   selfR   t   kwargs(    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR   5   s    	c         C`  s"   t  j t  j | |  j ƒ d d ƒS(   Nt   axisiÿÿÿÿ(   t   Kt   anyt	   not_equalR   (   R   t   inputst   mask(    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyt   compute_mask:   s    c         C`  sD   t  j t  j | |  j ƒ d d d t ƒ} | t  j | t  j ƒ  ƒ S(   NR   iÿÿÿÿt   keepdims(   R   R   R   R   R   t   castt   floatx(   R   R   t   boolean_mask(    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyt   call=   s    c         C`  sK   i |  j  d 6} t t |  ƒ j ƒ  } t t | j ƒ  ƒ t | j ƒ  ƒ ƒ S(   NR   (   R   R   R   t
   get_configt   dictt   listt   items(   R   t   configt   base_config(    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR!   B   s    N(   t   __name__t
   __module__t   __doc__R   t   NoneR   R    R!   (    (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR      s
   	t   Dropoutc           B`  sD   e  Z d  Z e j d d d „ ƒ Z d „  Z d d „ Z d „  Z	 RS(   sj  Applies Dropout to the input.

    Dropout consists in randomly setting
    a fraction `p` of input units to 0 at each update during training time,
    which helps prevent overfitting.

    # Arguments
        rate: float between 0 and 1. Fraction of the input units to drop.
        noise_shape: 1D integer tensor representing the shape of the
            binary dropout mask that will be multiplied with the input.
            For instance, if your inputs have shape
            `(batch_size, timesteps, features)` and
            you want the dropout mask to be the same for all timesteps,
            you can use `noise_shape=(batch_size, 1, features)`.
        seed: A Python integer to use as random seed.

    # References
        - [Dropout: A Simple Way to Prevent Neural Networks from Overfitting](http://www.cs.toronto.edu/~rsalakhu/papers/srivastava14a.pdf)
    c         K`  sP   t  t |  ƒ j |   t d t d | ƒ ƒ |  _ | |  _ | |  _ t |  _	 d  S(   Ng      ð?g        (
   R   R+   R   t   mint   maxt   ratet   noise_shapet   seedR   R   (   R   R.   R/   R0   R   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR   \   s
    		c         C`  s   |  j  S(   N(   R/   (   R   t   _(    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyt   _get_noise_shaped   s    c         `  s]   d ˆ j  k  o d k  n rY ˆ j ˆ  ƒ ‰ ‡  ‡ ‡ f d †  } t j | ˆ  d | ƒSˆ  S(   Ng        g      ð?c           `  s   t  j ˆ  ˆ j ˆ d ˆ j ƒS(   NR0   (   R   t   dropoutR.   R0   (    (   R   R/   R   (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyt   dropped_inputsk   s    t   training(   R.   R2   R   t   in_train_phase(   R   R   R5   R4   (    (   R   R/   R   s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR    g   s    c         C`  sK   i |  j  d 6} t t |  ƒ j ƒ  } t t | j ƒ  ƒ t | j ƒ  ƒ ƒ S(   NR.   (   R.   R   R+   R!   R"   R#   R$   (   R   R%   R&   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR!   r   s    N(
   R'   R(   R)   R   t   legacy_dropout_supportR*   R   R2   R    R!   (    (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR+   H   s   	t   SpatialDropout1Dc           B`  s)   e  Z d  Z e j d „  ƒ Z d „  Z RS(   sv  Spatial 1D version of Dropout.

    This version performs the same function as Dropout, however it drops
    entire 1D feature maps instead of individual elements. If adjacent frames
    within feature maps are strongly correlated (as is normally the case in
    early convolution layers) then regular dropout will not regularize the
    activations and will otherwise just result in an effective learning rate
    decrease. In this case, SpatialDropout1D will help promote independence
    between feature maps and should be used instead.

    # Arguments
        p: float between 0 and 1. Fraction of the input units to drop.

    # Input shape
        3D tensor with shape:
        `(samples, timesteps, channels)`

    # Output shape
        Same as input

    # References
        - [Efficient Object Localization Using Convolutional Networks](https://arxiv.org/abs/1411.4280)
    c         K`  s/   t  t |  ƒ j | |  t d d ƒ |  _ d  S(   Nt   ndimi   (   R   R8   R   R   t
   input_spec(   R   R.   R   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR   ‘   s    c         C`  s*   t  j | ƒ } | d d | d f } | S(   Ni    i   i   (   R   t   shape(   R   R   t   input_shapeR/   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR2   –   s    (   R'   R(   R)   R   t   legacy_spatialdropout1d_supportR   R2   (    (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR8   x   s   t   SpatialDropout2Dc           B`  s,   e  Z d  Z e j d d „ ƒ Z d „  Z RS(   sš  Spatial 2D version of Dropout.

    This version performs the same function as Dropout, however it drops
    entire 2D feature maps instead of individual elements. If adjacent pixels
    within feature maps are strongly correlated (as is normally the case in
    early convolution layers) then regular dropout will not regularize the
    activations and will otherwise just result in an effective learning rate
    decrease. In this case, SpatialDropout2D will help promote independence
    between feature maps and should be used instead.

    # Arguments
        rate: float between 0 and 1. Fraction of the input units to drop.
        data_format: 'channels_first' or 'channels_last'.
            In 'channels_first' mode, the channels dimension
            (the depth) is at index 1,
            in 'channels_last' mode is it at index 3.
            It defaults to the `image_data_format` value found in your
            Keras config file at `~/.keras/keras.json`.
            If you never set it, then it will be "channels_last".

    # Input shape
        4D tensor with shape:
        `(samples, channels, rows, cols)` if data_format='channels_first'
        or 4D tensor with shape:
        `(samples, rows, cols, channels)` if data_format='channels_last'.

    # Output shape
        Same as input

    # References
        - [Efficient Object Localization Using Convolutional Networks](https://arxiv.org/abs/1411.4280)
    c         K`  st   t  t |  ƒ j | |  | d  k r4 t j ƒ  } n  | d d h k rU t d ƒ ‚ n  | |  _ t d d ƒ |  _	 d  S(   Nt   channels_lastt   channels_firsts:   data_format must be in {"channels_last", "channels_first"}R9   i   (
   R   R>   R   R*   R   t   image_data_formatt
   ValueErrort   data_formatR   R:   (   R   R.   RC   R   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR   ¾   s    	c         C`  s}   t  j | ƒ } |  j d k r; | d | d d d f } n> |  j d k rg | d d d | d f } n t d |  j ƒ ‚ | S(   NR@   i    i   R?   i   s   Invalid data_format:(   R   R;   RC   RB   (   R   R   R<   R/   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR2   É   s    N(   R'   R(   R)   R   t   legacy_spatialdropoutNd_supportR*   R   R2   (    (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR>   œ   s    
t   SpatialDropout3Dc           B`  s,   e  Z d  Z e j d d „ ƒ Z d „  Z RS(   sš  Spatial 3D version of Dropout.

    This version performs the same function as Dropout, however it drops
    entire 3D feature maps instead of individual elements. If adjacent voxels
    within feature maps are strongly correlated (as is normally the case in
    early convolution layers) then regular dropout will not regularize the
    activations and will otherwise just result in an effective learning rate
    decrease. In this case, SpatialDropout3D will help promote independence
    between feature maps and should be used instead.

    # Arguments
        rate: float between 0 and 1. Fraction of the input units to drop.
        data_format: 'channels_first' or 'channels_last'.
            In 'channels_first' mode, the channels dimension (the depth)
            is at index 1, in 'channels_last' mode is it at index 4.
            It defaults to the `image_data_format` value found in your
            Keras config file at `~/.keras/keras.json`.
            If you never set it, then it will be "channels_last".

    # Input shape
        5D tensor with shape:
        `(samples, channels, dim1, dim2, dim3)` if data_format='channels_first'
        or 5D tensor with shape:
        `(samples, dim1, dim2, dim3, channels)` if data_format='channels_last'.

    # Output shape
        Same as input

    # References
        - [Efficient Object Localization Using Convolutional Networks](https://arxiv.org/abs/1411.4280)
    c         K`  st   t  t |  ƒ j | |  | d  k r4 t j ƒ  } n  | d d h k rU t d ƒ ‚ n  | |  _ t d d ƒ |  _	 d  S(   NR?   R@   s:   data_format must be in {"channels_last", "channels_first"}R9   i   (
   R   RE   R   R*   R   RA   RB   RC   R   R:   (   R   R.   RC   R   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR   õ   s    	c         C`  sƒ   t  j | ƒ } |  j d k r> | d | d d d d f } nA |  j d k rm | d d d d | d f } n t d |  j ƒ ‚ | S(   NR@   i    i   R?   i   s   Invalid data_format:(   R   R;   RC   RB   (   R   R   R<   R/   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR2      s      N(   R'   R(   R)   R   RD   R*   R   R2   (    (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyRE   Ô   s   
t
   Activationc           B`  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   sè  Applies an activation function to an output.

    # Arguments
        activation: name of activation function to use
            (see: [activations](../activations.md)),
            or alternatively, a Theano or TensorFlow operation.

    # Input shape
        Arbitrary. Use the keyword argument `input_shape`
        (tuple of integers, does not include the samples axis)
        when using this layer as the first layer in a model.

    # Output shape
        Same shape as input.
    c         K`  s5   t  t |  ƒ j |   t |  _ t j | ƒ |  _ d  S(   N(   R   RF   R   R   R   R   t   gett
   activation(   R   RH   R   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR     s    	c         C`  s   |  j  | ƒ S(   N(   RH   (   R   R   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR    !  s    c         C`  sT   i t  j |  j ƒ d 6} t t |  ƒ j ƒ  } t t | j ƒ  ƒ t | j ƒ  ƒ ƒ S(   NRH   (	   R   t	   serializeRH   R   RF   R!   R"   R#   R$   (   R   R%   R&   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR!   $  s    (   R'   R(   R)   R   R    R!   (    (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyRF     s   		t   Reshapec           B`  s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s,  Reshapes an output to a certain shape.

    # Arguments
        target_shape: target shape. Tuple of integers,
            does not include the samples dimension (batch size).

    # Input shape
        Arbitrary, although all dimensions in the input shaped must be fixed.
        Use the keyword argument `input_shape`
        (tuple of integers, does not include the samples axis)
        when using this layer as the first layer in a model.

    # Output shape
        `(batch_size,) + target_shape`

    # Example

    ```python
        # as first layer in a Sequential model
        model = Sequential()
        model.add(Reshape((3, 4), input_shape=(12,)))
        # now: model.output_shape == (None, 3, 4)
        # note: `None` is the batch dimension

        # as intermediate layer in a Sequential model
        model.add(Reshape((6, 2)))
        # now: model.output_shape == (None, 6, 2)

        # also supports shape inference using `-1` as dimension
        model.add(Reshape((-1, 2, 2)))
        # now: model.output_shape == (None, 3, 2, 2)
    ```
    c         K`  s)   t  t |  ƒ j |   t | ƒ |  _ d  S(   N(   R   RJ   R   t   tuplet   target_shape(   R   RL   R   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR   M  s    c   	      C`  s÷   t  | ƒ } d } d \ } } xT t | ƒ D]F \ } } | d k  rg | d k rX | } qq t d ƒ ‚ q+ | | 9} q+ Wt j | d t ƒ} | d k	 rÒ | d k s² | | d k rÁ t | ƒ ‚ n  | | | | <n | | k rí t | ƒ ‚ n  t | ƒ S(   s`  Find and replace a missing dimension in an output shape.

        This is a near direct port of the internal Numpy function
        `_fix_unknown_dimension` in `numpy/core/src/multiarray/shape.c`

        # Arguments
            input_shape: shape of array being reshaped
            output_shape: desired shape of the array with at most
                a single -1 which indicates a dimension that should be
                derived from the input shape.

        # Returns
            The new output shape with a -1 replaced with its computed value.

            Raises a ValueError if the total array size of the output_shape is
            different then the input_shape, or more then one unknown dimension
            is specified.

        # Raises
            ValueError: in case of invalid values
                for `input_shape` or `input_shape`.
        s)   total size of new array must be unchangedi   i    s'   Can only specify one unknown dimension.t   dtypeN(   i   N(   R#   R*   t	   enumerateRB   t   npt   prodt   intRK   (	   R   R<   t   output_shapet   msgt   knownt   unknownt   indext   dimt   original(    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyt   _fix_unknown_dimensionQ  s"    	c         C`  s"   | d f |  j  | d |  j ƒ S(   Ni    i   (   RY   RL   (   R   R<   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyt   compute_output_shape  s    c         C`  s{   |  j  } d | k rg d  } y t j | ƒ } Wn t k
 rA n X| d  k	 rg |  j | ƒ d } qg n  t j | d | ƒ S(   Niÿÿÿÿi   (   iÿÿÿÿ(   RL   R*   R   t	   int_shapet	   TypeErrorRZ   t   reshape(   R   R   RL   R<   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR    ƒ  s    	c         C`  sK   i |  j  d 6} t t |  ƒ j ƒ  } t t | j ƒ  ƒ t | j ƒ  ƒ ƒ S(   NRL   (   RL   R   RJ   R!   R"   R#   R$   (   R   R%   R&   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR!   •  s    (   R'   R(   R)   R   RY   RZ   R    R!   (    (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyRJ   *  s   !		.		t   Permutec           B`  s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s¤  Permutes the dimensions of the input according to a given pattern.

    Useful for e.g. connecting RNNs and convnets together.

    # Example

    ```python
        model = Sequential()
        model.add(Permute((2, 1), input_shape=(10, 64)))
        # now: model.output_shape == (None, 64, 10)
        # note: `None` is the batch dimension
    ```

    # Arguments
        dims: Tuple of integers. Permutation pattern, does not include the
            samples dimension. Indexing starts at 1.
            For instance, `(2, 1)` permutes the first and second dimension
            of the input.

    # Input shape
        Arbitrary. Use the keyword argument `input_shape`
        (tuple of integers, does not include the samples axis)
        when using this layer as the first layer in a model.

    # Output shape
        Same as the input shape, but with the dimensions re-ordered according
        to the specified pattern.
    c         K`  sH   t  t |  ƒ j |   t | ƒ |  _ t d t |  j ƒ d ƒ |  _ d  S(   NR9   i   (   R   R^   R   RK   t   dimsR   t   lenR:   (   R   R_   R   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR   ¹  s    c         C`  s]   t  | ƒ } t j | ƒ } x5 t |  j ƒ D]$ \ } } | | } | | | d <q+ Wt | ƒ S(   Ni   (   R#   t   copyRN   R_   RK   (   R   R<   RR   t   iRW   t
   target_dim(    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyRZ   ¾  s    
c         C`  s   t  j | d |  j ƒ S(   Ni    (   i    (   R   t   permute_dimensionsR_   (   R   R   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR    Æ  s    c         C`  sK   i |  j  d 6} t t |  ƒ j ƒ  } t t | j ƒ  ƒ t | j ƒ  ƒ ƒ S(   NR_   (   R_   R   R^   R!   R"   R#   R$   (   R   R%   R&   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR!   É  s    (   R'   R(   R)   R   RZ   R    R!   (    (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR^   ›  s
   			t   Flattenc           B`  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   sœ  Flattens the input. Does not affect the batch size.

    # Example

    ```python
        model = Sequential()
        model.add(Convolution2D(64, 3, 3,
                                border_mode='same',
                                input_shape=(3, 32, 32)))
        # now: model.output_shape == (None, 64, 32, 32)

        model.add(Flatten())
        # now: model.output_shape == (None, 65536)
    ```
    c         K`  s,   t  t |  ƒ j |   t d d ƒ |  _ d  S(   Nt   min_ndimi   (   R   Re   R   R   R:   (   R   R   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR   à  s    c         C`  sL   t  | d ƒ s1 t d t | d ƒ d ƒ ‚ n  | d t j | d ƒ f S(   Ni   s>   The shape of the input to "Flatten" is not fully defined (got sn   . Make sure to pass a complete "input_shape" or "batch_input_shape" argument to the first layer in your model.i    (   t   allRB   t   strRO   RP   (   R   R<   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyRZ   ä  s    c         C`  s   t  j | ƒ S(   N(   R   t   batch_flatten(   R   R   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR    î  s    (   R'   R(   R)   R   RZ   R    (    (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyRe   Ï  s   		
t   RepeatVectorc           B`  s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s  Repeats the input n times.

    # Example

    ```python
        model = Sequential()
        model.add(Dense(32, input_dim=32))
        # now: model.output_shape == (None, 32)
        # note: `None` is the batch dimension

        model.add(RepeatVector(3))
        # now: model.output_shape == (None, 3, 32)
    ```

    # Arguments
        n: integer, repetition factor.

    # Input shape
        2D tensor of shape `(num_samples, features)`.

    # Output shape
        3D tensor of shape `(num_samples, n, features)`.
    c         K`  s5   t  t |  ƒ j |   | |  _ t d d ƒ |  _ d  S(   NR9   i   (   R   Rj   R   t   nR   R:   (   R   Rk   R   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR     s    	c         C`  s   | d |  j  | d f S(   Ni    i   (   Rk   (   R   R<   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyRZ     s    c         C`  s   t  j | |  j ƒ S(   N(   R   t   repeatRk   (   R   R   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR      s    c         C`  sK   i |  j  d 6} t t |  ƒ j ƒ  } t t | j ƒ  ƒ t | j ƒ  ƒ ƒ S(   NRk   (   Rk   R   Rj   R!   R"   R#   R$   (   R   R%   R&   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR!     s    (   R'   R(   R)   R   RZ   R    R!   (    (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyRj   ò  s
   			t   Lambdac           B`  se   e  Z d  Z e j d d d d „ ƒ Z d „  Z d d „ Z d d „ Z	 d „  Z
 e d d „ ƒ Z RS(   s  Wraps arbitrary expression as a `Layer` object.

    # Examples

    ```python
        # add a x -> x^2 layer
        model.add(Lambda(lambda x: x ** 2))
    ```
    ```python
        # add a layer that returns the concatenation
        # of the positive part of the input and
        # the opposite of the negative part

        def antirectifier(x):
            x -= K.mean(x, axis=1, keepdims=True)
            x = K.l2_normalize(x, axis=1)
            pos = K.relu(x)
            neg = K.relu(-x)
            return K.concatenate([pos, neg], axis=1)

        def antirectifier_output_shape(input_shape):
            shape = list(input_shape)
            assert len(shape) == 2  # only valid for 2D tensors
            shape[-1] *= 2
            return tuple(shape)

        model.add(Lambda(antirectifier,
                         output_shape=antirectifier_output_shape))
    ```

    # Arguments
        function: The function to be evaluated.
            Takes input tensor as first argument.
        output_shape: Expected output shape from function.
            Only relevant when using Theano.
            Can be a tuple or function.
            If a tuple, it only specifies the first dimension onward;
                 sample dimension is assumed either the same as the input:
                 `output_shape = (input_shape[0], ) + output_shape`
                 or, the input is `None` and
                 the sample dimension is also `None`:
                 `output_shape = (None, ) + output_shape`
            If a function, it specifies the entire shape as a function of the
            input shape: `output_shape = f(input_shape)`
        arguments: optional dictionary of keyword arguments to be passed
            to the function.

    # Input shape
        Arbitrary. Use the keyword argument input_shape
        (tuple of integers, does not include the samples axis)
        when using this layer as the first layer in a model.

    # Output shape
        Specified by `output_shape` argument
        (or auto-inferred when using TensorFlow).
    c         K`  s¼   t  t |  ƒ j |   | |  _ | r+ | n i  |  _ | d  k	 rL t |  _ n  | |  _ | d  k rm d  |  _	 nK t
 | t t f ƒ r” t | ƒ |  _	 n$ t | ƒ s¯ t d ƒ ‚ n  | |  _	 d  S(   NsA   In Lambda, `output_shape` must be a list, a tuple, or a function.(   R   Rm   R   t   functiont	   argumentsR*   R   R   R   t   _output_shapet
   isinstanceRK   R#   t   callableR\   (   R   Rn   RR   R   Ro   R   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR   V  s    		c         C`  sŠ  |  j  d  k rç t j ƒ  d k rÇ t | t ƒ rg g  | D] } t j d | ƒ ^ q7 } |  j | ƒ } n! t j d | ƒ } |  j | ƒ } t | t ƒ r· g  | D] } t j | ƒ ^ qž St j | ƒ Sn  t	 j
 d j |  j | ƒ ƒ | St |  j  t t f ƒ rIt | t ƒ r| d d } n | r/| d n d  } | f t |  j  ƒ S|  j  | ƒ } t | t t f ƒ s|t d ƒ ‚ n  t | ƒ Sd  S(   Nt
   tensorflowR;   sþ   `output_shape` argument not specified for layer {} and cannot be automatically inferred with the Theano backend. Defaulting to output shape `{}` (same as input shape). If the expected output shape is different, specify it via the `output_shape` argument.i    s)   output_shape function must return a tuple(   Rp   R*   R   R   Rq   R#   t   placeholderR    R[   t   warningst   warnt   formatt   nameRK   RB   (   R   R<   R;   t   xst   xt   x_elemt   num_samples(    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyRZ   j  s,    % c         C`  sG   |  j  } t j |  j ƒ } d | j k r7 | | d <n  |  j | |  S(   NR   (   Ro   t   inspectt
   getargspecRn   t   args(   R   R   R   Ro   t   arg_spec(    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR    Ž  s
    	c         C`  s&   t  |  j ƒ r |  j | | ƒ S|  j S(   N(   Rr   R   (   R   R   R   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR   •  s    c         C`  s  t  |  j t j ƒ r- t |  j ƒ } d } n |  j j } d } t  |  j t j ƒ rl t |  j ƒ } d } n3 t |  j ƒ r |  j j } d } n |  j } d } i | d 6| d 6| d 6| d 6|  j d 6} t	 t
 |  ƒ j ƒ  } t t | j ƒ  ƒ t | j ƒ  ƒ ƒ S(   Nt   lambdaRn   t   rawt   function_typeRR   t   output_shape_typeRo   (   Rq   Rn   t   python_typest
   LambdaTypeR	   R'   Rp   Rr   Ro   R   Rm   R!   R"   R#   R$   (   R   Rn   Rƒ   RR   R„   R%   R&   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR!   š  s(    				
c         C`  s/  t  ƒ  } | r: t t | j ƒ  ƒ t | j ƒ  ƒ ƒ } n  | j d ƒ } | d k rt t | d d | d d ƒ} n4 | d k r™ t | d d | ƒ} n t d | ƒ ‚ | j d	 ƒ } | d k râ t | d
 d | d d ƒ} n/ | d k rt | d
 d | ƒ} n
 | d
 } | | d <| | d
 <|  |   S(   NRƒ   Rn   t   custom_objectst   printable_module_names   function in Lambda layerR   t   globss   Unknown function type:R„   RR   s%   output_shape function in Lambda layer(   t   globalsR"   R#   R$   t   popR   R
   R\   (   t   clsR%   R‡   R‰   Rƒ   Rn   R„   RR   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyt   from_config´  s0    	+




N(   R'   R(   R)   R   t   legacy_lambda_supportR*   R   RZ   R    R   R!   t   classmethodR   (    (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyRm     s   8	$	t   Densec           B`  s_   e  Z d  Z e j d e d d d d d d d d „	 ƒ Z d „  Z d „  Z	 d „  Z
 d „  Z RS(	   sh
  Just your regular densely-connected NN layer.

    `Dense` implements the operation:
    `output = activation(dot(input, kernel) + bias)`
    where `activation` is the element-wise activation function
    passed as the `activation` argument, `kernel` is a weights matrix
    created by the layer, and `bias` is a bias vector created by the layer
    (only applicable if `use_bias` is `True`).

    Note: if the input to the layer has a rank greater than 2, then
    it is flattened prior to the initial dot product with `kernel`.

    # Example

    ```python
        # as first layer in a sequential model:
        model = Sequential()
        model.add(Dense(32, input_shape=(16,)))
        # now the model will take as input arrays of shape (*, 16)
        # and output arrays of shape (*, 32)

        # after the first layer, you don't need to specify
        # the size of the input anymore:
        model.add(Dense(32))
    ```

    # Arguments
        units: Positive integer, dimensionality of the output space.
        activation: Activation function to use
            (see [activations](../activations.md)).
            If you don't specify anything, no activation is applied
            (ie. "linear" activation: `a(x) = x`).
        use_bias: Boolean, whether the layer uses a bias vector.
        kernel_initializer: Initializer for the `kernel` weights matrix
            (see [initializers](../initializers.md)).
        bias_initializer: Initializer for the bias vector
            (see [initializers](../initializers.md)).
        kernel_regularizer: Regularizer function applied to
            the `kernel` weights matrix
            (see [regularizer](../regularizers.md)).
        bias_regularizer: Regularizer function applied to the bias vector
            (see [regularizer](../regularizers.md)).
        activity_regularizer: Regularizer function applied to
            the output of the layer (its "activation").
            (see [regularizer](../regularizers.md)).
        kernel_constraint: Constraint function applied to
            the `kernel` weights matrix
            (see [constraints](../constraints.md)).
        bias_constraint: Constraint function applied to the bias vector
            (see [constraints](../constraints.md)).

    # Input shape
        nD tensor with shape: `(batch_size, ..., input_dim)`.
        The most common situation would be
        a 2D input with shape `(batch_size, input_dim)`.

    # Output shape
        nD tensor with shape: `(batch_size, ..., units)`.
        For instance, for a 2D input with shape `(batch_size, input_dim)`,
        the output would have shape `(batch_size, units)`.
    t   glorot_uniformt   zerosc         K`  s  d | k r1 d | k r1 | j  d ƒ f | d <n  t t |  ƒ j |   | |  _ t j | ƒ |  _ | |  _ t	 j | ƒ |  _
 t	 j | ƒ |  _ t j | ƒ |  _ t j | ƒ |  _ t j | ƒ |  _ t j |	 ƒ |  _ t j |
 ƒ |  _ t d d ƒ |  _ t |  _ d  S(   NR<   t	   input_dimRf   i   (   R‹   R   R   R   t   unitsR   RG   RH   t   use_biasR   t   kernel_initializert   bias_initializerR   t   kernel_regularizert   bias_regularizert   activity_regularizerR   t   kernel_constraintt   bias_constraintR   R:   R   R   (   R   R”   RH   R•   R–   R—   R˜   R™   Rš   R›   Rœ   R   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR     s    		c      
   C`  sØ   t  | ƒ d k s t ‚ | d } |  j | |  j f d |  j d d d |  j d |  j ƒ|  _ |  j r£ |  j |  j f d |  j	 d d d |  j
 d |  j ƒ|  _ n	 d  |  _ t d	 d d
 i | d 6ƒ |  _ t |  _ d  S(   Ni   iÿÿÿÿt   initializerRx   t   kernelt   regularizert
   constraintt   biasRf   t   axes(   R`   t   AssertionErrort
   add_weightR”   R–   R˜   R›   Rž   R•   R—   R™   Rœ   R¡   R*   R   R:   R   t   built(   R   R<   R“   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyt   build3  s     
						c         C`  s[   t  j | |  j ƒ } |  j r6 t  j | |  j ƒ } n  |  j d  k	 rW |  j | ƒ } n  | S(   N(   R   t   dotRž   R•   t   bias_addR¡   RH   R*   (   R   R   t   output(    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR    G  s    	c         C`  sQ   | r t  | ƒ d k s t ‚ | d s. t ‚ t | ƒ } |  j | d <t | ƒ S(   Ni   iÿÿÿÿ(   R`   R£   R#   R”   RK   (   R   R<   RR   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyRZ   O  s
    c         C`  sí   i
 |  j  d 6t j |  j ƒ d 6|  j d 6t j |  j ƒ d 6t j |  j ƒ d 6t j |  j	 ƒ d 6t j |  j
 ƒ d 6t j |  j ƒ d 6t j |  j ƒ d	 6t j |  j ƒ d
 6} t t |  ƒ j ƒ  } t t | j ƒ  ƒ t | j ƒ  ƒ ƒ S(   NR”   RH   R•   R–   R—   R˜   R™   Rš   R›   Rœ   (   R”   R   RI   RH   R•   R   R–   R—   R   R˜   R™   Rš   R   R›   Rœ   R   R   R!   R"   R#   R$   (   R   R%   R&   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR!   V  s    

N(   R'   R(   R)   R   t   legacy_dense_supportR*   R   R   R¦   R    RZ   R!   (    (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR   Ø  s   =			t   ActivityRegularizationc           B`  s&   e  Z d  Z d d d „ Z d „  Z RS(   sÅ  Layer that applies an update to the cost function based input activity.

    # Arguments
        l1: L1 regularization factor (positive float).
        l2: L2 regularization factor (positive float).

    # Input shape
        Arbitrary. Use the keyword argument `input_shape`
        (tuple of integers, does not include the samples axis)
        when using this layer as the first layer in a model.

    # Output shape
        Same shape as input.
    g        c         K`  sP   t  t |  ƒ j |   t |  _ | |  _ | |  _ t j d | d | ƒ |  _	 d  S(   Nt   l1t   l2(
   R   R«   R   R   R   R¬   R­   R   t   L1L2Rš   (   R   R¬   R­   R   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR   w  s
    			c         C`  sU   i |  j  d 6|  j d 6} t t |  ƒ j ƒ  } t t | j ƒ  ƒ t | j ƒ  ƒ ƒ S(   NR¬   R­   (   R¬   R­   R   R«   R!   R"   R#   R$   (   R   R%   R&   (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR!   ~  s    (   R'   R(   R)   R   R!   (    (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyR«   g  s   ('   t
   __future__R    R   t   numpyRO   Ra   R}   t   typesR…   Ru   t    R   R   R   R   R   R   t   engineR   R   t   utils.generic_utilsR	   R
   R   t   legacyR   R   R+   R8   R>   RE   RF   RJ   R^   Re   Rj   Rm   R   R«   (    (    (    s0   /tmp/pip-build-isqEY4/keras/keras/layers/core.pyt   <module>   s<   /0$87q4#*¼