Is there a Python equivalent to Matlab's function copulafit? Not necessarily in its entirety, but at least the Gaussian and t-copula and their negative log-likelihoods would be fine.
I'm aware of a few copula packages, but not sure which offers the highest resemblance to Matlab's code, shown below. I would actually prefer an authoritative implementation, like how numpy and scipy are rigorously high-quality. Better yet, a direct python translation of copulafit, or parts of.
Related
I've tried to write functions to calculate special functions (e.g. exponential, gamma, erf, etc), but to do the sum or product operations, I used while-loop with 10k turns. This is very time-consuming.
Then, I realized that scipy.special.gamma() function is significantly faster than my while-loop and I wanted to see and study the implementation/algorithm of the gamma function, but I couldn't find the source codes on the internet.
Is there a way to see the source codes of Scipy?
SciPy's source code is hosted on GitHub here: https://github.com/scipy/scipy
For floating-point arguments, SciPy uses CEPHES's implementation of gamma: https://github.com/scipy/scipy/blob/main/scipy/special/cephes/gamma.c
For complex arguments, SciPy uses a Cython implementation: https://github.com/scipy/scipy/blob/main/scipy/special/_loggamma.pxd
I am looking for a Pythonic realization of Expokit, which is a software package that provides matrix exponential routines for small dense or very large sparse matrices, real or complex, i.e. it finds
w(t) = exp(t*A)*v
This package had been realized in Fortran and Matlab and can be found here https://www.maths.uq.edu.au/expokit/
I have found a python wrapper expokitpy
https://github.com/weinbe58/expokitpy and a Krylov subspace methods package KryPy https://github.com/andrenarchy/krypy. Both seem to be relevant, however neither of them goes with good enough documentation (for me) to do time-evolution.
Does somebody have a working solution with the packages mentioned above or similar?
In case this is still useful to someone, it looks like there was an effort to incorporate expokit within scipy which has now stalled and is looking for somebody to finish. Though here are some instructions to compile with Fortran and then run via Python, with good results.
It seems also to have been adopted by slepc4py, which is then used by quimb, which seems useful if you need it for quantum information (or just use its expm and expm_multiply methods).
Does anyone know if there is a Python-based procedure to decompose time series utilizing STL (Seasonal-Trend-Loess) method?
I saw references to a wrapper program to call the stl function
in R, but I found that to be unstable and cumbersome from the environment set-up perspective (Python and R together). Also, link was 4 years old.
Can someone point out something more recent (e.g. sklearn, spicy, etc.)?
I haven't tried STLDecompose but I took a peek at it and I believe it uses a general purpose loess smoother. This is hard to do right and tends to be inefficient. See the defunct STL-Java repo.
The pyloess package provides a python wrapper to the same underlying Fortran that is used by the original R version. You definitely don't need to go through a bridge to R to get this same functionality! This package is not actively maintained and I've occasionally had trouble getting it to build on some platforms (thus the fork here). But once built, it does work and is the fastest one you're likely to find. I've been tempted to modify it to include some new features, but just can't bring myself to modify the Fortran (which is pre-processed RATFOR - very assembly-language like Fortran, and I can't find a RATFOR preprocessor anywhere).
I wrote a native Java implementation, stl-decomp-4j, that can be called from python using the pyjnius package. This started as a direct port of the original Fortran, refactored to a more modern programming style. I then extended it to allow quadratic loess interpolation and to support post-decomposition smoothing of the seasonal component, features that are described in the original paper but that were not put into the Fortran/R implementation. (They apparently are in the S-plus implementation, but few of us have access to that.) The key to making this efficient is that the loess smoothing simplifies when the points are equidistant and the point-by-point smoothing is done by simply modifying the weights that one is using to do the interpolation.
The stl-decomp-4j examples include one Jupyter notebook demonstrating how to call this package from python. I should probably formalize that as a python package but haven't had time. Quite willing to accept pull requests. ;-)
I'd love to see a direct port of this approach to python/numpy. Another thing on my "if I had some spare time" list.
Here you can find an example of Seasonal-Trend decomposition using LOESS (STL), from statsmodels.
Basicaly it works this way:
from statsmodels.tsa.seasonal import STL
stl = STL(TimeSeries, seasonal=13)
res = stl.fit()
fig = res.plot()
There is indeed:
https://github.com/jrmontag/STLDecompose
In the repo you will find a jupyter notebook for usage of the package.
RSTL is a Python port of R's STL: https://github.com/ericist/rstl. It works pretty well except it is 3~5 times slower than R's STL according to the author.
If you just want to get lowess trend line, you can just use Statsmodels' lowess function
https://www.statsmodels.org/dev/generated/statsmodels.nonparametric.smoothers_lowess.lowess.html.
Are there functions in python that will fill out missing values in a matrix for you, by using collaborative filtering (ex. alternating minimization algorithm, etc). Or does one need to implement such functions from scratch?
[EDIT]: Although this isn't a matrix-completion example, but just to illustrate a similar situation, I know there is an svd() function in Matlab that takes a matrix as input and automatically outputs the singular value decomposition (svd) of it. I'm looking for something like that in Python, hopefully a built-in function, but even a good library out there would be great.
Check out numpy's linalg library to find a python SVD implementation
There is a library fancyimpute. Also, sklearn NMF
I am currently trying to move from Matlab to Python and succeeded in several aspects. However, one function in Matlab's Signal Processing Toolbox that I use quite regularly is the impinvar function to calculate a digital filter from its analogue version.
In Scipy.signal I only found the bilinear function to do something similar. But, in contrast to the Matlab bilinear function, it does not take an optional argument to do some pre-warping of the frequencies. I did not find any impinvar (impulse invariance) function in Scipy.
Before I now start to code it myself I'd like to ask whether there is something that I simply overlooked? Thanks.
There is a Python translation of the Octave impinvar function in the PyDynamic package which should be equivalent to the Matlab version.