Skip to content

Cluster the projected data in SpectralBiclustering, and rank null vectors last - #515

Merged
godofecht merged 2 commits into
mainfrom
fix/spectral-biclustering-cpu
Nov 19, 2026
Merged

godofecht merged 2 commits into
mainfrom
fix/spectral-biclustering-cpu

Conversation

@godofecht

Copy link
Copy Markdown
Owner

What failed

Run all tests and examples fails on main in run 44425142857. tests/test_spectral_biclustering.flow reports that both row blocks and both column blocks landed in one cluster. It passes on macOS.

Cause

The fixture has rank two. spectral_biclustering_fit asks for six singular vectors, so four of them lie in the null space. The block power iteration returns rounding there, and the result depends on the BLAS. Where those vectors come back as zeros they score a piecewise error of zero and outrank the one vector that carries the checkerboard. Every point then has the same coordinates and k-means puts them in one cluster.

The same fault is reachable on macOS at other shapes. Before this change, of 1083 two block fixtures (4 to 40 rows, 4 to 40 columns, three block contrasts):

BLAS fits that lost the blocks
Accelerate, arm64 136
OpenBLAS, arm64 82

Change

The fit now follows scikit-learn's SpectralBiclustering more closely.

  • Left vectors are ranked against the row clusters. Right vectors are ranked against the column clusters.
  • Rows are clustered as the normalized data projected onto the kept right vectors. Columns are clustered as its transpose projected onto the kept left vectors. A null vector contributes coordinates near zero.
  • A vector whose singular value is below 0.0001 of the leading one is ranked after every real vector.

Test

tests/test_spectral_biclustering.flow gains a sweep over the 1083 fixtures above.

export FLOW_HOST=python FLOW_OPT_LEVEL=0
export FLOW_LDFLAGS="-framework Accelerate lib/scikit/flow_time.c lib/scikit/flow_parallel.c"
flow run tests/test_spectral_biclustering.flow
Accelerate OpenBLAS (Homebrew, arm64)
before 136 of 1083 fail, exit 1 82 of 1083 fail, exit 1
after 1083 pass, exit 0 1083 pass, exit 0

Toolchain is the pinned Flow commit 88aac509.

Not verified locally

The x86-64 OpenBLAS build on the runner is the one that failed, and it was not available here. This PR's Run all tests and examples job is the check for it.

Left out

Two fixtures scikit-learn recovers still fail here: 12 by 3 with two column clusters, and 60 by 40 with four row clusters and three column clusters. Both come from _bic_kmeans seeding its centres from evenly spaced points, which can pick two points from the same block. That is a separate fault from this one.

…tors last

The test fixture has rank two, so four of the six singular vectors the fit
asks for lie in the null space. The block power iteration returns rounding
there, and what it returns depends on the BLAS. Where those vectors came back
as zeros they scored a piecewise error of zero, outranked the vector that
carries the checkerboard, and every row landed in one cluster. That is the
failure on the Linux runner. On macOS the same fault shows at other shapes:
136 of 1083 two block fits with Accelerate, 82 with OpenBLAS.

The fit now follows scikit-learn more closely. Left vectors are ranked
against the row clusters and right vectors against the column clusters.
Rows are clustered as the normalized data projected onto the kept right
vectors, and columns as its transpose projected onto the kept left vectors,
so a null vector contributes coordinates near zero. A vector whose singular
value is below 0.0001 of the leading one is ranked after every real vector.

The test sweeps 1083 rank two fixtures across shapes and block contrasts.
@godofecht
godofecht merged commit e1c1bea into main Nov 19, 2026
9 checks passed
@godofecht
godofecht deleted the fix/spectral-biclustering-cpu branch November 19, 2026 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant