Skip to main content

PyTorch implementation of the FastICA algorithm for Independent Component Analysis

Project description

fastica_torch

A PyTorch implementation of the FastICA algorithm for Independent Component Analysis.

This package provides a GPU-accelerated implementation that replicates sklearn.decomposition.FastICA, allowing seamless use with PyTorch tensors and CUDA acceleration.

Installation

pip install fastica_torch

Or install from source:

git clone https://github.com/RichieHakim/FastICA_torch.git
cd FastICA_torch
pip install -e .

Quick Start

import torch
from fastica_torch import FastICA

# Generate mixed signals
n_samples, n_features = 1000, 5
X = torch.randn(n_samples, n_features)

# Fit FastICA and extract sources
ica = FastICA(n_components=3, random_state=42)
sources = ica.fit_transform(X)

# Transform new data
X_new = torch.randn(100, n_features)
sources_new = ica.transform(X_new)

# Reconstruct from sources
X_reconstructed = ica.inverse_transform(sources)

Features

  • sklearn-compatible API: Drop-in replacement for sklearn.decomposition.FastICA
  • PyTorch tensors: Native support for PyTorch tensors
  • GPU acceleration: Automatic CUDA support when tensors are on GPU
  • Multiple algorithms: Both parallel and deflation extraction methods
  • Contrast functions: logcosh, exp, cube for negentropy approximation

API Reference

FastICA

FastICA(
    n_components=None,      # Number of components (None = all)
    algorithm="parallel",   # "parallel" or "deflation"
    whiten="unit-variance", # "unit-variance", "arbitrary-variance", or False
    fun="logcosh",          # "logcosh", "exp", "cube", or callable
    fun_args=None,          # Dict of arguments for fun (e.g., {"alpha": 1.0})
    max_iter=200,           # Maximum iterations
    tol=1e-4,               # Convergence tolerance
    w_init=None,            # Initial unmixing matrix
    whiten_solver="svd",    # "svd" or "eigh"
    random_state=None,      # Random seed for reproducibility
)

Methods

Method Description
fit(X) Fit the model to X
fit_transform(X) Fit and return sources
transform(X) Apply unmixing to new data
inverse_transform(S) Reconstruct data from sources

Attributes (after fitting)

Attribute Description
components_ Unmixing matrix (n_components, n_features)
mixing_ Mixing matrix (n_features, n_components)
mean_ Feature means (only if whitening)
n_iter_ Number of iterations to converge

Comparison with sklearn

This implementation aims to produce numerically equivalent results to sklearn's FastICA when using the same random seed and parameters. Minor differences may occur due to:

  • Floating-point precision differences between NumPy and PyTorch
  • Different SVD implementations
  • Sign/permutation ambiguity inherent to ICA

Requirements

  • Python >= 3.9
  • PyTorch >= 2.0
  • NumPy >= 1.20

License

MIT License - see LICENSE for details.

References

  1. A. Hyvarinen and E. Oja, "Independent Component Analysis: Algorithms and Applications", Neural Networks, 13(4-5):411-430, 2000.
  2. A. Hyvarinen, "Fast and Robust Fixed-Point Algorithms for Independent Component Analysis", IEEE Trans. Neural Networks, 10(3):626-634, 1999.

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

fastica_torch-0.1.0.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastica_torch-0.1.0-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file fastica_torch-0.1.0.tar.gz.

File metadata

  • Download URL: fastica_torch-0.1.0.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for fastica_torch-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4972a770854902090965a2fc8c355a9e96020ce2d7da484468954b7dc1d8d9d9
MD5 caf59c9562ce5fc1eadf25cfca95c3a5
BLAKE2b-256 dc264b4e17044a9b18be9f12639a2137e7e283c8f756e153b03dc6f1ed50b520

See more details on using hashes here.

File details

Details for the file fastica_torch-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: fastica_torch-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for fastica_torch-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d0b3ed01d03c659ad02b2ac6a00e045c50539f6537d030a4ee328df26a27c8f0
MD5 06c642841cde4e3ef1dac75623e53073
BLAKE2b-256 0dde0c46aef5ac7fdc0bd904c46ffe84f65cc7bfa0f74a40a84ed01d9f5c1af2

See more details on using hashes here.

Supported by

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