
    ije                     v   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
  G d de      Z ed	d
g       G d de             Z eddg       G d de             Z eddg       G d de             Z eddg       G d de             Z eddg       G d de             Z eddg       G d d e             Z ed!d"g       G d# d$e             Z ed%d&g       G d' d(e             Z ed)d*g       G d+ d,e             Z ed-d.g       G d/ d0e             Zd5d1Z eg d2       G d3 d4e             Zy)6    N)ops)keras_export)random)Initializer)serialization_libc                       e Zd ZddZd Zy)RandomInitializerNc                    || _         |t        j                         }|| _
        y t        |t              rt        j                  |      }|| _
        y t        |t        t        j                  f      st        d|       || _
        y )Nzf`seed` argument should be an instance of `keras.random.SeedGenerator()` or an integer. Received: seed=)
_init_seedr   make_default_seed
isinstancedictr   deserialize_keras_objectintSeedGenerator
ValueErrorseed)selfr   s     /var/www/html/emotional.easysim.app/public_html/venv/lib/python3.12/site-packages/keras/src/initializers/random_initializers.py__init__zRandomInitializer.__init__   s    <++-D 	 d#$==dCD 	 D3(<(<"=>""&) 
 	    c                 H    t        j                  | j                        }d|iS )Nr   )r   serialize_keras_objectr   )r   seed_configs     r   
get_configzRandomInitializer.get_config   s!    '>>tO$$r   N)__name__
__module____qualname__r   r    r   r   r	   r	   
   s    %r   r	   zkeras.initializers.RandomNormalz keras.initializers.random_normalc                   6     e Zd ZdZd fd	ZddZ fdZ xZS )RandomNormalaE  Random normal initializer.

    Draws samples from a normal distribution for given parameters.

    Examples:

    >>> # Standalone usage:
    >>> initializer = RandomNormal(mean=0.0, stddev=1.0)
    >>> values = initializer(shape=(2, 2))

    >>> # Usage in a Keras layer:
    >>> initializer = RandomNormal(mean=0.0, stddev=1.0)
    >>> layer = Dense(3, kernel_initializer=initializer)

    Args:
        mean: A python scalar or a scalar keras tensor. Mean of the random
            values to generate.
        stddev: A python scalar or a scalar keras tensor. Standard deviation of
           the random values to generate.
        seed: A Python integer or instance of
            `keras.backend.SeedGenerator`.
            Used to make the behavior of the initializer
            deterministic. Note that an initializer seeded with an integer
            or `None` (unseeded) will produce the same random values
            across multiple calls. To get different random values
            across multiple calls, use as seed an instance
            of `keras.backend.SeedGenerator`.
    c                 B    || _         || _        t        |   |       y Nr   meanstddevsuperr   r   r'   r(   r   	__class__s       r   r   zRandomNormal.__init__B   !    	d#r   c                 r    t        j                  || j                  | j                  | j                  |      S N)shaper'   r(   r   dtype)r   normalr'   r(   r   r   r/   r0   s      r   __call__zRandomNormal.__call__G   s.    }};;
 	
