Manuscript Offprint
arXiv:2610.25898HP-GSBS: Accelerating greedy state boundary search with reusable interval statistics
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
Abstract
Greedy State Boundary Search (GSBS) identifies transitions between relatively stable neural activity patterns, but repeated candidate evaluation makes large analyses expensive. HP-GSBS is an open-source Python package that reorganizes the search around reusable interval contributions and correlation statistics. Streaming candidate reduction and local refinement further reduce repeated work; CPU, PyTorch CUDA and Triton backends share sequential segmentation decisions. Across seven controlled workloads with two realizations each, median same-input speedups range from 154 to 1730 times. All 168 optimized executions reproduce original boundaries and selected state counts, with maximum absolute t-distance difference . Four frozen EEG recordings provide complementary validation, including a complete input-to-segmentation application example. Batch processing, versioned result persistence and optional low-memory execution support recording collections and longer inputs. By removing redundant computation, HP-GSBS makes established neural-state segmentation faster while preserving its scientific outputs.
Keywords: neural state segmentation, GSBS, EEG, GPU computing
Required metadata
The computational bottleneck lies inside the search. Each candidate boundary repeatedly triggers state-mean reconstruction and comparison with the observed series. Double-boundary search considers pairs of positions within a state, expanding the candidate space quadratically with interval length. Refinement revisits existing boundaries after insertions, repeating calculations for intervals whose data have not changed. These costs accumulate across participants, stimuli and feature sets.
HP-GSBS [4] reorganizes this computation around reusable statistics. Interval contributions replace repeated template reconstruction, correlation prefixes replace repeated pairwise scans, and streaming search retains the best candidate without a dense candidate-score array. CPU and GPU implementations share the sequential search controller. The package accepts prepared time-by-feature matrices and returns complete segmentation outputs for existing research workflows.
2. Software description
2.1. Software architecture
The principal acceleration comes from reorganizing GSBS computation around reusable interval contributions and correlation statistics (Fig. 1). Let contain spatial patterns with features. Define , using the sample standard deviation. GSBS maximizes the mean spatial correlation between each observation and its assigned state pattern, then uses t-distance to select among partitions [2].
For a partition S into half-open intervals, this objective becomes
where
and . Normalizing a state mean removes its interval-length factor, yielding Eq. (1). The derivation and
*Corresponding author.
Email address: justinzhaoyz@outlook.com (Yanzhe Zhao)
| Nr. | Code metadata description | Metadata |
|---|---|---|
| C1 | Current code version | 0.2.0 |
| C2 | Permanent GitHub link to code/repository used for this code version | https://github.com/JustinZHAO-05/HP-GSBS/tree/v0.2.0 |
| C3 | Legal Code License | MIT |
| C4 | Code versioning system used | Git |
| C5 | Software code languages, tools, and services used | Python; NumPy, SciPy, Numba; optional PyTorch CUDA and Triton |
| C6 | Compilation requirements, operating environments & dependencies | Python 3.10; NumPy, SciPy, Numba, threadpoolctl, psutil, tqdm and statesegmentation 0.0.6. Numba performs just-in-time compilation. Optional NVIDIA GPU support uses CUDA PyTorch; Triton is tested on Linux/WSL2. |
| C7 | If available Link to developer documentation/manual | https://github.com/JustinZHAO-05/HP-GSBS/tree/v0.2.0/docs |
| C8 | Support email for questions | justinzhaoyz@outlook.com |
Table 1: Code metadata. The software is also archived at doi:10.5281/zenodo.23422148.
floating-point implementation are given in Supplementary Methods S1.
Replacing a state by two or three states changes only its contribution:
The interval-score table reduces each candidate to a few lookups (Fig. 1B). Constructing costs arithmetic and storage. A streaming reduction evaluates the legal candidates in order and retains their maximum, eliminating the additional quadratic double-candidate score array. Window-local refinement evaluates the requested boundary neighbourhood, and an active-block cache reuses local winners while their partition remains unchanged.
The best single- and double-boundary proposals are compared through t-distance, the Welch contrast [7] between within-state correlations and correlations across adjacent states :
Separate two-dimensional prefixes of pair counts, correlations and squared correlations provide means and unbiased variances by rectangular queries (Fig. 1C). Unlike , which scores interval templates, these tables summarize time-pair correlations for partition comparison. After interval endpoints are available, evaluating a partition requires queries rather than rescanning all time pairs. The temporal exclusion parameter is encoded in the pair mask. GSBS then accepts one or two boundaries and refines them sequentially.
The CPU backend uses NumPy/SciPy [8, 9] and Numba-compiled search [10]. PyTorch CUDA batches matrix products and prefix operations [11]; Triton fuses interval differences, dot products and norms [12]. GPU routes transfer precomputed statistics to the shared CPU controller, assigning regular numerical work to the accelerator while preserving sequential search dependencies.
2.2. Software functionalities
A configuration separates scientific parameters from execution choices. Users retain their statewise detection, maximum state count, block size, temporal exclusion and refinement settings. Results expose boundaries at every state-count index, t-distance, state patterns and boundary strengths. A typical workflow fits a prepared input, retrieves its segmentation, saves a reusable result and processes a collection:
from hpgsbs import GSBSConfig, GSBSResult, fit, fit_many cfg = GSBSConfig(kmax=20, dmin=1, mode="throughput") r = fit(x, cfg, backend="cpu-fast") bounds, curve = r.get_bounds(r.nstates), r.tdists r.save("results/recording.npz") restored = GSBSResult.load("results/recording.npz") batch = fit_many(recordings, cfg, backend="torch-cuda", batch_size="auto")
CPU workers fit recordings independently; GPU batches group compatible shapes and configurations. The manifest-based command-line workflow saves outputs atomically and resumes completed tasks only when input and versioned execution identities match. Output comparison checks complete boundary histories and numerical fields; optional traces compare search and refinement decisions. The versioned wheel/sdist, tests and examples support installation and reuse. Supplementary Section S3 gives a CPU-compatible workflow and recovery example.
FP64 is the default, with reference-expression reevaluation for ambiguous calculations. Full-Q/Prefix2D is the ordinary fast route. An optional CPU mode uses bounded candidate chunks and feature-moment t-distance statistics to avoid full pairwise tables; its double-candidate domain can still be quadratic. Supplementary Methods S2–S3 describe this trade-off.
3. Illustrative examples
3.1. Numerical consistency
A four-state synthetic input illustrates known-boundary recovery (Fig. 2). Sixteen features span 80 samples, with
A Neural state segmentation
GSBS
Multivoxel activity

