Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sandialabs/pyttb
Python Tensor Toolbox
https://github.com/sandialabs/pyttb
cp-decomposition data-science python scr-2671 snl-data-analysis tensors tucker-decomposition
Last synced: 5 days ago
JSON representation
Python Tensor Toolbox
- Host: GitHub
- URL: https://github.com/sandialabs/pyttb
- Owner: sandialabs
- License: bsd-2-clause
- Created: 2022-05-10T03:21:22.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-02-05T06:01:01.000Z (14 days ago)
- Last Synced: 2025-02-06T03:11:16.136Z (13 days ago)
- Topics: cp-decomposition, data-science, python, scr-2671, snl-data-analysis, tensors, tucker-decomposition
- Language: Python
- Homepage: https://pyttb.readthedocs.io
- Size: 1.04 MB
- Stars: 29
- Watchers: 3
- Forks: 14
- Open Issues: 25
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Citation: CITATION.bib
Awesome Lists containing this project
README
```
Copyright 2024 National Technology & Engineering Solutions of Sandia,
LLC (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the
U.S. Government retains certain rights in this software.
```
[](https://github.com/sandialabs/pyttb/actions/workflows/regression-tests.yml)
[](https://coveralls.io/github/sandialabs/pyttb)
[](https://pypi.org/project/pyttb/)
[](https://pypi.python.org/pypi/pyttb)
[](https://github.com/astral-sh/ruff)
[](https://github.com/psf/black)# pyttb: Python Tensor Toolbox
Welcome to `pyttb`, a refactor of the
[Tensor Toolbox for MATLAB](https://www.tensortoolbox.org) in Python.This package contains data classes and methods for manipulating dense,
sparse, and structured tensors, along with algorithms for computing
low-rank tensor decompositions:- Data Classes:
[`tensor`](https://pyttb.readthedocs.io/en/stable/tensor.html "dense tensors"),
[`sptensor`](https://pyttb.readthedocs.io/en/stable/sptensor.html "sparse tensors"),
[`ktensor`](https://pyttb.readthedocs.io/en/stable/ktensor.html "Kruskal tensors"),
[`ttensor`](https://pyttb.readthedocs.io/en/stable/ttensor.html "Tucker tensors"),
[`tenmat`](https://pyttb.readthedocs.io/en/stable/tenmat.html "matricized dense tensors"),
[`sptenmat`](https://pyttb.readthedocs.io/en/stable/sptenmat.html "matricized sparse tensors"),
[`sumtensor`](https://pyttb.readthedocs.io/en/stable/sumtensor.html "implicit sum of tensors")
- Algorithms:
[`cp_als`](https://pyttb.readthedocs.io/en/stable/cpals.html "CP decomposition via Alternating Least Squares"),
[`cp_apr`](https://pyttb.readthedocs.io/en/stable/cpapr.html "CP decomposition via Alternating Poisson Regression"),
[`gcp_opt`](https://pyttb.readthedocs.io/en/stable/gcpopt.html "Generalized CP decomposition"),
[`hosvd`](https://pyttb.readthedocs.io/en/stable/hosvd.html "Tucker decomposition via Higher Order Singular Value Decomposition"),
[`tucker_als`](https://pyttb.readthedocs.io/en/stable/tuckerals.html "Tucker decomposition via Alternating Least Squares")## Quick Start
### Installation
```commandline
python3 -m pip install pyttb
```### Example
```python
>>> import pyttb as ttb
>>> X = ttb.tenrand((2,2,2))
>>> type(X)>>> M = ttb.cp_als(X, rank=1)
CP_ALS:
Iter 0: f = 7.367245e-01 f-delta = 7.4e-01
Iter 1: f = 7.503069e-01 f-delta = 1.4e-02
Iter 2: f = 7.508240e-01 f-delta = 5.2e-04
Iter 3: f = 7.508253e-01 f-delta = 1.3e-06
Final f = 7.508253e-01
```### Memory layout
For historical reasons we use Fortran memory layouts, where numpy by default uses C.
This is relevant for indexing. In the future we hope to extend support for both.
```python
>>> import numpy as np
>>> c_order = np.arange(8).reshape((2,2,2))
>>> f_order = np.arange(8).reshape((2,2,2), order="F")
>>> print(c_order[0,1,1])
3
>>> print(f_order[0,1,1])
6
```### Getting Help
- [Documentation](https://pyttb.readthedocs.io)
- [Tutorials](https://pyttb.readthedocs.io/en/stable/tutorials.html)
- [Info for users coming from MATLAB](https://pyttb.readthedocs.io/en/stable/for_matlab_users.html)
- Learn about tensor decompositions:
[tensor paper](https://doi.org/10.1137/07070111X "Tensor Decompositions and Applications by Tamara G. Kolda, Brett W. Bader"),
[tensor book](https://www.mathsci.ai/post/tensor-textbook/ "Tensor Decompositions for Data Science by Grey Balard and Tamara G. Kolda")### Contributing
- [Report a bug](https://github.com/sandialabs/pyttb/issues/new)
- [Guide for contributors](CONTRIBUTING.md)
- [List of contributors](CONTRIBUTORS.md)### Citing pyttb in your work
If you use pyttb in your work, please cite it using the citation info [here](CITATION.bib).