r   c                 ^    t         |          }| j                  | j                  d}i ||S N)r'   r(   r)   r   r'   r(   r   base_configconfigr+   s      r   r   zRandomNormal.get_configP   2    g(*))t{{;(+(((r           皙?Nr   r   r   r   __doc__r   r3   r   __classcell__r+   s   @r   r"   r"          :$

) )r   r"   z"keras.initializers.TruncatedNormalz#keras.initializers.truncated_normalc                   6     e Zd ZdZd fd	ZddZ fdZ xZS )TruncatedNormala  Initializer that generates a truncated normal distribution.

    The values generated are similar to values from a
    `RandomNormal` initializer, except that values more
    than two standard deviations from the mean are
    discarded and re-drawn.

    Examples:

    >>> # Standalone usage:
    >>> initializer = TruncatedNormal(mean=0., stddev=1.)
    >>> values = initializer(shape=(2, 2))

    >>> # Usage in a Keras layer:
    >>> initializer = TruncatedNormal(mean=0., stddev=1.)
    >>> layer = Dense(3, kernel_initializer=initializer)

    Args:
        mean: A python scalar or a scalar keras tensor. Mean of the random
            values to generate.
        stddev: A python scalar or a scalar keras tensor. Standard deviation of
           the random values to generate.
        seed: A Python integer or instance of
            `keras.backend.SeedGenerator`.
            Used to make the behavior of the initializer
            deterministic. Note that an initializer seeded with an integer
            or `None` (unseeded) will produce the same random values
            across multiple calls. To get different random values
            across multiple calls, use as seed an instance
            of `keras.backend.SeedGenerator`.
    c                 B    || _         || _        t        |   |       y r$   r&   r*   s       r   r   zTruncatedNormal.__init__}   r,   r   c                 r    t        j                  || j                  | j                  | j                  |      S r.   )r   truncated_normalr'   r(   r   r2   s      r   r3   zTruncatedNormal.__call__   s0    &&;;
 	
r   c                 ^    t         |          }| j                  | j                  d}i ||S r5   r6   r7   s      r   r   zTruncatedNormal.get_config   r:   r   r;   r   r>   rA   s   @r   rD   rD   V   s    @$

) )r   rD   z keras.initializers.RandomUniformz!keras.initializers.random_uniformc                   6     e Zd ZdZd fd	ZddZ fdZ xZS )RandomUniformaz  Random uniform initializer.

    Draws samples from a uniform distribution for given parameters.

    Examples:

    >>> # Standalone usage:
    >>> initializer = RandomUniform(minval=0.0, maxval=1.0)
    >>> values = initializer(shape=(2, 2))

    >>> # Usage in a Keras layer:
    >>> initializer = RandomUniform(minval=0.0, maxval=1.0)
    >>> layer = Dense(3, kernel_initializer=initializer)

    Args:
        minval: A python scalar or a scalar keras tensor. Lower bound of the
            range of random values to generate (inclusive).
        maxval: A python scalar or a scalar keras tensor. Upper bound of the
            range of random values to generate (exclusive).
        seed: A Python integer or instance of
            `keras.backend.SeedGenerator`.
            Used to make the behavior of the initializer
            deterministic. Note that an initializer seeded with an integer
            or `None` (unseeded) will produce the same random values
            across multiple calls. To get different random values
            across multiple calls, use as seed an instance
            of `keras.backend.SeedGenerator`.
    c                 B    || _         || _        t        |   |       y r$   )minvalmaxvalr)   r   )r   rL   rM   r   r+   s       r   r   zRandomUniform.__init__   s!    d#r   c                 r    t        j                  || j                  | j                  | j                  |      S )N)r/   rL   rM   r   r0   )r   uniformrL   rM   r   r2   s      r   r3   zRandomUniform.__call__   s.    ~~;;;;
 	
