Comments (10)
I found that the standard form (i.e. loc=0, scale=1) of the CDF and SF for the Cauchy distribution can be written as follows:
def cauchy_cdf(x):
return np.arctan2(1, -x)/np.pi
def cauchy_sf(x):
return np.arctan2(1, x)/np.pi
These give good precision over the entire domain.
The inverses can be implemented by wrapping the functions available in Boost.
I'll submit a PR soon with these updates.
from scipy.
For example, how about the following code:
def _cdf(self, x):
return np.where(
x > -2.0,
0.5 + np.arctan(x) / np.pi,
-np.arctan(1.0 / x) / np.pi
)
def _sf(self, x):
return np.where(
x < 2.0,
0.5 - np.arctan(x) / np.pi,
np.arctan(1.0 / x) / np.pi
)
def _ppf(self, q):
return -1.0 / np.tan(q * np.pi)
def _isf(self, q):
return 1.0 / np.tan(q * np.pi)
I wish numpy had integer periodic trigonometric functions such as sinpi as implemented in MATLAB.
from scipy.
Thanks @tk-yoshimura , this looks like a good suggestion. One minor thing is to use scipy's lazywhere
instead of np.where
(see for example here) for better performance. Can we interest you in a PR? We welcome expertise on precision related issues.
from scipy.
Thanks @dschmitz89, you have also been helpful with the yule-simon distribution, non-central t distribution, and zipf distribution.
I would also like to help scipy with the stable distribution I implemented in C#, so I will start by forking to understand the structure of scipy.
It may take some time to issue the PR, so if you are in a hurry, may I ask for your help?
I am better at C++,C# than python.
If _lazywhere is used, it will look like this:
Is this correct?
def _cdf(self, x):
return _lazywhere(
x > -2.0, [x],
lambda x: 0.5 + np.arctan(x) / np.pi,
f2=lambda x: -np.arctan(1.0 / x) / np.pi
)
def _sf(self, x):
return _lazywhere(
x < 2.0, [x],
lambda x: 0.5 - np.arctan(x) / np.pi,
f2=lambda x: np.arctan(1.0 / x) / np.pi
)
from scipy.
Thanks @dschmitz89, you have also been helpful with the yule-simon distribution, non-central t distribution, and zipf distribution. I would also like to help scipy with the stable distribution I implemented in C#, so I will start by forking to understand the structure of scipy.
It may take some time to issue the PR, so if you are in a hurry, may I ask for your help? I am better at C++,C# than python.
If _lazywhere is used, it will look like this: Is this correct?
def _cdf(self, x): return _lazywhere( x > -2.0, [x], lambda x: 0.5 + np.arctan(x) / np.pi, f2=lambda x: -np.arctan(1.0 / x) / np.pi ) def _sf(self, x): return _lazywhere( x < 2.0, [x], lambda x: 0.5 - np.arctan(x) / np.pi, f2=lambda x: np.arctan(1.0 / x) / np.pi )
We are not in a hurry, don't worry. Besides quick fixes we also seek to expand our contributor base :).
I think the code snippet should look like:
def _cdf(self, x):
return _lazywhere(
x > -2.0, (x, ),
lambda x: 0.5 + np.arctan(x) / np.pi,
f2=lambda x: -np.arctan(1.0 / x) / np.pi
)
def _sf(self, x):
return _lazywhere(
x < 2.0, (x, ),
lambda x: 0.5 - np.arctan(x) / np.pi,
f2=lambda x: np.arctan(1.0 / x) / np.pi
)
So you were almost correct, only (x, )
instead of [x]
is required.
For your PR please also include a test that currently fails and passes with your update in this file.
from scipy.
Just for my own curiosity, why is it better to use a tuple vs. a list here? Is it a speed thing? Is it better style?
from scipy.
I wish numpy had integer periodic trigonometric functions such as sinpi as implemented in MATLAB.
SciPy does have sindg
and related functions, taking degrees as arguments. Though under the hood they are converted to radian (after range reduction) and fed into the usual trigonometric functions.
For the functions here range reduction is not an issue since 0 <= q <= 1
. Apart from producing certain special values exactly, such as tanPi(0.25)==1
, are there other benefits of say tanPi
over tan
?
from scipy.
The problem with my code is that the following is not exactly zero.
The reason for this is that 0.5*np.pi is not exactly pi/2 in floating point numbers.
ppf(0.5)=-6.123233995736766e-17
from scipy.
The problem with my code is that the following is not exactly zero. The reason for this is that 0.5*np.pi is not exactly pi/2 in floating point numbers.
ppf(0.5)=-6.123233995736766e-17
I see. I feel it would not be a bad idea to add tanPi and related functions to SciPy, but Iām not sure if it would be attractive to the community. Maybe I should ask that in the mailing list.
Update: I just did. https://discuss.scientific-python.org/t/rfc-add-sinpi-cospi-tanpi-and-cotpi-functions-to-special/1193
from scipy.
Just for my own curiosity, why is it better to use a tuple vs. a list here? Is it a speed thing? Is it better style?
@nickodell I think at some point I had tried it in the past and it did not work. I am not 100% sure anymore though, so feel free to test a list instead of the tuple.
from scipy.
Related Issues (20)
- ENH: Octave full support HOT 4
- DOC/DEV: direct to building guide from quickstart guide
- REL: missing MacOS 10.13 Py3.12 wheel HOT 8
- BUG: `special.betaincinv` returns nan HOT 2
- BUG: Combining SciPy 1.14.1 and statsmodels 0.14.2 on OSX causes "symbol not found in flat namespace '_npy_cabs'" HOT 5
- BUG: scipy-1.14.1-cp312-cp312-macosx_12_0_arm64 wheel rejected by pip check HOT 8
- QUERY: error building from source HOT 4
- DOC/DEV: replace mambaforge with miniforge HOT 3
- BUG: Canonicalization of `scipy.sparse.csr_array` seems broken
- BUG: nearly real Hermitian matrix acquire large imaginary part in eigenvectors from `scipy.linalg.eigh` HOT 4
- DEV/MAINT: Allow unicode characters `Ā±` and `ā` in source code (for linter) HOT 3
- DOC: signal.firls: reference unavailable HOT 7
- ENH: Add support for Xi Correlation in scipy HOT 1
- DOC: `linalg.cho_{factor, solve}`: explain `overwrite_*` keywords HOT 5
- BUG: interp1d linear interpolation produces negative output on non-negative np.float32 inputs HOT 5
- MAINT, DOC: make dist pipefail issue HOT 1
- BUG: `special.pro_rad2`: incorrect results
- BUG: stats: qrvs: hppa failing many tests HOT 2
- BUG: ImportError: wrt undefined symbol: dstevr_ HOT 10
- ENH: linalg: N-D array (batch) support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scipy.