State templates
Mean

Boundary search
Candidate boundary
State count
Number of states, K
B Interval score reuse
HP-GSBS · FULL-Q
Original GSBS
Temporal prefixes

Rebuild for each candidate
Interval vectors
Interval table Q
Candidate splits
Score gain
Single
Double
Lookup & reuse
Select by TD
Refine
C Prefix-based t-distance
HP-GSBS · PREFIX2D
Pattern correlations
2D prefix statistics

Within vs adjacent

Count
Sum r
Sum
Four-corner query

Pattern correlation
t-distance
CPU
PyTorch CUDA
Triton
Shared search + refinement
States
TD(K)
K
Figure 1: Neural-state segmentation and reusable computation. (A) GSBS constructs state templates, searches candidate boundaries and selects the state count using t-distance. (B) Temporal prefixes supply reusable interval scores, ; single and double splits replace only their parent contribution. The best proposals undergo t-distance comparison and sequential refinement. (C) Two-dimensional prefixes of valid-pair counts, correlations and squared correlations provide within-state and adjacent-state statistics by four-corner queries. The full symmetric correlation matrix is shown; statistics use each eligible pair once. Three numerical backends feed a shared search controller. Data-derived elements use a 120-TR Sherlock fMRI excerpt [5, 6]; heatmaps show feature subsets, while fitting uses all 4,230 voxels. Detailed construction and provenance are in Supplementary Section S4.
Gaussian state means and noise of standard deviation 0.05. All implementations select four states at boundaries 20, 40 and 60. Maximum absolute t-distance differences are for CPU and for both GPU routes; every recorded search and refinement decision agrees.
The controlled benchmark covers seven configurations and two realizations per configuration. All 168 optimized executions, including warm-ups, reproduce official complete boundary arrays and selected state counts. State patterns and strengths are identical; the largest absolute t-distance difference is .
Official GSBS HP CPU HP PyTorch HP Triton
A Piecewise-stationary input

B Shared boundaries and selected K = 4
C Complete state-count curve

D Floating-point differences

Figure 2: Segmentation agreement on a four-state signal. (A) Synthetic activity; dashed lines mark generating boundaries. (B) Ground truth and selected boundaries from the official implementation and three HP-GSBS backends. (C) Complete t-distance curves, retaining double-insertion indexing; all routes select K = 4. (D) Absolute differences from official values; GPU curves overlap. Seed 19; noise standard deviation 0.05; T = 80, P = 16, .
3.2. Real EEG application
Four frozen inputs derived from the Brain, Body, and Behavior Dataset [13] provide application-level evidence. These 5.12-Hz matrices span 32 or 64 channels and 1336–1857 samples. Boundary histories and selected state counts match their reference outputs across the three backends (Table 2).
Figure 3 follows Recording 1 from its full 64-channel input to the selected state sequence. A fixed central excerpt links the detected boundaries to the temporal pattern-similarity matrix. All routes select 126 states and reproduce the complete boundary history, with maximum TD difference . Local views are extracted from saved full-record fits, connecting the input, state intervals and state-count selection without refitting the excerpt.
3.3. Controlled runtime performance
The paired benchmark varies recording length, feature count and search depth around , , (Fig. 4). Lengths are 256, 512 and 768; feature counts are 8, 32 and 64; maximum state counts are 10, 20 and 40. Reusing the centre gives seven unique configurations. Inputs comprise eight contiguous states with Gaussian spatial means and noise of standard deviation 0.8.
Measurements use HP-GSBS 0.2.0 and unmodified statesegmentation 0.0.6 on a Ryzen 7 7840H and RTX 4050 Laptop GPU (6 GB), under WSL2. Arithmetic is FP64, TF32 is disabled and numerical-library thread counts are one. Each input has one timed official fit and, per optimized backend, one warm-up followed by three timed fits. Backend order rotates; GPU timing is synchronized. Complete-fit times include construction, computation and transfers, excluding file access, validation and saving. Speedups are computed within input before summarizing across seeds (Supplementary Section S4).
At the centre, official GSBS takes 64.7 s, compared with 0.142 s for CPU, 0.081 s for PyTorch and 0.099 s for Triton. Median paired speedups are 454, 795 and 675 times, respectively. At T = 768, they reach 770 times for CPU and 1730 times for PyTorch. The CPU gains establish the value of computation reuse independently of
A Full-record segmentation
64 channels · 5.12 Hz

B Boundary agreement · zoom

C Temporal pattern similarity

D State-count selection

Figure 3: Real EEG segmentation from saved full-record fits. (A) Standardized 64-channel EEG and the selected state sequence; alternating colours distinguish adjacent intervals. (B) A fixed central window (120.51–140.43 s), with boundaries from four implementations aligned beneath the input. Both EEG heatmaps use a colour scale clipped at . (C) Full symmetric spatial-pattern correlations for the same window; outlined blocks mark selected state intervals. (D) All evaluated t-distance indices, preserving double-insertion indexing; marker positions are staggered for visibility. All routes select 126 states with identical boundary histories and a maximum absolute TD difference of . Parameters: , , statewise detection, sequential refinement, block size 50 and FP64.
GPU acceleration. Across the feature-count and search-depth sweeps at , optimized runtimes remain 0.065–0.165 s. Historical comparisons for larger workloads are reported separately in Supplementary Table S6.
3.4. Computational reuse, memory and batch throughput
Figure 5A isolates improvements within an existing Full-Q implementation. On the EEG input, , streaming candidates reduces runtime from 3.364 to 1.803 s; local refinement and active-block caching reduce it further to 1.601 and 1.429 s. Scientific settings remain fixed.
For a input under single-boundary search without refinement, low-memory execution reduces peak RSS from 1598.0 to 190.6 MiB and runtime from 9.754 to 0.110 s (Fig. 5B). A separate four-workload series reaches with 469.5 MiB peak RSS and 1.444 s runtime. Both di-
| Recording | Selected | Maximum | Equal boundaries | ||
|---|---|---|---|---|---|
| 1 | 131 | 126 | Yes | ||
| 2 | 121 | 120 | Yes | ||
| 3 | 172 | 173 | Yes | ||
| 4 | 135 | 131 | Yes |
Table 2: Historical saved-output comparisons on frozen EEG, summarized over CPU, PyTorch CUDA and Triton FP64 outputs. Each recording used dmin=5, statewise detection, finetune=1 and blocksize=50. Reference provenance and comparison levels are specified in Supplementary Section S4. Double insertion permits a final state count of .
Official GSBS
HP CPU
HP PyTorch
HP Triton
A ,

