tensorpack

tensorpack is a collection of tensor decomposition methods from the Meyer lab, built on TensorLy and xarray. It targets multi-dimensional biological data sets that are often incomplete or come paired with additional matrices.

Installation

uv add git+https://github.com/meyer-lab/tensorpack.git@main

Which method should I use?

  • tensorpack.cmtf.perform_CP() – CP decomposition of one tensor; NaN entries are treated as missing.

  • tensorpack.cmtf.perform_CMTF() – a tensor and a matrix that share their first mode, factored jointly.

  • tensorpack.coupled.CoupledTensor – any number of arrays sharing named dimensions in an xarray.Dataset, optionally non-negative.

  • tensorpack.decomposition.Decomposition – scan component counts and compute R2X and Q2X.

Example

import numpy as np
from tensorpack import perform_CP

rng = np.random.default_rng(0)
tensor = rng.gamma(2, 2, (10, 20, 25))
tensor[rng.random(tensor.shape) < 0.2] = np.nan

cp = perform_CP(tensor, r=3)
print(cp.R2X)

Contents: