
    Αiw                       % S SK Jr  S SKJr  S SKrS SKJr  S SKJr  S SK	J
r
  \(       a  S SKJr  S SKJr  S SKrS SKJr  S S	KJr  S S
KJr  S SKJr  \\\4   rS\S'   \\R6                  \R8                  \R:                  \R<                  4   rS\S'   \\\\   \\   \R@                  \   \4   r!S\S'   \\\\   \\   \R@                  \\R6                  \R8                  4      \4   r"S\S'    " S S\
5      r#g)    )annotations)TYPE_CHECKINGN)Normal)ExpTransform)TransformedDistribution)Sequence)Union)	TypeAlias)Tensor)NestedSequencer
   _LognormalLocBase_LognormalLocNDArray_LognormalLoc_LognormalScalec                     ^  \ rS rSr% SrS\S'   S\S'   SU 4S jjr\SS j5       r\SS j5       r	SS	 jr
SS
 jrSS jrSrU =r$ )	LogNormal6   a
  The LogNormal distribution with location `loc` and `scale` parameters.

.. math::

    X \sim Normal(\mu, \sigma)

    Y = exp(X) \sim LogNormal(\mu, \sigma)


Due to LogNormal distribution is based on the transformation of Normal distribution, we call that :math:`Normal(\mu, \sigma)` is the underlying distribution of :math:`LogNormal(\mu, \sigma)`

Mathematical details

The probability density function (pdf) is

.. math::
    pdf(x; \mu, \sigma) = \frac{1}{\sigma x \sqrt{2\pi}}e^{(-\frac{(ln(x) - \mu)^2}{2\sigma^2})}

In the above equation:

* :math:`loc = \mu`: is the means of the underlying Normal distribution.
* :math:`scale = \sigma`: is the stddevs of the underlying Normal distribution.

Args:
    loc(int|float|complex|list|tuple|numpy.ndarray|Tensor): The means of the underlying Normal distribution.The data type is float32, float64, complex64 and complex128.
    scale(int|float|list|tuple|numpy.ndarray|Tensor): The stddevs of the underlying Normal distribution.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> from paddle.distribution import LogNormal

        >>> # Define a single scalar LogNormal distribution.
        >>> dist = LogNormal(loc=0., scale=3.)
        >>> # Define a batch of two scalar valued LogNormals.
        >>> # The underlying Normal of first has mean 1 and standard deviation 11, the underlying Normal of second 2 and 22.
        >>> dist = LogNormal(loc=[1., 2.], scale=[11., 22.])
        >>> # Get 3 samples, returning a 3 x 2 tensor.
        >>> dist.sample((3, ))

        >>> # Define a batch of two scalar valued LogNormals.
        >>> # Their underlying Normal have mean 1, but different standard deviations.
        >>> dist = LogNormal(loc=1., scale=[11., 22.])

        >>> # Complete example
        >>> value_tensor = paddle.to_tensor([0.8], dtype="float32")

        >>> lognormal_a = LogNormal([0.], [1.])
        >>> lognormal_b = LogNormal([0.5], [2.])
        >>> sample = lognormal_a.sample((2, ))
        >>> # a random tensor created by lognormal distribution with shape: [2, 1]
        >>> entropy = lognormal_a.entropy()
        >>> print(entropy)
        Tensor(shape=[1], dtype=float32, place=Place(cpu), stop_gradient=True,
            [1.41893852])
        >>> lp = lognormal_a.log_prob(value_tensor)
        >>> print(lp)
        Tensor(shape=[1], dtype=float32, place=Place(cpu), stop_gradient=True,
            [-0.72069150])
        >>> p = lognormal_a.probs(value_tensor)
        >>> print(p)
        Tensor(shape=[1], dtype=float32, place=Place(cpu), stop_gradient=True,
            [0.48641577])
        >>> kl = lognormal_a.kl_divergence(lognormal_b)
        >>> print(kl)
        Tensor(shape=[1], dtype=float32, place=Place(cpu), stop_gradient=True,
            [0.34939718])