B ,

C ,

D Paired speedup

E

F

Figure 4: Controlled complete-fit performance. (A–C) Runtime versus T, P and , with the other two fixed. Small filled points show two per-input observations; open markers show their median, and whiskers their range. HP observations summarize three timed fits after warm-up; official observations are single fits. The annotation in B gives central-configuration runtimes. (D–F) Same-input official/HP speedups across seeds; D highlights the median PyTorch speedup at T = 768. The central configuration is reused across panels. All fits use statewise detection and sequential refinement.
mensions increase in this series. Selected and final partitions agree with an independent tiled t-distance calculation within .
The throughput curves show how parallelism depends on workload (Fig. 5C,D). Short-input CPU throughput increases from 274 to 1767 fits/minute with one versus eight workers. PyTorch batching increases it from 647 to 1418 fits/minute at batch size eight, with larger batches showing the subsequent trend. Repeated high-K EEG tasks favour recording-level CPU parallelism: eight workers reach 155 fits/minute, versus approximately 40–45 for the GPU routes. GPU batching accelerates precomputation while each recording retains sequential CPU search.
3.5. Computing environment and reproducibility
The controlled measurements used Python 3.10.12, NumPy 2.2.6, SciPy 1.15.3, Numba 0.68.0, PyTorch 2.11.0/CUDA 12.8 and Triton 3.6.0. The package supplies observations, plotting arrays, figure code and a separate rerun protocol. Matplotlib [14] regenerates all five figures without new GSBS fits. Supplementary Material records the distinct provenance of the paired benchmark, mechanism
A Computation reuse

B Long-input efficiency
Full-Q Low-memory
Peak RSS (MiB)
Runtime (s)

Low-memory workloads

C Short inputs
450 time points × 16 features,
Input size (T × P)
CPU scaling
GPU batching

Workers

Batch size
CPU
PyTorch CUDA
Triton
D High-K input
1336 time points × 64 features,
CPU scaling
GPU batching

Workers