r   c                 ^    t         |          }| j                  | j                  d}i ||S )N)rL   rM   )r)   r   rL   rM   r7   s      r   r   zRandomUniform.get_config   s2    g(* KK4;;?(+(((r   )gr=   Nr   r>   rA   s   @r   rJ   rJ      rB   r   rJ   z"keras.initializers.VarianceScalingz#keras.initializers.variance_scalingc                   B     e Zd ZdZ	 	 	 	 	 	 d fd	ZddZ fdZ xZS )VarianceScalinga  Initializer that adapts its scale to the shape of its input tensors.

    With `distribution="truncated_normal" or "untruncated_normal"`, samples are
    drawn from a truncated/untruncated normal distribution with a mean of zero
    and a standard deviation (after truncation, if used) `stddev = sqrt(scale /
    n)`, where `n` is:

    - number of input units in the weight tensor, if `mode="fan_in"`
    - number of output units, if `mode="fan_out"`
    - average of the numbers of input and output units, if `mode="fan_avg"`

    With `distribution="uniform"`, samples are drawn from a uniform distribution
    within `[-limit, limit]`, where `limit = sqrt(3 * scale / n)`.

    Examples:

    >>> # Standalone usage:
    >>> initializer = VarianceScaling(
        scale=0.1, mode='fan_in', distribution='uniform')
    >>> values = initializer(shape=(2, 2))

    >>> # Usage in a Keras layer:
    >>> initializer = VarianceScaling(
        scale=0.1, mode='fan_in', distribution='uniform')
    >>> layer = Dense(3, kernel_initializer=initializer)

    Args:
        scale: Scaling factor (positive float).
        mode: One of `"fan_in"`, `"fan_out"`, `"fan_avg"`.
        distribution: Random distribution to use.
            One of `"truncated_normal"`, `"untruncated_normal"`, or `"uniform"`.
        seed: A Python integer or instance of
            `keras.backend.SeedGenerator`.
            Used to make the behavior of the initializer
            deterministic. Note that an initializer seeded with an integer
            or `None` (unseeded) will produce the same random values
            across multiple calls. To get different random values
            across multiple calls, use as seed an instance
            of `keras.backend.SeedGenerator`.
        input_axes: Optional list of integers. The axes of the input tensor
            that should be considered for computing the fan-in.
        output_axes: Optional list of integers. The axes of the output tensor
            that should be considered for computing the fan-out.
    c                 $   |dk  rt        d|       h d}||vrt        d| d|       |j                         }|dk(  rd}h d}||vrt        d	| d
|       || _        || _        || _        || _        || _        t        	| !  |       y )Nr<   z9Argument `scale` must be positive float. Received: scale=>   fan_infan_avgfan_outzInvalid `mode` argument: z. Please use one of r1   rG   >   rO   rG   untruncated_normalz!Invalid `distribution` argument: z.Please use one of r%   )	r   lowerscalemodedistribution
input_axesoutput_axesr)   r   )
r   rY   rZ   r[   r   r\   r]   allowed_modesallowed_distributionsr+   s
            r   r   zVarianceScaling.__init__   s     C<##('+  9}$+D6 2%%2O5  $))+8#-L!

 443L> B%%:$;=  
	($&d#r   c                    | j                   }t        || j                  | j                        \  }}| j                  dk(  r|t        d|      z  }n4| j                  dk(  r|t        d|      z  }n|t        d||z   dz        z  }| j                  dk(  r<t        j                  |      dz  }t        j                  |d||| j                  	      S | j                  d
k(  r9t        j                  |      }t        j                  |d||| j                  	      S t        j                  d|z        }t        j                  || ||| j                        S )N)r\   r]   rT         ?rV          @rG   g۶%?r<   )r'   r(   r0   r   rW   g      @)rL   rM   r0   r   )rY   compute_fansr\   r]   rZ   maxr[   mathsqrtr   rG   r   r1   rO   )r   r/   r0   rY   rT   rV   r(   limits           r   r3   zVarianceScaling.__call__%  s;   

&doo4;K;K
 99 Sf%%EYY)#Sg&&ESv/3677E 22YYu%(;;F**Ce$))  "66YYu%F==Ce$))  IIcEk*E>>ufU%dii r   c                     t         |          }| j                  | j                  | j                  | j
                  | j                  d}i ||S )N)rY   rZ   r[   r\   r]   )r)   r   rY   rZ   r[   r\   r]   r7   s      r   r   zVarianceScaling.get_config@  sP    g(*ZZII --//++
 )+(((r   )ra   rT   rG   NNNr   r>   rA   s   @r   rR   rR      s2    +^ '&$P6	) 	)r   rR   z keras.initializers.GlorotUniformz!keras.initializers.glorot_uniformc                   *     e Zd ZdZd fd	Zd Z xZS )GlorotUniformah  The Glorot uniform initializer, also called Xavier uniform initializer.

    Draws samples from a uniform distribution within `[-limit, limit]`, where
    `limit = sqrt(6 / (fan_in + fan_out))` (`fan_in` is the number of input
    units in the weight tensor and `fan_out` is the number of output units).

    Examples:

    >>> # Standalone usage:
    >>> initializer = GlorotUniform()
    >>> values = initializer(shape=(2, 2))

    >>> # Usage in a Keras layer:
    >>> initializer = GlorotUniform()
    >>> layer = Dense(3, kernel_initializer=initializer)

    Args:
        seed: A Python integer or instance of
            `keras.backend.SeedGenerator`.
            Used to make the behavior of the initializer
            deterministic. Note that an initializer seeded with an integer
            or `None` (unseeded) will produce the same random values
            across multiple calls. To get different random values
            across multiple calls, use as seed an instance
            of `keras.backend.SeedGenerator`.

    Reference:

    - [Glorot et al., 2010](http://proceedings.mlr.press/v9/glorot10a.html)
    c                 0    t         |   ddd|||       y )Nra   rU   rO   rY   rZ   r[   r   r\   r]   r)   r   r   r   r\   r]   r+   s       r   r   zGlorotUniform.__init__r  s'    "!# 	 	
