Skip to content

CDiscover · discover.ica

Independent component analysis

Which statistically independent signals were mixed together to produce these variables?

FastICA (parallel, log-cosh contrast) on whitened numeric variables: separates the observed channels into independent, non-Gaussian sources and the mixing matrix that combines them. Use it to unmix signals (sensors, spectra, returns) or to find non-Gaussian structure PCA misses. Both engines run the same algorithm from the same start matrix, so the components agree.

Verified in Python and R Python and R agree to 6 decimals Seeded Also called ICA, FastICA, blind source separation…

A real result

Example “Mixed signals”, recorded in both engines. In the app, “Try this example” loads it into Analyze.

Independent component analysisRecorded · Python and R agreeRecorded 2026-11-25 · 23 values compared
R

ICA unmixed 4 variables into 3 independent components; component 1 has excess kurtosis -1.98.

Components
3
IC1 excess kurtosis
−1.982

Plots

Independent components 1 × 2Which rows group together, and how well separated are the groups?
View data
GroupIC1IC2
All rows−0.0626−0.1807
All rows0.9943−0.1632
All rows0.9506−0.1182
All rows0.9374−0.0637
All rows0.96630.0037
All rows0.95380.0578
All rows0.93040.1079
All rows0.96020.1742
All rows0.94800.2266
All rows0.98260.2930
All rows0.95480.3390
All rows0.88120.3697
All rows0.91830.4341
All rows0.94300.4935
All rows0.95270.5470
All rows0.94120.5927
All rows0.91430.6321
All rows0.96110.6933
All rows0.90780.7216
All rows0.93150.7724
All rows0.94090.8172
All rows0.89730.8436
All rows0.92760.8915
All rows0.96560.9399
All rows0.92030.9603
All rows0.93580.9979
All rows0.93641.029
All rows0.91191.050
All rows0.95561.090
All rows0.97171.120
All rows0.90671.121
All rows0.92011.146
All rows0.95611.175
All rows0.91571.178
All rows0.89851.186
All rows0.94311.211
All rows0.91601.211
All rows0.92691.220
All rows0.92601.224
All rows0.89951.217
All rows0.92451.224
All rows0.88381.209
All rows0.91141.212
All rows0.93631.212
All rows0.92431.198
All rows0.88251.172
All rows0.91831.169
All rows0.88871.142
All rows0.91331.131
All rows0.94561.119
All rows0.93731.093
All rows0.90291.056
All rows0.96101.047
All rows−1.1061.114
All rows−1.0781.091
All rows−1.1271.042
All rows−1.0741.022
All rows−1.0680.9865
All rows−1.1130.9329
All rows−1.0750.9035

First 60 of 400 rows.

Independent components

ComponentExcess kurtosisShape
1−1.982flat / bimodal
2−1.353flat / bimodal
31.065peaked / heavy-tailed

Mixing matrix (how much each component feeds each variable)

VariableIC1IC2IC3
ch10.55750.67451.297
ch22.0300.45490.8220
ch30.35700.81970.6863
ch41.0310.27881.200
Python

ICA unmixed 4 variables into 3 independent components; component 1 has excess kurtosis -1.98.

Components
3
IC1 excess kurtosis
−1.982

To keep this page light, the plots are shown once, under the R tab.

Independent components

ComponentExcess kurtosisShape
1−1.982flat / bimodal
2−1.353flat / bimodal
31.065peaked / heavy-tailed

Mixing matrix (how much each component feeds each variable)

VariableIC1IC2IC3
ch10.55750.67451.297
ch22.0300.45490.8220
ch30.35700.81970.6863
ch41.0310.27881.200

Do it in CodeSplash Run it on your own data, in Python or R, with the code to prove it.

Worked examples in the app

  • Mixed signalsds1_mixed · features: ch1, ch2, ch3, ch4
  • Usarrests allml_usarrests · features: Murder, Assault, UrbanPop, Rape

In the guides

Where it sits in the decision guides

  • Dimensionality reduction (PCA, ICA, NMF) · DS & ML Decision Guide · Discover — find structure without labels