r   locscalec                   > [        XS9U l        U R                  R                  U l        U R                  R                  U l        [        TU ]  U R                  [        5       /5        g )N)r   r   )r   _baser   r   super__init__r   )selfr   r   	__class__s      ]/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/distribution/lognormal.pyr   LogNormal.__init__   sG    1
::>>ZZ%%
ln%56    c                    [         R                  " U R                  R                  U R                  R                  S-  -   5      $ )zBMean of lognormal distribution.

Returns:
    Tensor: mean value.
   )paddleexpr   meanvariancer   s    r   r#   LogNormal.mean   s/     zz$**//DJJ,?,?!,CCDDr   c                    [         R                  " U R                  R                  5      [         R                  " SU R                  R
                  -  U R                  R                  -   5      -  $ )zJVariance of lognormal distribution.

Returns:
    Tensor: variance value.
r    )r!   expm1r   r$   r"   r#   r%   s    r   r$   LogNormal.variance   sN     ||DJJ//06::

$**"5"554
 
 	
r   c                d    U R                   R                  5       U R                   R                  -   $ )a^  Shannon entropy in nats.

The entropy is

.. math::

    entropy(\sigma) = 0.5 \log (2 \pi e \sigma^2) + \mu

In the above equation:

* :math:`loc = \mu`: is the mean of the underlying Normal distribution.
* :math:`scale = \sigma`: is the stddevs of the underlying Normal distribution.

Returns:
  Tensor: Shannon entropy of lognormal distribution.

)r   entropyr#   r%   s    r   r+   LogNormal.entropy   s$    $ zz!!#djjoo55r   c                L    [         R                  " U R                  U5      5      $ )zProbability density/mass function.

Args:
  value (Tensor): The input tensor.

Returns:
  Tensor: probability.The data type is same with :attr:`value` .

)r!   r"   log_prob)r   values     r   probsLogNormal.probs   s     zz$--.//r   c                L    U R                   R                  UR                   5      $ )ar  The KL-divergence between two lognormal distributions.

The probability density function (pdf) is

.. math::

    KL\_divergence(\mu_0, \sigma_0; \mu_1, \sigma_1) = 0.5 (ratio^2 + (\frac{diff}{\sigma_1})^2 - 1 - 2 \ln {ratio})

.. math::

    ratio = \frac{\sigma_0}{\sigma_1}

.. math::

    diff = \mu_1 - \mu_0

In the above equation:

* :math:`loc = \mu_0`: is the means of current underlying Normal distribution.
* :math:`scale = \sigma_0`: is the stddevs of current underlying Normal distribution.
* :math:`loc = \mu_1`: is the means of other underlying Normal distribution.
* :math:`scale = \sigma_1`: is the stddevs of other underlying Normal distribution.
* :math:`ratio`: is the ratio of scales.
* :math:`diff`: is the difference between means.

Args:
    other (LogNormal): instance of LogNormal.

Returns:
    Tensor: kl-divergence between two lognormal distributions.

)r   kl_divergence)r   others     r   r3   LogNormal.kl_divergence   s    B zz''44r   )r   r   r   )r   r   r   r   returnNone)r6   r   )r/   r   r6   r   )r4   r   r6   r   )__name__
__module____qualname____firstlineno____doc____annotations__r   propertyr#   r$   r+   r0   r3   __static_attributes____classcell__)r   s   @r   r   r   6   sY    DL 
KM7 E E 
 
6(
0!5 !5r   r   )$
__future__r   typingr   r!   paddle.distribution.normalr   paddle.distribution.transformr   ,paddle.distribution.transformed_distributionr   collections.abcr   r	   numpynpnumpy.typingnpttyping_extensionsr
   r   paddle._typingr   floatcomplexr   r=   float32float64	complex64
complex128r   NDArrayr   r   r    r   r   <module>rU      s
   #    - 6 P(+-#(#8y8&+


BJJbmm;')   %"#()()		 M9  "'uE"**bjj012		"OY e5' e5r   