r   c                 p    t        j                  | j                        | j                  | j                  dS N)r   r\   r]   r   r   r   r\   r]   r   s    r   r   zGlorotUniform.get_config|  .    %<<T__M//++
 	
r   NNNr   r   r   r?   r   r   r@   rA   s   @r   rj   rj   L      >

r   rj   zkeras.initializers.GlorotNormalz keras.initializers.glorot_normalc                   *     e Zd ZdZd fd	Zd Z xZS )GlorotNormala~  The Glorot normal initializer, also called Xavier normal initializer.

    Draws samples from a truncated normal distribution centered on 0 with
    `stddev = sqrt(2 / (fan_in + fan_out))` where `fan_in` is the number of
    input units in the weight tensor and `fan_out` is the number of output units
    in the weight tensor.

    Examples:

    >>> # Standalone usage:
    >>> initializer = GlorotNormal()
    >>> values = initializer(shape=(2, 2))

    >>> # Usage in a Keras layer:
    >>> initializer = GlorotNormal()
    >>> layer = Dense(3, kernel_initializer=initializer)

    Args:
        seed: A Python integer or instance of
            `keras.backend.SeedGenerator`.
            Used to make the behavior of the initializer
            deterministic. Note that an initializer seeded with an integer
            or `None` (unseeded) will produce the same random values
            across multiple calls. To get different random values
            across multiple calls, use as seed an instance
            of `keras.backend.SeedGenerator`.

    Reference:

    - [Glorot et al., 2010](http://proceedings.mlr.press/v9/glorot10a.html)
    c                 0    t         |   ddd|||       y )Nra   rU   rG   rl   rm   rn   s       r   r   zGlorotNormal.__init__  s'    +!# 	 	
r   c                 p    t        j                  | j                        | j                  | j                  dS rp   rq   rr   s    r   r   zGlorotNormal.get_config  rs   r   rt   ru   rA   s   @r   rx   rx     s    @

r   rx   zkeras.initializers.LecunNormalzkeras.initializers.lecun_normalc                   *     e Zd ZdZd fd	Zd Z xZS )LecunNormala  Lecun normal initializer.

    Initializers allow you to pre-specify an initialization strategy, encoded in
    the Initializer object, without knowing the shape and dtype of the variable
    being initialized.

    Draws samples from a truncated normal distribution centered on 0 with
    `stddev = sqrt(1 / fan_in)` where `fan_in` is the number of input units in
    the weight tensor.

    Examples:

    >>> # Standalone usage:
    >>> initializer = LecunNormal()
    >>> values = initializer(shape=(2, 2))

    >>> # Usage in a Keras layer:
    >>> initializer = LecunNormal()
    >>> layer = Dense(3, kernel_initializer=initializer)

    Args:
        seed: A Python integer or instance of
            `keras.backend.SeedGenerator`.
            Used to make the behavior of the initializer
            deterministic. Note that an initializer seeded with an integer
            or `None` (unseeded) will produce the same random values
            across multiple calls. To get different random values
            across multiple calls, use as seed an instance
            of `keras.backend.SeedGenerator`.

    Reference:

    - [Klambauer et al., 2017](https://arxiv.org/abs/1706.02515)
    c                 0    t         |   ddd|||       y )Nra   rT   rG   rl   rm   rn   s       r   r   zLecunNormal.__init__  '    +!# 	 	
r   c                 p    t        j                  | j                        | j                  | j                  dS rp   rq   rr   s    r   r   zLecunNormal.get_config  rs   r   rt   ru   rA   s   @r   r|   r|     s    !F