What you need

Variablesnumeric · 2–200 columns
Observed channels to unmix (numbers; rows with a missing value are left out).
Color points bycategorical / boolean · 0–1 column
Optional: colors the source map only.

Choices you make

model

Componentsdefault —

Independent sources to extract (at most the number of variables).

Advanced

Maximum iterationsdefault 200

FastICA fixed-point iterations before stopping without convergence.

Convergence tolerancedefault 0.0001

Stop when no unmixing direction changes by more than this.

What it reports

n
How many independent units the analysis used; it sets precision and power.
n_variables
How many independent units the analysis used; it sets precision and power.
n_components
How many independent units the analysis used; it sets precision and power.
n_iter
How many independent units the analysis used; it sets precision and power.
converged
Whether an iterative fit found a stable solution; warnings mean estimates may be unreliable.

Per group, level or term: kurtosis[<k>], mixing[<k>:<variable>], source_check[<k>]

Python and R

Python and R agree to 6 decimals (relative tolerance 1e-6). Python uses numpy; R uses codesplashr.

Default traps between the two languages

  • Both engines run codesplash's FastICA twin (PCA whitening with canonical eigenvector signs, start matrix from the shared random stream, log-cosh contrast, symmetric decorrelation). scikit-learn's FastICA and R's fastICA start from their own random matrices and return components in arbitrary order and sign; here components are ordered by |excess kurtosis| and signed so each mixing column's largest entry is positive.
Python

The exact script CodeSplash ran for example “Mixed signals” · Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0

# Independent component analysis
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method discover.ica 1.0.0 · spec 75b76cce380f11b3
# Dataset: ds1_mixed (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
import os

import numpy as np
import pandas as pd

import codesplash as cs
from codesplash import ml as csml
from codesplash.ml import discover_ext as dx
from codesplash.ml import embed as csembed

def chart_rows(n, cap=2000):
    return np.arange(n) if n <= cap else np.unique(np.linspace(0, n - 1, cap).round().astype(int))

# %% Data
FEATURES = ["ch1", "ch2", "ch3", "ch4"]
LABEL = None
SEED = 42
df = pd.read_parquet("tests/parity/fixtures/ds1_mixed.parquet", columns=list(dict.fromkeys(FEATURES + ([LABEL] if LABEL else []))))
n_input = len(df)
warnings = []
rows = csembed.complete_rows(df, FEATURES)
if len(rows) < n_input:
    warnings.append(f"{n_input - len(rows)} of {n_input} rows were left out because a value was missing.")
if len(rows) < len(FEATURES) + 2:
    raise ValueError("ICA needs more rows than variables.")
X = csembed.numeric_matrix(df, FEATURES, rows)

# %% Independent components (FastICA twin: whitening, host start matrix, log-cosh contrast)
K = 3
K = len(FEATURES) if K is None else min(int(K), len(FEATURES))
fit = dx.fastica(X, K, SEED, max_iter=200, tol=0.0001)
S, A, kurt = fit["sources"], fit["mixing"], fit["kurtosis"]
if not fit["converged"]:
    warnings.append(f"FastICA did not converge in {fit['n_iter']} iterations (largest change {fit['lim']:.2g}); raise the iterations or ask for fewer components.")

# %% Artifacts
out = csml.out_dir("target/academy-parity/run-8142/discover.ica/mixed_signals/out-python")
emb = pd.DataFrame({"row": rows.astype(np.int64)})
for j in range(K):
    emb[f"dim_{j + 1}"] = S[:, j]
emb.to_parquet(os.path.join(out, "embedding.parquet"), index=False)

# %% Result
values = {"n": len(rows), "n_variables": len(FEATURES), "n_components": K, "n_iter": fit["n_iter"], "converged": int(fit["converged"])}
for j in range(K):
    values[f"kurtosis[{j + 1}]"] = float(kurt[j])
    values[f"source_check[{j + 1}]"] = csembed.checksum(S[:, j], rows)
    for i, f in enumerate(FEATURES):
        values[f"mixing[{j + 1}:{f}]"] = float(A[i, j])