Batch size
Figure 5: Computation reuse, memory and parallel execution. (A) CPU ablation on a EEG input, . (B) Left: peak process RSS and complete-fit time for a input. Right: four increasing low-memory workloads; both T and P change. Separate measurements give 190.6 and 191.1 MiB at . All B measurements use single-boundary search, no refinement, block size zero and . (C,D) Throughput versus CPU workers and GPU batch size for short synthetic and high-K EEG inputs. CPU batches contain 32 and eight tasks, respectively; high-K tasks repeat one EEG input. A, B runtimes and C/D show three-run medians and observed-range whiskers; memory values are measured peaks. These are existing release-development measurements.
illustration, saved EEG outputs and release-development measurements.
4. Impact
HP-GSBS makes repeated neural-state analysis practical within a research workflow. Tens or hundreds of seconds become subsecond fits in the controlled benchmark, allowing researchers to iterate across participants, stimuli and feature sets. Batch scheduling extends this benefit to recording collections, while saved boundary histories and t-distance curves support later state-count comparisons without repeating the fit.
Historical release benchmarks extend this picture to larger inputs (Supplementary Table S6). For and , recorded official runtime is approximately 5011 s and release-wheel PyTorch runtime is 0.363 s. This separate cross-session comparison illustrates the change from an hour-scale task to subsecond processing; the paired experiment supplies the primary speedup estimates.
The common interface lets researchers choose CPU workers or GPU batching according to workload, retain their preprocessing and scientific parameters, and inspect numerical agreement before adoption. Full-Q prioritizes latency at quadratic storage cost, whereas the optional low-memory route supports longer restricted workloads. The evidence covers laptop-class hardware and four frozen EEG records; the open implementation provides a basis for wider applications.
5. Conclusions
HP-GSBS accelerates neural-state segmentation by computing reusable interval statistics and concentrating subsequent work on changing parts of the partition. CPU and
GPU implementations reproduce original boundary decisions across controlled synthetic and frozen EEG examples. Same-input speedups of 154–1730 times, batch processing and optional low-memory execution expand the practical scale of GSBS while preserving its scientific outputs.
Funding
This research did not receive any specific grant from funding agencies in the public, commercial, or not-for-profit sectors.
Declaration of competing interest
The authors declare no known competing financial interests or personal relationships that could have appeared to influence the work reported in this paper.
Code and data availability
HP-GSBS 0.2.0 is available under the MIT license through the versioned repository in Table 1 and Zenodo [4]. The paper reproducibility materials (version 1.0.1) are archived at doi:10.5281/zenodo.23457342 [15] and maintained at https://github.com/JustinZHAO-05/HP-GSBS-SoftwareX-Reproducibility. The package includes the Sherlock-derived mechanism example with attribution [5, 6], synthetic inputs, benchmark observations, Recording 1's frozen EEG input and saved outputs, aggregate comparisons for the other three EEG records, and reproduction scripts. Original BBBD data are described by Madsen et al. [13]. Original reproduction code is MIT licensed; data, derived examples, figures and documentation are distributed under CC BY 4.0 with source attribution and processing information.
CRediT authorship contribution statement
Yanzhe Zhao: Conceptualization, Methodology, Software, Formal analysis, Investigation, Validation, Data curation, Visualization, Writing – original draft, Writing – review & editing, Project administration.
Yongzhang Ji: Methodology, Writing – review & editing.
Declaration of generative AI and AI-assisted technologies in the manuscript preparation process
ChatGPT (OpenAI) assisted drafting, language editing and figure-code preparation; Codex (OpenAI) assisted software, experiment scripts and manuscript integration. Numerical results come from recorded experiments, and figures were rendered programmatically from data. The authors are responsible for scientific interpretation and final approval.
References
[1] C. Baldassano, J. Chen, A. Zadbood, J. W. Pillow, U. Hasson, K. A. Norman, Discovering event structure in continuous narrative perception and memory, Neuron 95 (3) (2017) 709–721.e5. doi:10.1016/j.neuron.2017.06.041.
[2] L. Geerligs, M. van Gerven, U. Güçlü, Detecting neural state transitions underlying event segmentation, NeuroImage 236 (2021) 118085. doi:10.1016/j.neuroimage.2021.118085.
[3] L. Geerligs, D. Gözükara, D. Oetringer, K. L. Campbell, M. van Gerven, U. Güçlü, A partially nested cortical hierarchy of neural states underlies event segmentation in the human brain, eLife 11 (2022) e77430. doi:10.7554/eLife.77430.
[4] Y. Zhao, HP-GSBS: High-performance greedy state boundary search, Zenodo, version 0.2.0 (2026). doi:10.5281/zenodo.23422148.
URL https://github.com/JustinZHAO-05/HP-GSBS/tree/v0.2.0
[5] C. Baldassano, Sherlock data for OHBM, dataset. CC BY 4.0 (2020). doi:10.6084/m9.figshare.12436955.v1.
[6] J. Chen, Y. C. Leong, C. J. Honey, C. H. Yong, K. A. Norman, U. Hasson, Shared memories reveal shared structure in neural activity across individuals, Nature Neuroscience 20 (2017) 115–125. doi:10.1038/nn.4450.
[7] B. L. Welch, The generalization of ‘Student’s’ problem when several different population variances are involved, Biometrika 34 (1–2) (1947) 28–35. doi:10.1093/biomet/34.1-2.28.
[8] C. R. Harris, K. J. Millman, S. J. van der Walt, R. Gommers, P. Virtanen, D. Cournapeau, et al., Array programming with NumPy, Nature 585 (2020) 357–362. doi:10.1038/s41586-020-2649-2.
[9] P. Virtanen, R. Gommers, T. E. Oliphant, M. Haberland, T. Reddy, D. Cournapeau, et al., SciPy 1.0: Fundamental algorithms for scientific computing in Python, Nature Methods 17 (2020) 261–272. doi:10.1038/s41592-019-0686-2.
[10] S. K. Lam, A. Pitrou, S. Seibert, Numba: A LLVM-based Python JIT compiler, in: Proceedings of the Second Workshop on the LLVM Compiler Infrastructure in HPC, ACM, 2015, pp. 1–6. doi:10.1145/2833157.2833162.
[11] A. Paszke, S. Gross, F. Massa, A. Lerer, J. Bradbury, G. Chanan, et al., PyTorch: An imperative style, high-performance deep learning library, in: Advances in Neural Information Processing Systems, Vol. 32, 2019. URL https://proceedings.neurips.cc/paper/2019/hash/bdbca288fee7f92f2bfa9f7012727740-Abstract.html
[12] P. Tillet, H. T. Kung, D. Cox, Triton: An intermediate language and compiler for tiled neural network computations, in: Proceedings of the 3rd ACM SIG-
PLAN International Workshop on Machine Learning and Programming Languages, ACM, 2019, pp. 10–19. doi:10.1145/3315508.3329973.
[13] J. Madsen, N. Kuppa, L. C. Parra, The Brain, Body, and Behavior Dataset (BBBD): Multimodal recordings during educational videos, Scientific Data 13 (2026) 920. doi:10.1038/s41597-026-07215-1.
[14] J. D. Hunter, Matplotlib: A 2D graphics environment, Computing in Science & Engineering 9 (3) (2007) 90–95. doi:10.1109/MCSE.2007.55.
[15] Y. Zhao, Y. Ji, Hp-gsbs: Softwarex reproducibility materials, Zenodo, version 1.0.1 (2026). doi:10.5281/zenodo.23457342.
URL https://github.com/JustinZHAO-05/HP-GSB-S-SoftwareX-Reproducibility
Y. Zhao and Y. Ji
Supplementary Material
HP-GSBS: Accelerating greedy state boundary search with reusable interval statistics
Yanzhe Zhao, Yongzhang Ji
School of Future Technology, Tianjin University, Tianjin, China
Faculty of Psychology, Southwest University, Chongqing, China
*Correspondence: justinzhaoyz@outlook.com
S1 Interval decomposition and candidate reuse
The target is the matching objective used by GSBS [1, 2]. Let be the spatial centering operator, , and . For an interval of length , its mean pattern is . The contribution to the mean spatial correlation is
Define and . Because
the length factor cancels, giving
The identity applies to nonconstant spatial state means. It preserves the distinction between row-wise spatial standardization in GSBS and any preprocessing applied before the matrix reaches the software.
The full score is additive over intervals. A single boundary replaces one interval by two; a double boundary replaces it by three. HP-GSBS reuses all unaffected contributions. In a local search block of length , scores are multiplied by to reproduce the original local normalization. The CPU implementation computes prefix differences in bounded tiles. PyTorch constructs interval scores through batched Gram products and recomputes short-interval differences directly; Triton fuses the prefix differences, dot product and norm.
Streaming reduction preserves candidate order and the original blockwise domain. The unscored sentinel, first-maximum rule and nonfinite-score handling are explicitly tested against the reference implementation. Candidate proposals maximize the matching score; the subsequent single-versus-double decision uses t-distance. Refinement deletes and reinserts boundaries sequentially, retaining their insertion labels. In a double insertion, adjacent state-count slots can share a partition; the last accepted partition may contain states. The full arrays retain this indexing.
S2 T-distance from sufficient statistics
Let denote row-standardized data with its residual row means removed, matching the centering in numpy.cov. Correlations are . Let be the state label and .
S1
Y. Zhao and Y. Ji
Table S1: Principal computational costs. is the number of legal candidates, a searched block length, the prefix chunk size and the current state count. Costs describe the named operation rather than a universal complete-fit bound.
| Operation | Reference-style calculation | HP-GSBS calculation |
|---|---|---|
| One candidate score | Reconstruct and normalize template | Full-Q lookup; prefix mode |
| Interval precomputation | Repeated within candidates | time, table |
| Double-score storage | score array | Bounded running summary; legal candidates still visited |
| Fixed-partition TD | Scan pair structure | rectangle queries after endpoints are obtained |
| Feature-moment TD | Pairwise time matrix | arithmetic, with |
| Full output history | Same required boundary history |
The two distributions are
Only these eligible upper-triangular pairs enter the score. For either distribution, the sufficient statistics are count , sum and squared sum . They give
This is the Welch statistic [3] used as the GSBS partition contrast. No inferential -value is used to accept boundaries.
Two-dimensional prefixes
The stable backend builds zero-padded two-dimensional prefixes of the valid-pair indicator, masked correlation matrix and squared matrix. Four array references give the sum in any rectangle. Within-state rectangles and adjacent-state rectangles assemble the six statistics. Constructing interval endpoints from a boundary vector costs ; the rectangle queries then cost . Small-sample handling follows the original implementation. Near-zero variances and ambiguous single/double comparisons invoke the reference calculation.
Feature moments for long inputs
The optional low-memory route works in feature space. With , an interval has summaries
Before short-lag exclusion, its within-state statistics are
For distinct adjacent intervals , the cross statistics are
S2
Y. Zhao and Y. Ji
Pairs with are subtracted from the relevant distribution. The implementation retains state summaries and bounded short-band caches, rather than a time-by-feature-by-feature prefix. Candidate scoring uses raw-input and standardized-input time prefixes, with at most working arrays. Boundary-history output still contributes storage.
Moment differences can lose precision when correlations are nearly constant. The implementation uses bounded tiled two-pass pair statistics for risky cases and conservatively refuses unresolved nearly degenerate results. This is an experimental execution option; Full-Q/Prefix2D remains the fast default for the ordinary high- inputs evaluated here.
S3 Execution interfaces and numerical scope
The stable configuration combines FP64, Full-Q, streaming candidates and Prefix2D t-distance. CPU, PyTorch CUDA and Triton share this controller. An optional independent input supplies t-distance data while continues to determine candidates and state patterns.
Near-tied candidate scores are reevaluated with the original expression. Such guards preserve the measured decision paths, while practical tolerances remain distinct from an error bound over all floating-point inputs. Spatially constant rows and nonfinite inputs are rejected; the documented handling of ill-conditioned but otherwise valid matrices follows the reference pathway. Resource budgets limit candidate enumeration, original-expression reevaluation, workspace and tiled pair evaluation. Budget refusal does not change the candidate domain or scientific parameters.
Table S2: Released functionality and optional extensions.
| Mode | Status | Role |
|---|---|---|
| FP64 Full-Q + Prefix2D, three backends | Stable | Default numerical path; sequential search and refinement |
| Raw-prefix + feature moments | Experimental | CPU low-memory option with guarded numerical refusal |
| Selective Triton resident candidates | Experimental | Device reduction for selected large candidate domains |
| FP32 Incremental TD; no-Q GPU prototypes | Experimental Research | GPU t-distance differs from strict FP64 comparisons Transactional partition updates and component-level GPU studies; not public complete-fit defaults |
Saved results include the full boundary history, t-distance curve, selected states, state patterns and strengths. Batch execution processes recordings independently. GPU groups use compatible shapes and resource settings; CPU workers parallelize whole recordings. Resume requires both successful output and matching versioned execution identity. Historical results remain readable after a version change, while rerunning the new implementation uses a new output directory.
Reusable research workflow
The executable scripts/research_workflow.py generates a small prepared input, fits it on CPU, retrieves boundaries and t-distance, saves and reloads a versioned result, and processes two recordings independently. The main-text GPU example uses the same result interface. CPU multiprocessing is configured through GSBSConfig(n_jobs=...); on platforms using spawn, calls belong inside a main guard.
For a recording collection, the released command-line interface accepts a task manifest:
python -m hpgsbs fit-batch tasks.json --backend cpu-fast
--workers 4 --output outputs
S3
Y. Zhao and Y. Ji
The manifest records input paths and scientific configuration. Results are written atomically and completed entries are reused when their execution identity matches. The same command can therefore resume an interrupted collection; a change of software version, input or configuration requires the corresponding new execution identity. Exact manifest fields and examples are provided in the versioned software documentation [4].
S4 Experimental design and numerical comparisons
Controlled paired benchmark
Seven unique configurations were evaluated with seeds 20261017 and 20261018. The centre , , is reused in each one-factor series. Gaussian means were generated as an matrix, followed by a Gaussian noise matrix scaled by 0.8. Eight contiguous states have boundaries from rounded equally spaced endpoints. The first features are retained. Thus feature subsets are nested, and the comparison reuses identical inputs. The 14 configuration–seed cases contain ten distinct input matrices; seed reuse also couples comparisons across conditions.
Each official observation times construction and GSBS.fit(showProgressBar=False). Import and numerical initialization used a separate short input. Each HP observation has one untimed warm-up and three timed calls to the released public API. The route ordering rotates by configuration and seed. GPU calls are synchronized before and after timing. Validation and serialization occur outside the timed interval. In total, 14 official fits and 126 timed HP fits were collected, plus 42 HP warm-ups. All 168 HP outputs passed the prescribed comparisons; no configuration was removed.
For input i, backend b and repetitions r, define
Runtime summaries are medians of the two per-input observations, and speedups are medians of the two paired ratios. Whiskers span the two observations. They represent observed ranges, not confidence intervals. The official implementation has one timed observation per input; the optimized routes have three. Tables S3–S5 retain this distinction. The data bundle includes all 140 timed observations.
Mechanism illustration and data provenance
Figure 1 uses the public Sherlock fMRI dataset [5, 6]. The input is the mean angular-gyrus response over 16 participants, restricted to the first 120 TRs (TR = 1.5 s). Fitting uses all 4,230 voxels; 64 voxels are displayed in the activity heatmap. The supplied interval and correlation matrices are derived from this input, with smaller subsets used to explain rectangle queries. The complete symmetric correlation matrix is displayed for interpretation; the temporal mask and eligible upper-triangular pairs define the sufficient statistics actually counted. Thus the interval-template table Q and the correlation prefixes have different meanings despite their related matrix displays.
The saved illustration uses HP-GSBS 0.2.0 CPU, FP64, , , finetune=1, and block size 50. Supplied numerical checks compare its output with statesegmentation 0.0.6. The three backend icons explain the software architecture; cross-backend evidence is provided by the synthetic and EEG comparisons. Derived arrays, the search trace, attribution and the parity report accompany the figure source.
S4
Y. Zhao and Y. Ji
Illustrative signal and EEG provenance
The main illustrative signal uses seed 19, four 16-feature Gaussian means repeated for 20 samples each, and noise with standard deviation 0.05. Its 80 samples have generating boundaries 20, 40 and 60. All four routes select these boundaries, with the exact state-count and numerical differences shown in Fig. 2 of the main article. Supplementary Table S10 reports the other previously recorded seed/noise cases, preserving the distinction between implementation agreement and recovery of generating boundaries.
The EEG evidence uses four study-preprocessed, frozen inputs derived from BBBD [7], sampled at 5.12 Hz. The original arrays are stored as float32 and converted to FP64 for fitting. Their feature counts are 64, 32 (frontal), 64 and 64; original recording-specific values and are retained. No additional filtering or source reconstruction was performed for this manuscript.
The saved-output comparison for recording 1 uses its complete official reference. Recordings 2–4 use CPU outputs previously checked against official results, providing a reference chain for the GPU comparisons. Their CPU self-comparisons are identity checks. The supplied release evidence additionally records all three v0.2 backends against the frozen full outputs. Full boundary history, final state count, t-distance, state patterns and strengths are checked. Table 2 of the main article retains all four historical full-output comparisons.
Figure 3 uses the newly supplied frozen input and four complete saved outputs for Recording 1 (1336 × 64). The entire input is used for segmentation; the local window is selected by fixed sample indices 617–718, corresponding to plotted bin edges 120.5078125–140.4296875 s. Input values are already standardized per channel. Heatmap colours are clipped to ±3 for display without changing the analysis arrays. Correlation uses all 64 channels and is displayed symmetrically, with selected state blocks clipped at the window edges. The full-record state sequence and local boundaries all come from the saved selected partition. Evaluated t-distance indices are 2–131; the uncomputed padded slot is omitted. All four outputs select 126 states and have identical complete boundary histories and state patterns. Maximum absolute t-distance differences from the official output are 2.43361 × 10−13 (CPU) and 9.59233 × 10−14 (both GPU routes). The figure is regenerated directly from these files without fitting the excerpt.
Numerical criteria
Boundary arrays and selected state counts use exact equality. T-distance, state patterns and strengths use atol = rtol = , with shapes and nonfinite masks checked separately. The maximum absolute t-distance difference in the controlled benchmark is ; state-pattern and strength differences are zero. The illustrative signal was compared at the strict per-refinement-move level. Missing required trace fields cause the strict comparison to fail.
Environment
The controlled experiment ran on an AMD Ryzen 7 7840H and NVIDIA RTX 4050 Laptop GPU (6 GB) under Ubuntu 22.04/WSL2, using Python 3.10.12, NumPy 2.2.6, SciPy 1.15.3, Numba 0.68.0, PyTorch 2.11.0+cu128, Triton 3.6.0 and CUDA runtime 12.8. BLAS, Numba and PyTorch intra-/inter-operation thread counts were one, and TF32 was disabled. The pre-existing component, memory and throughput measurements below used the documented release-development environment on the same laptop family. They are reported separately from the new paired benchmark.
S5
Y. Zhao and Y. Ji
S5 Complete controlled-benchmark tables
Table S3: Complete-fit runtime in seconds: median [minimum, maximum] across two input seeds. Each HP value is first summarized over three timed runs.
| Official | CPU | PyTorch | Triton | |||
|---|---|---|---|---|---|---|
| 256 | 32 | 20 | 11.234 [10.144, 12.324] | 0.073 [0.073, 0.073] | 0.068 [0.065, 0.070] | 0.064 [0.063, 0.064] |
| 512 | 32 | 20 | 64.667 [58.876, 70.458] | 0.142 [0.138, 0.146] | 0.081 [0.075, 0.087] | 0.099 [0.086, 0.111] |
| 768 | 32 | 20 | 189.610 [169.973, 209.247] | 0.251 [0.226, 0.277] | 0.110 [0.105, 0.116] | 0.131 [0.124, 0.138] |
| 512 | 8 | 20 | 53.323 [52.454, 54.192] | 0.122 [0.120, 0.123] | 0.081 [0.077, 0.085] | 0.075 [0.073, 0.076] |
| 512 | 64 | 20 | 79.365 [79.157, 79.573] | 0.153 [0.149, 0.156] | 0.077 [0.073, 0.082] | 0.100 [0.094, 0.106] |
| 512 | 32 | 10 | 55.603 [50.179, 61.028] | 0.118 [0.117, 0.120] | 0.065 [0.063, 0.068] | 0.076 [0.069, 0.082] |
| 512 | 32 | 40 | 75.652 [69.669, 81.635] | 0.165 [0.160, 0.170] | 0.111 [0.106, 0.116] | 0.126 [0.126, 0.126] |
Table S4: Paired speedups (times): median [minimum, maximum] of the two same-input ratios. Ratios use unrounded values before summarization.
| CPU | PyTorch | Triton | |||
|---|---|---|---|---|---|
| 256 | 32 | 20 | 154.0 [139.5, 168.5] | 166.9 [144.1, 189.7] | 177.0 [158.6, 195.4] |
| 512 | 32 | 20 | 454.1 [425.1, 483.2] | 794.8 [782.0, 807.6] | 675.0 [528.2, 821.9] |
| 768 | 32 | 20 | 770.1 [613.5, 926.6] | 1729.7 [1470.9, 1988.4] | 1458.3 [1235.0, 1681.7] |
| 512 | 8 | 20 | 438.5 [427.1, 450.0] | 662.2 [616.9, 707.4] | 715.7 [690.1, 741.2] |
| 512 | 64 | 20 | 520.5 [508.8, 532.2] | 1027.7 [967.7, 1087.7] | 797.3 [751.1, 843.5] |
| 512 | 32 | 10 | 469.9 [429.9, 509.8] | 854.8 [740.3, 969.4] | 735.1 [723.7, 746.6] |
| 512 | 32 | 40 | 457.6 [434.4, 480.7] | 683.6 [599.8, 767.4] | 599.3 [551.7, 646.9] |
Table S5: Per-input complete-fit observations (seconds). HP columns are the median of three timed runs; the official column is one timed run.
| Seed | Official | CPU | PyTorch | Triton | |||
|---|---|---|---|---|---|---|---|
| 256 | 32 | 20 | 20261017 | 12.3239 | 0.0731 | 0.0650 | 0.0631 |
| 256 | 32 | 20 | 20261018 | 10.1440 | 0.0727 | 0.0704 | 0.0639 |
| 512 | 32 | 20 | 20261017 | 70.4578 | 0.1458 | 0.0872 | 0.0857 |
| 512 | 32 | 20 | 20261018 | 58.8762 | 0.1385 | 0.0753 | 0.1115 |
| 768 | 32 | 20 | 20261017 | 209.2472 | 0.2258 | 0.1052 | 0.1244 |
| 768 | 32 | 20 | 20261018 | 169.9726 | 0.2770 | 0.1156 | 0.1376 |
| 512 | 8 | 20 | 20261017 | 52.4543 | 0.1228 | 0.0850 | 0.0760 |
| 512 | 8 | 20 | 20261018 | 54.1916 | 0.1204 | 0.0766 | 0.0731 |
| 512 | 64 | 20 | 20261017 | 79.5733 | 0.1564 | 0.0822 | 0.1059 |
| 512 | 64 | 20 | 20261018 | 79.1572 | 0.1487 | 0.0728 | 0.0938 |
| 512 | 32 | 10 | 20261017 | 61.0280 | 0.1197 | 0.0630 | 0.0817 |
| 512 | 32 | 10 | 20261018 | 50.1787 | 0.1167 | 0.0678 | 0.0693 |
| 512 | 32 | 40 | 20261017 | 81.6352 | 0.1698 | 0.1064 | 0.1262 |
| 512 | 32 | 40 | 20261018 | 69.6693 | 0.1604 | 0.1162 | 0.1263 |
S6
Y. Zhao and Y. Ji
S6 Complementary performance and recovery results
Historical extended workloads
Table S6 preserves the published v0.2.0 release comparison [8]. Earlier official timings and later release-wheel timings were collected in separate sessions on the same documented machine. Synthetic workloads use the median of three timed complete fits after warm-up; the EEG entry uses one complete fit per route. Complete-fit timing includes computation and required transfers, with validation and file output outside the timed interval. These observations extend the workload range of the main paired experiment and remain a separate evidence series.
Table S6: Historical extended workload performance: complete-fit seconds, with official/HP ratios in parentheses. Ratios use unrounded observations.
| Workload | Official | CPU | PyTorch | Triton | ||
|---|---|---|---|---|---|---|
| Small | 20 | 48.0 | 0.103 (467x) | 0.075 (636x) | 0.057 (847x) | |
| Medium | 30 | 349.9 | 0.317 (1,105x) | 0.098 (3,556x) | 0.098 (3,577x) | |
| Large | 40 | 2213.5 | 0.868 (2,550x) | 0.172 (12,903x) | 0.213 (10,377x) | |
| XL | 50 | 5011.3 | 1.952 (2,567x) | 0.363 (13,816x) | 0.456 (10,988x) | |
| EEG | 131 | 6115.4 | 1.610 (3,798x) | 0.853 (7,165x) | 0.838 (7,299x) |
The XL PyTorch ratio is approximately 13,816 times when recomputed from the archived unrounded values. The corresponding 5,011 s to 0.363 s comparison illustrates the practical value of reuse for larger analyses. Main-text speedup conclusions retain the same-input paired design.
Ablation and memory
The ablation uses one frozen EEG input (, , , statewise detection, sequential refinement and block size 50). Its materialized baseline already uses the earlier Full-Q optimization. The successive changes isolate streaming reduction, window refinement and active-block reuse, rather than repeating the comparison with the unoptimized official implementation.
Table S7: CPU ablation: three timed fits after one warm-up, seconds. All compared outputs agree.
| Configuration | Median | Minimum | Maximum |
|---|---|---|---|
| Materialized | 3.3638 | 3.2950 | 3.3870 |
| Streaming | 1.8035 | 1.7705 | 1.9462 |
| Streaming + window | 1.6014 | 1.5863 | 1.6605 |
| Streaming + window + cache | 1.4288 | 1.4275 | 1.4291 |
The separate memory comparison uses a input, single-boundary search, no refinement, block size zero and . The Full-Q/materialized path takes 9.754 s and peaks at 1598.0 MiB process RSS; raw-prefix/feature-moments takes 0.110 s and peaks at 190.6 MiB. These are process totals, including runtime state, sampled every 5 ms. Their timing ranges are 9.384–10.432 s and 0.105–0.113 s.
The long-input series changes both and and records a restricted search configuration. The run selects 15 states, and its final 16-state partition is also checked. Full statewise search retains a quadratic double-candidate domain, so the released resource budget can reject that larger computation without altering its scientific parameters.
S7
Y. Zhao and Y. Ji
Table S8: Long-input low-memory measurements under the same single-boundary/no-refinement configuration. Each median uses three timed runs. The final column is the maximum selected/final-partition TD difference from the tiled oracle.
| Median (s) | Range (s) | Peak RSS (MiB) | Max. TD difference | |
|---|---|---|---|---|
| 0.1077 | 0.1074–0.1079 | 191.1 | ||
| 0.1843 | 0.1724–0.1850 | 204.5 | ||
| 0.3745 | 0.3652–0.4073 | 247.5 | ||
| 1.4439 | 1.4177–1.4842 | 469.5 |
Batch throughput
Short workloads use independent synthetic inputs of size , , . High-K tasks use repeated copies of one EEG input, , . Each configuration has one warm-up batch and three timed batches. Timings include pool construction, serialization where applicable, fitting and synchronization; validation occurs afterwards. Fits/minute is computed per batch, then summarized. CPU batches have 32 short tasks or eight high-K tasks; the GPU batch count is explicit. Table S9 contains the selected configurations used to interpret the main figure, including larger GPU batches. Admission skips are not encoded as zero throughput.
Table S9: Batch throughput: median [minimum, maximum], completed fits/minute.
| Workload | Backend | Workers | Batch | Fits/minute |
|---|---|---|---|---|
| Small | CPU | 1 | 32 | 274.3 [269.4, 282.9] |
| Small | CPU | 2 | 32 | 839.6 [815.0, 843.6] |
| Small | CPU | 4 | 32 | 1362.2 [1328.0, 1419.7] |
| Small | CPU | 8 | 32 | 1766.8 [1638.0, 1781.1] |
| Small | PyTorch | 1 | 1 | 646.7 [641.3, 730.3] |
| Small | PyTorch | 1 | 8 | 1418.4 [1383.6, 1425.6] |
| Small | PyTorch | 1 | 32 | 1459.9 [1378.7, 1538.1] |
| Small | PyTorch | 1 | 64 | 1399.3 [1398.8, 1484.2] |
| Small | Triton | 1 | 1 | 658.6 [652.8, 660.1] |
| Small | Triton | 1 | 8 | 1451.5 [933.0, 1654.5] |
| Small | Triton | 1 | 32 | 1529.9 [1384.9, 1598.3] |
| Small | Triton | 1 | 64 | 1340.3 [1313.8, 1358.1] |
| High-K | CPU | 1 | 8 | 24.4 [24.0, 24.9] |
| High-K | CPU | 2 | 8 | 74.3 [74.1, 74.7] |
| High-K | CPU | 4 | 8 | 125.7 [124.5, 129.4] |
| High-K | CPU | 8 | 8 | 154.9 [149.0, 161.9] |
| High-K | PyTorch | 1 | 1 | 42.9 [42.0, 47.9] |
| High-K | PyTorch | 1 | 4 | 40.5 [38.8, 40.7] |
| High-K | PyTorch | 1 | 8 | 41.2 [40.4, 41.5] |
| High-K | Triton | 1 | 1 | 41.9 [40.5, 45.6] |
| High-K | Triton | 1 | 4 | 44.6 [44.2, 45.1] |
| High-K | Triton | 1 | 8 | 43.1 [42.2, 43.3] |
S8
Y. Zhao and Y. Ji
Generating-boundary recovery
Table S10: Previously recorded synthetic recovery examples, all with exact implementation agreement. The generating boundaries are 20, 40 and 60. Precision and recall compare selected boundaries with those exact indices.
| Seed | Noise SD | Selected K | Selected boundaries | Precision | Recall |
|---|---|---|---|---|---|
| 12 | 0.05 | 3 | 20, 40 | 1.00 | 0.67 |
| 12 | 2.00 | 2 | 42 | 0.00 | 0.00 |
| 19 | 0.05 | 4 | 20, 40, 60 | 1.00 | 1.00 |
| 19 | 2.00 | 6 | 3, 7, 20, 41, 58 | 0.20 | 0.33 |
These examples show how noise and state-count selection affect GSBS outputs while the optimized implementation follows the same decisions. The main figure uses the existing seed-19 low-noise example to illustrate the interface and numerical agreement.
S7 Reproducibility package
The public reproducibility package (version 1.0.1) is archived at doi:10.5281/zenodo.23457342 [9] and maintained at https://github.com/JustinZHAO-05/HP-GSBS-SoftwareX-Reproducibility. Original reproduction code is MIT licensed; data, derived examples, figures and documentation retain CC BY 4.0 attribution, with data sources and processing described in the repository.
The accompanying package separates numerical data from their visualization. paired_timed_runs.csv contains all timed observations; paired_per_input.csv, paired_runtime.csv and paired_speedup.csv give successive summaries. paired_inputs.csv records shapes, seeds and input hashes. synthetic_figure_data.npz contains the illustrative input and extracted backend outputs; the t-distance curves are also available as CSV. The remaining CSVs contain the ablation, memory, throughput and EEG aggregate values used in the article.
Run pythonscripts/make_figures.py to rebuild Figs. 1–5 without refitting. The figure_sources directory contains the final plotting scripts, derived Sherlock matrices, and Recording 1 input and saved EEG outputs. The historical extended-workload CSV and links to the published release provenance accompany the new table. generate_inputs.py regenerates the controlled synthetic matrices and checks their supplied hashes. run_paired_benchmark.py implements the recorded four-route measurement protocol for a new machine and writes into a new directory. Its new measurements are separate from the supplied observations. A small CPU-compatible consistency example is included. Exact timings depend on the execution environment, while the deterministic inputs and numerical comparisons can be independently checked.
Software is fixed to HP-GSBS 0.2.0 [4]. The new paired and illustrative experiments use the released package. Complementary ablation, memory and throughput data come from the documented pre-release implementation that established these optimizations; later changes concerned guarded execution, scheduling and release metadata. Their original scopes remain explicit. The supplied private paper archive was used as an author-provided source; publication of this supplementary package does not require public access to that private repository. Recording 1 is supplied as the frozen analysis matrix and saved outputs used in Fig. 3. The other three EEG cases remain aggregate comparisons. Figure sources retain data attribution and recorded input provenance; they do not require access to the private repository for plotting.
S9
Y. Zhao and Y. Ji
References
[1] L. Geerligs, M. van Gerven, U. Güçlü, Detecting neural state transitions underlying event segmentation, NeuroImage 236 (2021) 118085. doi:10.1016/j.neuroimage.2021.118085.
[2] L. Geerligs, D. Gözükara, D. Oetringer, K. L. Campbell, M. van Gerven, U. Güçlü, A partially nested cortical hierarchy of neural states underlies event segmentation in the human brain, eLife 11 (2022) e77430. doi:10.7554/eLife.77430.
[3] B. L. Welch, The generalization of ‘Student’s’ problem when several different population variances are involved, Biometrika 34 (1–2) (1947) 28–35. doi:10.1093/biomet/34.1-2.28.
[4] Y. Zhao, HP-GSBS: High-performance greedy state boundary search, Zenodo, version 0.2.0 (2026). doi:10.5281/zenodo.23422148.
URL https://github.com/JustinZHAO-05/HP-GSBS/tree/v0.2.0
[5] C. Baldassano, Sherlock data for OHBM, dataset. CC BY 4.0 (2020). doi:10.6084/m9.figshare.12436955.v1.
[6] J. Chen, Y. C. Leong, C. J. Honey, C. H. Yong, K. A. Norman, U. Hasson, Shared memories reveal shared structure in neural activity across individuals, Nature Neuroscience 20 (2017) 115–125. doi:10.1038/nn.4450.
[7] J. Madsen, N. Kuppa, L. C. Parra, The Brain, Body, and Behavior Dataset (BBBD): Multimodal recordings during educational videos, Scientific Data 13 (2026) 920. doi:10.1038/s41597-026-07215-1.
[8] Y. Zhao, HP-GSBS v0.2.0: historical official comparison and release-wheel benchmarks, Versioned software benchmark record, archived numerical observations are included in the accompanying reproducibility package (2026).
[9] Y. Zhao, Y. Ji, Hp-gsbs: Softwarex reproducibility materials, Zenodo, version 1.0.1 (2026). doi:10.5281/zenodo.23457342.
URL https://github.com/JustinZHAO-05/HP-GSBS-SoftwareX-Reproducibility
S10