r   r|   zkeras.initializers.LecunUniformz keras.initializers.lecun_uniformc                   *     e Zd ZdZd fd	Zd Z xZS )LecunUniforma  Lecun uniform initializer.

    Draws samples from a uniform distribution within `[-limit, limit]`, where
    `limit = sqrt(3 / fan_in)` (`fan_in` is the number of input units in the
    weight tensor).

    Examples:

    >>> # Standalone usage:
    >>> initializer = LecunUniform()
    >>> values = initializer(shape=(2, 2))

    >>> # Usage in a Keras layer:
    >>> initializer = LecunUniform()
    >>> layer = Dense(3, kernel_initializer=initializer)

    Args:
        seed: A Python integer or instance of
            `keras.backend.SeedGenerator`.
            Used to make the behavior of the initializer
            deterministic. Note that an initializer seeded with an integer
            or `None` (unseeded) will produce the same random values
            across multiple calls. To get different random values
            across multiple calls, use as seed an instance
            of `keras.backend.SeedGenerator`.

    Reference:

    - [Klambauer et al., 2017](https://arxiv.org/abs/1706.02515)
    c                 0    t         |   ddd|||       y )Nra   rT   rO   rl   rm   rn   s       r   r   zLecunUniform.__init__  '    "!# 	 	
r   c                 p    t        j                  | j                        | j                  | j                  dS rp   rq   rr   s    r   r   zLecunUniform.get_config)  rs   r   rt   ru   rA   s   @r   r   r     rv   r   r   zkeras.initializers.HeNormalzkeras.initializers.he_normalc                   *     e Zd ZdZd fd	Zd Z xZS )HeNormala  He normal initializer.

    It draws samples from a truncated normal distribution centered on 0 with
    `stddev = sqrt(2 / fan_in)` where `fan_in` is the number of input units in
    the weight tensor.

    Examples:

    >>> # Standalone usage:
    >>> initializer = HeNormal()
    >>> values = initializer(shape=(2, 2))

    >>> # Usage in a Keras layer:
    >>> initializer = HeNormal()
    >>> layer = Dense(3, kernel_initializer=initializer)

    Args:
        seed: A Python integer or instance of
            `keras.backend.SeedGenerator`.
            Used to make the behavior of the initializer
            deterministic. Note that an initializer seeded with an integer
            or `None` (unseeded) will produce the same random values
            across multiple calls. To get different random values
            across multiple calls, use as seed an instance
            of `keras.backend.SeedGenerator`.

    Reference:

    - [He et al., 2015](https://arxiv.org/abs/1502.01852)
    c                 0    t         |   ddd|||       y )Nrb   rT   rG   rl   rm   rn   s       r   r   zHeNormal.__init__R  r~   r   c                 p    t        j                  | j                        | j                  | j                  dS rp   rq   rr   s    r   r   zHeNormal.get_config\  rs   r   rt   ru   rA   s   @r   r   r   1      >

r   r   zkeras.initializers.HeUniformzkeras.initializers.he_uniformc                   *     e Zd ZdZd fd	Zd Z xZS )	HeUniforma  He uniform variance scaling initializer.

    Draws samples from a uniform distribution within `[-limit, limit]`, where
    `limit = sqrt(6 / fan_in)` (`fan_in` is the number of input units in the
    weight tensor).

    Examples:

    >>> # Standalone usage:
    >>> initializer = HeUniform()
    >>> values = initializer(shape=(2, 2))

    >>> # Usage in a Keras layer:
    >>> initializer = HeUniform()
    >>> layer = Dense(3, kernel_initializer=initializer)

    Args:
        seed: A Python integer or instance of
            `keras.backend.SeedGenerator`.
            Used to make the behavior of the initializer
            deterministic. Note that an initializer seeded with an integer
            or `None` (unseeded) will produce the same random values
            across multiple calls. To get different random values
            across multiple calls, use as seed an instance
            of `keras.backend.SeedGenerator`.

    Reference:

    - [He et al., 2015](https://arxiv.org/abs/1502.01852)
    c                 0    t         |   ddd|||       y )Nrb   rT   rO   rl   rm   rn   s       r   r   zHeUniform.__init__  r   r   c                 p    t        j                  | j                        | j                  | j                  dS rp   rq   rr   s    r   r   zHeUniform.get_config  rs   r   rt   ru   rA   s   @r   r   r   d  r   r   r   c                    t        |       } |:|8d}|D ]
  }|| |   z  } d}|D ]
  }|| |   z  } t        |      t        |      fS t        |       dk  rdx}}nPt        |       dk(  r| d   x}}n:t        |       dk(  r| d   }| d   }n!d}| dd D ]  }||z  }	 | d   |z  }| d   |z  }t        |      t        |      fS )aZ  Computes the number of input and output units for a weight shape.

    Args:
        shape: Integer shape tuple.
        input_axes: Optional list of integers, axes representing input units.
        output_axes: Optional list of integers, axes representing output units.

    Returns:
        A tuple of integer scalars: `(fan_in, fan_out)`.
    N   r      )tupler   len)r/   r\   r]   rT   axisrV   receptive_field_sizedims           r   rc   rc     s    %LE+"9 	"DeDk!F	" 	#DuT{"G	#6{CL((