tables = [
    {
        "key": "components",
        "title": "Independent components",
        "columns": [
            {"key": "component", "label": "Component", "type": "integer"},
            {"key": "kurtosis", "label": "Excess kurtosis", "type": "number"},
            {"key": "shape", "label": "Shape"},
        ],
        "rows": [{"component": j + 1, "kurtosis": float(kurt[j]),
                  "shape": "peaked / heavy-tailed" if kurt[j] > 0.5 else ("flat / bimodal" if kurt[j] < -0.5 else "near Gaussian")} for j in range(K)],
    },
    {
        "key": "mixing",
        "title": "Mixing matrix (how much each component feeds each variable)",
        "columns": [{"key": "variable", "label": "Variable"}] + [{"key": f"ic{j + 1}", "label": f"IC{j + 1}", "type": "number"} for j in range(K)],
        "rows": [dict({"variable": f}, **{f"ic{j + 1}": float(A[i, j]) for j in range(K)}) for i, f in enumerate(FEATURES)],
    },
]
charts = []
if K >= 2:
    pick = chart_rows(len(rows))
    groups = ["All rows"] * len(pick) if LABEL is None else [("(missing)" if pd.isna(v) else str(v)) for v in df[LABEL].iloc[rows[pick]]]
    charts.append(cs.chart("map", "cluster-scatter", "Independent components 1 × 2", {
        "x": cs.col("IC1", S[pick, 0], "numeric"),
        "y": cs.col("IC2", S[pick, 1], "numeric"),
        "cluster": cs.col(LABEL or "Group", groups, "categorical"),
    }, note=None if len(pick) == len(rows) else f"{len(pick):,} of {len(rows):,} rows shown."))
cs.publish({
    "title": "Independent component analysis",
    "engine": cs.engine_info("numpy", "pandas"),
    "n": len(rows),
    "summary": f"ICA unmixed {len(FEATURES)} variables into {K} independent components; component 1 has excess kurtosis {kurt[0]:.2f}.",
    "statistics": [
        {"key": "n_components", "label": "Components", "value": K, "format": "integer"},
        {"key": "kurtosis1", "label": "IC1 excess kurtosis", "value": float(kurt[0])},
    ],
    "tables": tables,
    "charts": charts,
    "values": values,
    "warnings": warnings,
    "artifacts": [{"key": "embedding", "path": os.path.join(out, "embedding.parquet"), "format": "parquet"}],
})
R

The exact script CodeSplash ran for example “Mixed signals” · R version 4.5.1 (2025-06-13)

# Independent component analysis
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method discover.ica 1.0.0 · spec 75b76cce380f11b3
# Dataset: ds1_mixed (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
library(codesplashr)

chart_rows <- function(n, cap = 2000) if (n <= cap) seq_len(n) else unique(round(seq(1, n, length.out = cap)))

# %% Data
FEATURES <- c("ch1", "ch2", "ch3", "ch4")
LABEL <- NULL
SEED <- 42
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/ds1_mixed.parquet", col_select = unique(c(FEATURES, LABEL))))
n_input <- nrow(df)
warnings <- list()
rows <- cs_ml_complete_rows(df, FEATURES)
if (length(rows) < n_input) {
  warnings <- c(warnings, sprintf("%d of %d rows were left out because a value was missing.", n_input - length(rows), n_input))
}
if (length(rows) < length(FEATURES) + 2) stop("ICA needs more rows than variables.")
X <- cs_ml_numeric_matrix(df, FEATURES, rows)

# %% Independent components (FastICA twin: whitening, host start matrix, log-cosh contrast)
K <- 3
K <- if (is.null(K)) length(FEATURES) else min(as.integer(K), length(FEATURES))
fit <- cs_ml_fastica(X, K, SEED, max_iter = 200, tol = 0.0001)
S <- fit$sources; A <- fit$mixing; kurt <- fit$kurtosis
if (!fit$converged) {
  warnings <- c(warnings, sprintf("FastICA did not converge in %d iterations (largest change %s); raise the iterations or ask for fewer components.",
                                  fit$n_iter, format(signif(fit$lim, 2))))
}

