Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added log-cauchy distribution #20632

Merged
merged 7 commits into from Dec 30, 2020
Merged

added log-cauchy distribution #20632

merged 7 commits into from Dec 30, 2020

Conversation

mayankray2020
Copy link
Contributor

@mayankray2020 mayankray2020 commented Dec 20, 2020

  • stats
    • implemented LogCauchy Distribution

@sympy-bot
Copy link

sympy-bot commented Dec 20, 2020

Hi, I am the SymPy bot (v161). I'm here to help you write a release notes entry. Please read the guide on how to write release notes.

Your release notes are in good order.

Here is what the release notes will look like:

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.8.

Click here to see the pull request description that was parsed.
<!-- BEGIN RELEASE NOTES -->
* stats
  * implemented LogCauchy Distribution

<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

Comment on lines 2318 to 2350
r"""
Create a continuous random variable with a Log-Cauchy distribution.
The density of the Log-Cauchy distribution is given by
.. math::
f(x) := \frac{1}{\pi x} \frac{\gamma}{(log(x)-\x0^2) + \gamma^2}
Parameters
==========
x0 : Real number, the location
gamma : Real number, `\gamma > 0`, a scale
Returns
=======
RandomSymbol
Examples
========
>>> from sympy.stats import LogCauchy, density, cdf
>>> from sympy import Symbol, S

>>> x0 = 2
>>> gamma = S.One / 5
>>> z = Symbol("z")

>>> X = LogCauchy("x", x0, gamma)

>>> density(X)(z)
1/(5*pi*z*((log(z) - 2)**2 + 1/25))

>>> cdf(X)(z)
atan(5*log(z) - 10)/pi + 1/2

References
==========
.. [1] https://en.wikipedia.org/wiki/Log-Cauchy_distribution
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
r"""
Create a continuous random variable with a Log-Cauchy distribution.
The density of the Log-Cauchy distribution is given by
.. math::
f(x) := \frac{1}{\pi x} \frac{\gamma}{(log(x)-\x0^2) + \gamma^2}
Parameters
==========
x0 : Real number, the location
gamma : Real number, `\gamma > 0`, a scale
Returns
=======
RandomSymbol
Examples
========
>>> from sympy.stats import LogCauchy, density, cdf
>>> from sympy import Symbol, S
>>> x0 = 2
>>> gamma = S.One / 5
>>> z = Symbol("z")
>>> X = LogCauchy("x", x0, gamma)
>>> density(X)(z)
1/(5*pi*z*((log(z) - 2)**2 + 1/25))
>>> cdf(X)(z)
atan(5*log(z) - 10)/pi + 1/2
References
==========
.. [1] https://en.wikipedia.org/wiki/Log-Cauchy_distribution
"""
r"""
Create a continuous random variable with a Log-Cauchy distribution.
The density of the Log-Cauchy distribution is given by
.. math::
f(x) := \frac{1}{\pi x} \frac{\gamma}{(log(x)-\x0^2) + \gamma^2}
Parameters
==========
x0 : Real number, the location
gamma : Real number, `\gamma > 0`, a scale
Returns
=======
RandomSymbol
Examples
========
>>> from sympy.stats import LogCauchy, density, cdf
>>> from sympy import Symbol, S
>>> x0 = 2
>>> gamma = S.One / 5
>>> z = Symbol("z")
>>> X = LogCauchy("x", x0, gamma)
>>> density(X)(z)
1/(5*pi*z*((log(z) - 2)**2 + 1/25))
>>> cdf(X)(z)
atan(5*log(z) - 10)/pi + 1/2
References
=========
.. [1] https://en.wikipedia.org/wiki/Log-Cauchy_distribution
"""

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 851 to 852
assert density(X)(2) - 1/(10*pi*(1/25 + (-2 + log(2))**2)) < 0.001
assert cdf(X)(2) - (-atan(10 - 5*log(2))/pi + 1/2) < 0.001
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add symbolic tests instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added symbolic tests

sympy/stats/crv_types.py Outdated Show resolved Hide resolved
Comment on lines 2361 to 2362
return rv(name, LogCauchyDistribution, (x0, gamma))
#-------------------------------------------------------------------------------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return rv(name, LogCauchyDistribution, (x0, gamma))
#-------------------------------------------------------------------------------
return rv(name, LogCauchyDistribution, (x0, gamma))
#-------------------------------------------------------------------------------

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

class LogCauchyDistribution(SingleContinuousDistribution):
_argnames = ('x0', 'gamma')

set = Interval(0, oo)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
set = Interval(0, oo)
set = Interval.open(0, oo)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

sympy/stats/crv_types.py Outdated Show resolved Hide resolved
@mayankray2020
Copy link
Contributor Author

@czgdp1807 please review this

sympy/stats/crv_types.py Outdated Show resolved Hide resolved

@staticmethod
def check(mu, sigma):
_value_check(sigma > 0, "Scale parameter Gamma must be positive.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_value_check(sigma > 0, "Scale parameter Gamma must be positive.")
_value_check((sigma > 0) != False, "Scale parameter Gamma must be positive.")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done @czgdp1807

@czgdp1807
Copy link
Member

LGTM. Will merge tomorrow if no objections raised.

@czgdp1807 czgdp1807 merged commit b0b16e1 into sympy:master Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants