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.
Metadata
Release files for fastica-torch 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fastica_torch-0.1.1.tar.gz | 18.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fastica_torch-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.6 kB
Release files / fastica_torch-0.1.1.tar.gz
| Download URL | fastica_torch-0.1.1.tar.gz |
|---|---|
| Size | 18.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d41c64a4b6583b7f25cefa8e7f8c8021bf7ace1f380d0bcc64707eef5e7f4660
|
|
BLAKE2b-256 checksum How to use checksums |
2d3007bab0f829cf7a98f9870ecb82d7c5c640d4c4af51725c39bd2dce8aaec3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.11
|
Release files / fastica_torch-0.1.1-py3-none-any.whl
| Download URL | fastica_torch-0.1.1-py3-none-any.whl |
|---|---|
| Size | 13.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f380b6ee211ee5706a0d0655db65a2e91d4393dbe93c25e264acc812ccb28297
|
|
BLAKE2b-256 checksum How to use checksums |
5bdba5bdcebe056bd89c51c3a58548a47e227d4e465ae3f8cf50dcb9d029f6c9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.11
|