# %% Artifacts
out <- cs_ml_out_dir("target/academy-parity/run-8142/discover.ica/mixed_signals/out-r")
emb <- data.frame(row = as.integer(rows))
for (j in seq_len(K)) emb[[paste0("dim_", j)]] <- S[, j]
nanoparquet::write_parquet(emb, file.path(out, "embedding.parquet"))

# %% Result
values <- list(n = length(rows), n_variables = length(FEATURES), n_components = K, n_iter = fit$n_iter, converged = as.integer(fit$converged))
for (j in seq_len(K)) {
  values[[sprintf("kurtosis[%d]", j)]] <- kurt[j]
  values[[sprintf("source_check[%d]", j)]] <- cs_ml_checksum(S[, j], rows)
  for (i in seq_along(FEATURES)) values[[sprintf("mixing[%d:%s]", j, FEATURES[i])]] <- A[i, j]
}
shape_of <- function(k) if (k > 0.5) "peaked / heavy-tailed" else if (k < -0.5) "flat / bimodal" else "near Gaussian"
tables <- list(
  list(key = "components", title = "Independent components",
       columns = list(list(key = "component", label = "Component", type = "integer"),
                      list(key = "kurtosis", label = "Excess kurtosis", type = "number"),
                      list(key = "shape", label = "Shape")),
       rows = lapply(seq_len(K), function(j) list(component = j, kurtosis = kurt[j], shape = shape_of(kurt[j])))),
  list(key = "mixing", title = "Mixing matrix (how much each component feeds each variable)",
       columns = c(list(list(key = "variable", label = "Variable")),
                   lapply(seq_len(K), function(j) list(key = paste0("ic", j), label = paste0("IC", j), type = "number"))),
       rows = lapply(seq_along(FEATURES), function(i) {
         r <- list(variable = FEATURES[i])
         for (j in seq_len(K)) r[[paste0("ic", j)]] <- A[i, j]
         r
       }))
)
charts <- list()
if (K >= 2) {
  pick <- chart_rows(length(rows))
  groups <- if (is.null(LABEL)) rep("All rows", length(pick)) else {
    g <- as.character(df[[LABEL]][rows[pick] + 1L]); g[is.na(g)] <- "(missing)"; g
  }
  charts[[1]] <- cs_chart("map", "cluster-scatter", "Independent components 1 × 2", list(
    x = cs_col("IC1", S[pick, 1], "numeric"),
    y = cs_col("IC2", S[pick, 2], "numeric"),
    cluster = cs_col(if (is.null(LABEL)) "Group" else LABEL, groups, "categorical")
  ), note = if (length(pick) == length(rows)) NULL else sprintf("%s of %s rows shown.", format(length(pick), big.mark = ","), format(length(rows), big.mark = ",")))
}
cs_publish(list(
  title = "Independent component analysis",
  engine = cs_engine_info("codesplashr", "nanoparquet"),
  n = length(rows),
  summary = sprintf("ICA unmixed %d variables into %d independent components; component 1 has excess kurtosis %.2f.", length(FEATURES), K, kurt[1]),
  statistics = list(list(key = "n_components", label = "Components", value = K, format = "integer"),
                    list(key = "kurtosis1", label = "IC1 excess kurtosis", value = kurt[1])),
  tables = tables,
  charts = charts,
  values = values,
  warnings = warnings,
  artifacts = list(list(key = "embedding", path = file.path(out, "embedding.parquet"), format = "parquet"))
))

Sources

  • Hyvärinen A (1999). Fast and robust fixed-point algorithms for independent component analysis. IEEE Trans Neural Networks 10(3):626–634.
  • Hyvärinen A, Oja E (2000). Independent component analysis: algorithms and applications. Neural Networks 13:411–430.

From the CodeSplash method registry · discover.ica v1.0.0.