5zA~	Uq 8#	Uqq(  !": 	(C C' 	(r11)22v;G$$r   )zkeras.initializers.Orthogonalzkeras.initializers.orthogonalz(keras.initializers.OrthogonalInitializerc                   6     e Zd ZdZd fd	ZddZ fdZ xZS )
Orthogonala  Initializer that generates an orthogonal matrix.

    If the shape of the tensor to initialize is two-dimensional, it is
    initialized with an orthogonal matrix obtained from the QR decomposition of
    a matrix of random numbers drawn from a normal distribution. If the matrix
    has fewer rows than columns then the output will have orthogonal rows.
    Otherwise, the output will have orthogonal columns.

    If the shape of the tensor to initialize is more than two-dimensional,
    a matrix of shape `(shape[0] * ... * shape[n - 2], shape[n - 1])`
    is initialized, where `n` is the length of the shape vector.
    The matrix is subsequently reshaped to give a tensor of the desired shape.

    Examples:

    >>> # Standalone usage:
    >>> initializer = keras.initializers.Orthogonal()
    >>> values = initializer(shape=(2, 2))

    >>> # Usage in a Keras layer:
    >>> initializer = keras.initializers.Orthogonal()
    >>> layer = keras.layers.Dense(3, kernel_initializer=initializer)

    Args:
        gain: Multiplicative factor to apply to the orthogonal matrix.
        seed: A Python integer. Used to make the behavior of the initializer
            deterministic.

    Reference:

    - [Saxe et al., 2014](https://openreview.net/forum?id=_wzZwKpTDF_9C)
    c                 4    || _         t        | 	  |       y r$   )gainr)   r   )r   r   r   r+   s      r   r   zOrthogonal.__init__  s    	d#r   c                    t        |      dk  rt        d| dt        |       d      d}|d d D ]  }||z  }	 |d   }t        ||      t        ||      f}t	        j
                  || j                  |      }t        j                  |      \  }}	t        j                  |	      }
|t        j                  |
      z  }||k  rt        j                  |      }| j                  t        j                  ||      z  S )Nr   zKThe tensor to initialize must be at least two-dimensional. Received: shape=z	 of rank .r   r   )r   r0   )r   r   rd   minr   r1   r   r   qrdiagsign	transposer   reshape)r   r/   r0   num_rowsr   num_cols
flat_shapeaqrds              r   r3   zOrthogonal.__call__  s    u:>yUA7  ": 	COH	9(H-s8X/FG
 MM*499EBvvay1HHQK	SXXa[ha Ayy3;;q%000r   c                 H    t         |          }d| j                  i}i ||S )Nr   )r)   r   r   r7   s      r   r   zOrthogonal.get_config  s.    g(*$))$(+(((r   )ra   Nr   r>   rA   s   @r   r   r     s    B$16) )r   r   )NN)re   	keras.srcr   keras.src.api_exportr   keras.src.backendr   "keras.src.initializers.initializerr   keras.src.savingr   r	   r"   rD   rJ   rR   rj   rx   r|   r   r   r   rc   r   r    r   r   <module>r      s     - $ : .% %( )*/)$ /)/)d ,-2)' 2)2)j *+/)% /)/)d ,-z)' z)z)z *+/
O /
/
d )*0
? 0
0
f ()3
/ 3
3
l )*/
? /
/
d ,.LMN/
 /
 O/
d -/NOP/
 /
 Q/
d$%N D)" D)D)r   