We are releasing a new version of TensorLy, long in the making, with a long list of major improvements, new features, better documentation, bug fixes and overall quality of life improvements!
New features
Transparent support for einsum
There are two main ways to implement tensor algebraic methods:
- Perhaps the most common, using existing matrix based algebraic methods, which typically involves unfolding the tensor (reshaping the tensor into a matrix and permuting its dimensions)
- Directly leverage tensor contraction, e.g. through an ensue interface. This implies that the einsum actually performs tensor contraction.
We improved the tenalg backend, you can transparently dispatch all tensor algebraic operations to the backend's einsum:
import tensorly as tl
# Tensor algebra
from tensorly import tenalg
# Dispatch all operations to einsum
tenalg.set_backend('einsum')
Now all tenalg functions will call einsum under the hood!
Opt-Einsum support
In addition, for each einsum call, you can now use opt-einsum to compute a (near) optimal contraction path and cache it with just one call!
# New opt-einsum plugin
from tensorly.plugins import use_opt_einsum
# Transparently compute and cache contraction path using opt-einsum
use_opt_einsum('optimal')
Switch back to the original backend's einsum:
# New opt-einsum plugin
from tensorly.plugins import use_default_einsum
use_default_einsum()
Efficient contraction on GPU with cuQuantum
If you want to accelerate your computation, you probably want to use the GPU.
TensorLy has been supporting GPU transparently for a while, through its MXNet, CuPy, TensorFlow, PyTorch and more recently, JAX backends.
Now you can also get efficient tensor contractions on GPU using NVIDIA's cuQuantum library!
Now any function to the `tenalg` module
# New opt-einsum plugin
from tensorly.plugins import use_cuquantum
# Transparently compute and cache contraction path using opt-einsum
use_cuquantum('optimal')
# Create a new tensor on GPU
tensor = tl.randn((32, 256, 256, 3), device='cuda')
# Decompose it with CP, keep 5% of the parameters
parafac(tensor, rank=0.05, init='random', n_iter_max=10)
Similarity measure
We now provide CorrIndex, a correlation invariant index
CP-partial least square regression
This release brings a new multi-linear partial least squares regression, as first introduce by Rasmus Bro, exposed in a convenient scikit-learn-like class, CP_PLSR
Tensor-Train via orthogonal iteration
We have a new tensor decomposition tensor_train_OI
class for tensor-train decomposition via orthogonal iteration.
Unified SVD interface
We now have a unified interface for Singular Value Decomposition svd_interface
.
It has support for resolving sign indeterminacy, returning a non-negative output, missing values (masked input), and various computation methods, all in one, neat interface!
New datasets
TensorLy now includes real-world datasets well-suited for tensor analysis, that you can now directly load/download in a ready to use form!
COVID-19 Serology Dataset
Systems serology is a new technology that examines the antibodies from a patient’s serum, aiming to comprehensively profile the interactions between the antibodies and Fc receptors alongside other types of immunological and demographic data. Here, we will apply CP decomposition to a COVID-19 system serology dataset. In this dataset, serum antibodies of 438 samples collected from COVID-19 patients were systematically profiled by their binding behavior to SARS-CoV-2 (the virus that causes COVID-19) antigens and Fc receptors activities. The data is formatted in a three-mode tensor of samples, antigens, and receptors Samples are labeled by the status of the patients.
IL2
IL-2 signals through the Jak/STAT pathway and transmits a signal into immune cells by phosphorylating STAT5 (pSTAT5). When phosphorylated, STAT5 will cause various immune cell types to proliferate, and depending on whether regulatory (regulatory T cells, or Tregs) or effector cells (helper T cells, natural killer cells, and cytotoxic T cells, or Thelpers, NKs, and CD8+ cells) respond, IL-2 signaling can result in immunosuppression or immunostimulation respectively. Thus, when designing a drug meant to repress the immune system, potentially for the treatment of autoimmune diseases, IL-2 which primarily enacts a response in Tregs is desirable. Conversely, when designing a drug that is meant to stimulate the immune system, potentially for the treatment of cancer, IL-2 which primarily enacts a response in effector cells is desirable. In order to achieve either signaling bias, IL-2 variants with altered affinity for its various receptors (IL2Rα or IL2Rβ) have been designed. Furthermore IL-2 variants with multiple binding domains have been designed as multivalent IL-2 may act as a more effective therapeutic.
The data contains the responses of 8 different cell types to 13 different IL-2 mutants, at 4 different timepoints, at 12 standardized IL-2 concentrations. It is formatted as a 4th order tensor of shape (13 x 4 x 12 x 8), with dimensions representing IL-2 mutant, stimulation time, dose, and cell type respectively.
Kinetic
A Kinetic fluorescence dataset, well suited for Parafac and multi-way partial least squares regression (N-PLS).
The data is represented as a four-way data set with the modes: Concentration, excitation wavelength, emission wavelength and time.
Indian Pines
Airborne Visible / Infrared Imaging Spectrometer (AVIRIS) hyperspectral sensor data. It consists of 145 times 145 pixels and 220 spectral reflectance bands in the wavelength range 0.4–2.5 10^(-6) meters.
Black linting
We now automatically check for code formatting and the CI tests the code style against the Black styleguides.
List of merged pull requests in this release
In addition to these big features, this release also comes with a whole lot of improvements, better documentation and bug fixes!
Non-exhaustive list of changes:
- solves hals rec_error0 issue and does some pep improvements by @caglayantuna in #339
- Copy cptensor by @caglayantuna in #324
- Normalization by @caglayantuna in #281
- Add random_state for non negative PARAFAC HALS by @MarieRoald in #344
- fix tensorflow dtype issue by @caglayantuna in #340
- nn_tucker hals class, doc, api improvements by @caglayantuna in #345
- Constrained parafac example and improved docstrings by @caglayantuna in #347
- IL-2 stimulation dataset by @borcuttjahns in #348
- Adds matricize function by @JeanKossaifi in #366
- copy tucker tensor by @caglayantuna in #367
- simplex projection issue by @caglayantuna in #363
- Make
tl.shape
return tuple for PyTorch backend by @MarieRoald in #357 - Add
keepdims
totl.sum
with the PyTorch backend by @MarieRoald in #356 - Fix bug with
tl.clip
for the PyTorch and TensorFlow backends by @MarieRoald in #355 - Import COVID-19 systems serology example dataset by @cyrillustan in #359
- Add Covid example notebook by @cyrillustan in #361
- Adds exp to the backend by @JeanKossaifi in #377
- Adds digamma fun to backend by @JeanKossaifi in #378
- Adds log function to tensorly by @caglayantuna in #381
- Clip function to sparse backend with a_max=None by @caglayantuna in #379
- CorrIndex implementation for comparing decomposition outputs by @hmbaghdassarian in #364
- Adds pad_tt_rank by @JeanKossaifi in #387
- fix normalized sparsity test by @caglayantuna in #385
- User defined indices list for sample kr by @caglayantuna in #382
- Drop nosetests by @yan12125 in #388
- default axis for tensorflow concatenate by @caglayantuna in #389
- Add exp and log to top-level backend exports by @j6k4m8 in #393
- Add trig functions and constants by @j6k4m8 in #398
- Add black code style and linting to CI by @j6k4m8 in #400
- JAX backend - v > 0.3.0 by @JeanKossaifi in #397
- Permute cp factors by @caglayantuna in #380
- Return errors for tucker by @caglayantuna in #396
- Constrained cp class by @caglayantuna in #390
- Added IL2 PARAFAC Analysis Example Script by @borcuttjahns in #362
- Update applications examples by @borcuttjahns in #405
- Tensor permutation fix for Jax by @aarmey in #406
- 2 new dataset by @caglayantuna in #408
- Permute factors api by @caglayantuna in #404
- removed numpy copy bug by @Mahmood-Hussain in #415
- Test for reproducibility of CP by @aarmey in #371
- reorder modes and ranks in partial_tucker by @caglayantuna in #418
- Remove descending argument in sorting functions by @aarmey in #419
- Moves tf to the numpy interface by @aarmey in #407
- change decimal for randomized_svd by @caglayantuna in #421
- Add assert allclose and tests for test utils by @MarieRoald in #420
- Make parafac() robust to complex tensors by @maximeguillaud in #298
- Apply black-style formatting to repository by @j6k4m8 in #401
- Better initialization of CMTF ALS by @aarmey in #424
- Fix mxnet testing by @aarmey in #425
- Add testing for complex values in CP by @aarmey in #423
- Move SVD to a common frontend interface by @aarmey in #429
- Warning when fixing last mode by @caglayantuna in #437
- Doc fix typo in tensor_basics.rst by @ssnio in #445
- Tensor PLSR by @aarmey in #435
- Fix the documentation build by @aarmey in #450
- Callback interface for CP decomposition by @aarmey in #417
- Adds svd interface to TT and TR, as well as TensorRing class by @JeanKossaifi in #453
- TT improvements + doc by @JeanKossaifi in #454
- Raise error for users trying to use tl.partial_svd. by @JeanKossaifi in #455
- Tt rank errors by @JeanKossaifi in #456
- FIX cp_norm: preserve context by @JeanKossaifi in #461
- Finished f-string formatting by @aarmey in #464
- Temporarily skip indian_pines test by @JeanKossaifi in #466
- Adds opt-einsum path caching plugin by @JeanKossaifi in #462
- Use a secure link to tensorly.org by @johnthagen in #467
- Add TTOI functions by @Lili-Zheng-stat in #411
- Decorator for backend specific implementations by @MarieRoald in #434
- Remove in-place projection operations in PARAFAC2 by @aarmey in #474
- Adding indian pines locally and updating loader by @cohenjer in #472
Credit
This release is only possible thanks to a lot of voluntary work by the whole TensorLy team that work hard to maintain and improve the library! Thanks in particular to the core devs
New Contributors
Big thanks to all the new contributors and welcome to the TensorLy community!
- @borcuttjahns made their first contribution in #348
- @cyrillustan made their first contribution in #359
- @hmbaghdassarian made their first contribution in #364
- @yan12125 made their first contribution in #388
- @j6k4m8 made their first contribution in #393
- @Mahmood-Hussain made their first contribution in #415
- @maximeguillaud made their first contribution in #298
- @ssnio made their first contribution in #445
- @johnthagen made their first contribution in #467
- @Lili-Zheng-stat made their first contribution in #411
Full Changelog: 0.7.0...0.8.0