GithubHelp home page GithubHelp logo

rtensor's Introduction

Build Status Randomized CP Decomposition


The CP decomposition is an equation-free, data-driven tensor decomposition that is capable of providing accurate reconstructions of multi-mode data arising in signal processing, computer vision, neuroscience and elsewhere.

The ctensor package includes the following tensor decomposition routines:

  • CP using the alternating least squares method (ALS)
  • CP using the block coordinate descent method (BCD)
  • Both methods can be used either using a deterministic or a fast randomized algorithm.
  • The package is build ontop of the scikit-tensor package

The following figure illustrates the performance of the randomized accelerated CP decomposition routines. toy

Installation


Get the latest version git clone https://github.com/Benli11/ctensor

To build and install ctensor, run from within the main directory in the release: python setup.py install

After successfully installing, the unit tests can be run by: python setup.py test

See the documentation for more details (coming soon).

Example


Get started:

import numpy as np
from ctensor import ccp_als, ccp_bcd
from ctensor import dtensor, ktensor

First, lets create some toy data:

from ctensor import toydata
X = toydata(m=250, t=150, background=0, display=1)

This function returns a array of dimension 250x250x150, where the last index denotes time. The underlying spatial modes and time dynamics of the data are shown in the following figure. toy

Then we define the array as a tensor as follows

T = dtensor(X)

The CP decomposition using the block coordine descent method (BCD) is obtained as

P = ccp_bcd(T , r=4, c=False, maxiter=500)   

However, the deterministic algorihm is computational expensive in general. More efficently the randomized CP decompsition algorithm can be use to obtain a near-optimal approximation

P = ccp_bcd(T , r=4, c=True, p=10, q=2, maxiter=500)   

where the parameter p denotes the amount of oversampling, and q denotes the number of additional power iterations. By, default we use p=10, and q=2 which are a good trade-off between computational speed and approximation quality. Once the CP decompostion is obtained, the lambda values and the factor matrices can be obtained as

print(P.lmbda)
A,B,C = P.U   

The next figure shows the reconstructed modes and time dynamics, which faithfully capture the underlying system. toy

References


rtensor's People

Contributors

benli11 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.