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
parallelanddeflationextraction methods - Contrast functions:
logcosh,exp,cubefor 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
- A. Hyvarinen and E. Oja, "Independent Component Analysis: Algorithms and Applications", Neural Networks, 13(4-5):411-430, 2000.
- A. Hyvarinen, "Fast and Robust Fixed-Point Algorithms for Independent Component Analysis", IEEE Trans. Neural Networks, 10(3):626-634, 1999.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastica_torch-0.1.1.tar.gz.
File metadata
- Download URL: fastica_torch-0.1.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d41c64a4b6583b7f25cefa8e7f8c8021bf7ace1f380d0bcc64707eef5e7f4660
|
|
| MD5 |
ca4a233d7a8930fdd3417e258366738e
|
|
| BLAKE2b-256 |
2d3007bab0f829cf7a98f9870ecb82d7c5c640d4c4af51725c39bd2dce8aaec3
|
File details
Details for the file fastica_torch-0.1.1-py3-none-any.whl.
File metadata
- Download URL: fastica_torch-0.1.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f380b6ee211ee5706a0d0655db65a2e91d4393dbe93c25e264acc812ccb28297
|
|
| MD5 |
b25fbef59421509b019466ed796ea6ea
|
|
| BLAKE2b-256 |
5bdba5bdcebe056bd89c51c3a58548a47e227d4e465ae3f8cf50dcb9d029f6c9
|