Skip to main content

Package to visualise component-based decomposition models such as PCA and PARAFAC

Project description

Tests Coverage Documentation Status https://img.shields.io/badge/code%20style-black-000000.svg

TLViz is a Python package for visualising component-based decomposition models like PARAFAC and PCA.

Documentation

The documentation is available on the TensorLy website and includes

Dependencies

TLViz supports Python 3.7 or above (it may also work with Python 3.6, though that is not officially supported).

Installation requires matplotlib, numpy, pandas, scipy, statsmodels and xarray.

Installation

To install the latest stable release of TLViz and its dependencies, run:

pip install tlviz

There is also functionality to create improved QQ-plots with Pingoiun. However, this is disabled by default due to the restrictive GPL lisence. To enable this possibility, you must manually install Pingoiun.

To install the latest development version of TLViz, you can either clone this repo or run

pip install git+https://github.com/marieroald/tlviz.git

Example

import tlviz
import matplotlib.pyplot as plt
from tensorly.decomposition import parafac

def fit_parafac(dataset, num_components, num_inits):
    model_candidates = [
        parafac(dataset.data, num_components, init="random", random_state=i)
        for i in range(num_inits)
    ]
    model = tlviz.multimodel_evaluation.get_model_with_lowest_error(
        model_candidates, dataset
    )
    return tlviz.postprocessing.postprocess(model, dataset)

data = tlviz.data.load_aminoacids()
cp_tensor = fit_parafac(data, 3, num_inits=3)
tlviz.visualisation.components_plot(cp_tensor)
plt.show()
Loading Aminoacids dataset from:
Bro, R, PARAFAC: Tutorial and applications, Chemometrics and Intelligent Laboratory Systems, 1997, 38, 149-171
An example figure showing the component vectors of a three component PARAFAC model fitted to a fluoresence spectroscopy dataset.

This example uses TensorLy to fit five three-component PARAFAC models to the data. Then it uses TLViz to:

  1. Select the model that gave the lowest reconstruction error,

  2. normalise the component vectors, storing their magnitude in a separate weight-vector,

  3. permute the components in descending weight (i.e. signal strength) order,

  4. flip the components so they point in a logical direction compared to the data,

  5. convert the factor matrices into Pandas DataFrames with logical indices,

  6. and plot the components using matplotlib.

All these steps are described in the API documentation with references to the literature.

Testing

The test suite requires an additional set of dependencies. To install these, run

pip install tlviz[test]

or

pip install -e .[test]

inside your local copy of the TLViz repository.

The tests can be run by calling pytest with no additional arguments. All doctests are ran by default and a coverage summary will be printed on the screen. To generate a coverage report, run coverage html.

Contributing

Contributions are welcome to TLViz, see the contribution guidelines.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

TLViz-0.1.1.tar.gz (632.4 kB view details)

Uploaded Source

Built Distribution

TLViz-0.1.1-py2.py3-none-any.whl (701.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file TLViz-0.1.1.tar.gz.

File metadata

  • Download URL: TLViz-0.1.1.tar.gz
  • Upload date:
  • Size: 632.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.13

File hashes

Hashes for TLViz-0.1.1.tar.gz
Algorithm Hash digest
SHA256 72835c38fedf02290bf0b7540def77a756a2b0389a91373365610e7cd985a93b
MD5 dcdb60ef6c15f2c52d6e9e390c9f3df6
BLAKE2b-256 cf7f75eae7aa41373373ba64a28fb89a89761f66fb12f7e7c72cb98d6be0085a

See more details on using hashes here.

File details

Details for the file TLViz-0.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: TLViz-0.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 701.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.13

File hashes

Hashes for TLViz-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1d221a1e47a4227dcb34c2f934c9dfe39dc840429607d1e6c107fc55a61c217b
MD5 4d0164648467337dd590923c331d6454
BLAKE2b-256 abaed98edec8984dbd12d99b4cf8acb12f1c873cf34a9896bb4894321457803d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page