Skip to main content

OTICA logo

OTICA

Optimal Transport Independent Component Analysis.
Contrast-free source separation for linear non-Gaussian mixtures.

Documentation · PyPI ·

PyPI version Supported Python versions: 3.11–3.14 Lint status Coverage Documentation status License

otica is a Python package for linear independent component analysis (ICA) based on optimal transport. It recovers latent sources by maximizing their empirical squared 2-Wasserstein distances to the standard Gaussian, using a fixed non-Gaussianity criterion that requires no user-chosen contrast function or nonlinearity.


✨ Features

  • Contrast-free source separation: Uses the squared 2-Wasserstein distance to the standard Gaussian as a fixed non-Gaussianity criterion.
  • Exact empirical objective: Computes the one-dimensional Wasserstein criterion directly from ordered samples and Gaussian quantiles, without density estimation.
  • Riemannian optimization: Optimizes the whitened ICA objective on the orthogonal group with a Picard-style limited-memory BFGS method and Armijo backtracking.
  • Dimension reduction: Supports extraction of a specified number of components through principal-component whitening.
  • Flexible initialization: Accepts FastICA, random, or user-provided initial unmixing matrices through w_init.
  • scikit-learn integration: Native BaseEstimator integration with the standard transformer API, including fit, transform, fit_transform, and inverse_transform.

⚡ Method

For observations generated by the linear ICA model $X = S A^\top$, otica first centers and whitens the data. Let $Z \in \mathbb{R}^{d}$ be the whitened random vector. For an orthogonal unmixing matrix $W \in \mathbb{R}^{d \times d}$, the population objective is

$$ F(W) = \sum_{k = 1}^{d} \mathcal{W}_2\left( (Z W^\top)_k, \mathcal{N}(0, 1) \right)^2, \quad W W^\top = I_d. $$

Given $n$ whitened observations collected as the rows of $Z \in \mathbb{R}^{n \times d}$, let $Y = Z W^\top$. OTICA maximizes

$$ \widehat{F}n(W) = \sum{k = 1}^{d} \mathcal{W}2\left( \frac{1}{n} \sum{i = 1}^{n} \delta_{Y_{ik}}, \mathcal{N}(0, 1) \right)^2. $$

For each component $k$, the implementation sorts the entries of the $k$-th column as $Y_{(1)k} \leq \cdots \leq Y_{(n)k}$ and matches them with the corresponding standard-Gaussian rank statistics. Under the usual ICA assumptions, including mutually independent sources with at most one Gaussian component, the population objective identifies the sources up to permutation, sign, and scale.


🚀 Installation

python -m pip install otica

🔧 Usage

Example

The following example generates three independent non-Gaussian signals, mixes them linearly, and recovers them with OTICA. Because ICA is identifiable only up to permutation and sign, recovery is evaluated using the best absolute correlation for each true source.

import matplotlib.pyplot as plt
import numpy as np
from otica import OTICA

rng = np.random.default_rng(42)
n_samples = 5000
time = np.linspace(0.0, 8.0, n_samples)

# Generate independent, non-Gaussian latent sources.
sources = np.column_stack(
    [
        rng.laplace(size=n_samples),
        rng.uniform(-np.sqrt(3.0), np.sqrt(3.0), size=n_samples),
        rng.standard_t(df=5, size=n_samples) * np.sqrt(3.0 / 5.0),
    ]
)

# Mix the sources into the observed signals.
mixing = np.array(
    [
        [1.0, 0.5, -0.2],
        [0.2, 1.0, 0.4],
        [-0.4, 0.1, 1.0],
    ]
)
X = sources @ mixing.T

# Fit OTICA and recover the latent components.
model = OTICA(random_state=42)
estimated_sources = model.fit_transform(X)

correlations = np.corrcoef(sources.T, estimated_sources.T)[:3, 3:]
best_indices = np.abs(correlations).argmax(axis=1)
best_correlations = correlations[np.arange(3), best_indices]
recovered_sources = estimated_sources[:, best_indices] * np.sign(best_correlations)
print("Best absolute correlation per source:", np.abs(best_correlations))

fig, axes = plt.subplots(3, 2, sharex=True, figsize=(12, 6))
for component in range(3):
    axes[component, 0].plot(
        time[:500], sources[:500, component], color="#4292DC"
    )
    axes[component, 1].plot(
        time[:500], recovered_sources[:500, component], color="#FF8866"
    )
    axes[component, 0].set_ylabel(f"Source {component + 1}")

axes[0, 0].set_title("True sources")
axes[0, 1].set_title("Recovered sources")
axes[-1, 0].set_xlabel("Time")
axes[-1, 1].set_xlabel("Time")
fig.tight_layout()
plt.show()

📊 Reproducing Results

Clone the repository, create and activate a virtual environment, then install the exact package versions used for the paper:

python -m pip install -r scripts/requirements.txt

Keep the repository folder layout unchanged: do not move, rename, or flatten its folders, because the experiment scripts resolve paths relative to their file locations.

Run the experiment scripts from the repository root:

python scripts/criterion-rotation.py
python scripts/statistical-performance.py --nd
python scripts/statistical-performance.py --gaussianity
python scripts/runtime-scaling.py

Alternatively, run all experiments sequentially on Windows, Linux, or macOS:

python run-all.py

The runner uses the active Python interpreter and stops if an experiment fails.

These commands write criterion-rotation.pdf, varying-nd-amari-index.pdf, gaussianity-amari-index.pdf, and runtime-scaling.pdf to figures/. The paper settings (including random seed 42, sample sizes, dimensions, distributions, and 20 runs) are defined as constants near the top of each script.

Metadata

Release files for otica 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for otica 0.2.2
File Size Uploaded Provenance Actions
otica-0.2.2.tar.gz 657.9 kB Without provenance Details for otica-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for otica 0.2.2
File Interpreter ABI Platform Actions
otica-0.2.2-py3-none-any.whl Python 3 none any Details for otica-0.2.2-py3-none-any.whl

Total release size: 681.5 kB

Release files / otica-0.2.2.tar.gz

Download URL otica-0.2.2.tar.gz
Size 657.9 kB
Tags Source
SHA-256 checksum
How to use checksums
811ba51daedc773b0e2029b5fb4bb742e533989d01b98753c8f5d107c4dfcabe
BLAKE2b-256 checksum
How to use checksums
432e2d2d8434498f7e82f0a50e880a3175de4177e834a3779dfe1d7ced64cd8a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / otica-0.2.2-py3-none-any.whl

Download URL otica-0.2.2-py3-none-any.whl
Size 23.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
68ae5b92176a1a4d95e1ef2fdeb8d3395559e28f7b20a6de05222b8b47451e05
BLAKE2b-256 checksum
How to use checksums
454d17a96c11f3fdda6a68755a1d65addbb6811d57c2dcb4a4f1778f8deee282
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for otica 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page