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
Conversation
mayankray2020
commented
Dec 20, 2020
•
edited
edited
- stats
- implemented LogCauchy Distribution
✅ 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.
Update The release notes on the wiki have been updated. |
sympy/stats/crv_types.py
Outdated
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 | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 | |
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
return rv(name, LogCauchyDistribution, (x0, gamma)) | ||
#------------------------------------------------------------------------------- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return rv(name, LogCauchyDistribution, (x0, gamma)) | |
#------------------------------------------------------------------------------- | |
return rv(name, LogCauchyDistribution, (x0, gamma)) | |
#------------------------------------------------------------------------------- |
There was a problem hiding this comment.
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
class LogCauchyDistribution(SingleContinuousDistribution): | ||
_argnames = ('x0', 'gamma') | ||
|
||
set = Interval(0, oo) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set = Interval(0, oo) | |
set = Interval.open(0, oo) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@czgdp1807 please review this |
sympy/stats/crv_types.py
Outdated
|
||
@staticmethod | ||
def check(mu, sigma): | ||
_value_check(sigma > 0, "Scale parameter Gamma must be positive.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_value_check(sigma > 0, "Scale parameter Gamma must be positive.") | |
_value_check((sigma > 0) != False, "Scale parameter Gamma must be positive.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done @czgdp1807
LGTM. Will merge tomorrow if no objections raised. |