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.
A real result
Example “Mixed signals”, recorded in both engines. In the app, “Try this example” loads it into Analyze.
ICA unmixed 4 variables into 3 independent components; component 1 has excess kurtosis -1.98.
- Components
- 3
- IC1 excess kurtosis
- −1.982
Plots
View data
| Group | IC1 | IC2 |
|---|---|---|
| All rows | −0.0626 | −0.1807 |
| All rows | 0.9943 | −0.1632 |
| All rows | 0.9506 | −0.1182 |
| All rows | 0.9374 | −0.0637 |
| All rows | 0.9663 | 0.0037 |
| All rows | 0.9538 | 0.0578 |
| All rows | 0.9304 | 0.1079 |
| All rows | 0.9602 | 0.1742 |
| All rows | 0.9480 | 0.2266 |
| All rows | 0.9826 | 0.2930 |
| All rows | 0.9548 | 0.3390 |
| All rows | 0.8812 | 0.3697 |
| All rows | 0.9183 | 0.4341 |
| All rows | 0.9430 | 0.4935 |
| All rows | 0.9527 | 0.5470 |
| All rows | 0.9412 | 0.5927 |
| All rows | 0.9143 | 0.6321 |
| All rows | 0.9611 | 0.6933 |
| All rows | 0.9078 | 0.7216 |
| All rows | 0.9315 | 0.7724 |
| All rows | 0.9409 | 0.8172 |
| All rows | 0.8973 | 0.8436 |
| All rows | 0.9276 | 0.8915 |
| All rows | 0.9656 | 0.9399 |
| All rows | 0.9203 | 0.9603 |
| All rows | 0.9358 | 0.9979 |
| All rows | 0.9364 | 1.029 |
| All rows | 0.9119 | 1.050 |
| All rows | 0.9556 | 1.090 |
| All rows | 0.9717 | 1.120 |
| All rows | 0.9067 | 1.121 |
| All rows | 0.9201 | 1.146 |
| All rows | 0.9561 | 1.175 |
| All rows | 0.9157 | 1.178 |
| All rows | 0.8985 | 1.186 |
| All rows | 0.9431 | 1.211 |
| All rows | 0.9160 | 1.211 |
| All rows | 0.9269 | 1.220 |
| All rows | 0.9260 | 1.224 |
| All rows | 0.8995 | 1.217 |
| All rows | 0.9245 | 1.224 |
| All rows | 0.8838 | 1.209 |
| All rows | 0.9114 | 1.212 |
| All rows | 0.9363 | 1.212 |
| All rows | 0.9243 | 1.198 |
| All rows | 0.8825 | 1.172 |
| All rows | 0.9183 | 1.169 |
| All rows | 0.8887 | 1.142 |
| All rows | 0.9133 | 1.131 |
| All rows | 0.9456 | 1.119 |
| All rows | 0.9373 | 1.093 |
| All rows | 0.9029 | 1.056 |
| All rows | 0.9610 | 1.047 |
| All rows | −1.106 | 1.114 |
| All rows | −1.078 | 1.091 |
| All rows | −1.127 | 1.042 |
| All rows | −1.074 | 1.022 |
| All rows | −1.068 | 0.9865 |
| All rows | −1.113 | 0.9329 |
| All rows | −1.075 | 0.9035 |
First 60 of 400 rows.
Independent components
| Component | Excess kurtosis | Shape |
|---|---|---|
| 1 | −1.982 | flat / bimodal |
| 2 | −1.353 | flat / bimodal |
| 3 | 1.065 | peaked / heavy-tailed |
Mixing matrix (how much each component feeds each variable)
| Variable | IC1 | IC2 | IC3 |
|---|---|---|---|
| ch1 | 0.5575 | 0.6745 | 1.297 |
| ch2 | 2.030 | 0.4549 | 0.8220 |
| ch3 | 0.3570 | 0.8197 | 0.6863 |
| ch4 | 1.031 | 0.2788 | 1.200 |
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
| Component | Excess kurtosis | Shape |
|---|---|---|
| 1 | −1.982 | flat / bimodal |
| 2 | −1.353 | flat / bimodal |
| 3 | 1.065 | peaked / heavy-tailed |
Mixing matrix (how much each component feeds each variable)
| Variable | IC1 | IC2 | IC3 |
|---|---|---|---|
| ch1 | 0.5575 | 0.6745 | 1.297 |
| ch2 | 2.030 | 0.4549 | 0.8220 |
| ch3 | 0.3570 | 0.8197 | 0.6863 |
| ch4 | 1.031 | 0.2788 | 1.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.
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"}],
})
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.