Manuscript Offprint
arXiv:2610.23590Boundary Detection for High-Dimensional Point Clouds
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
Abigail Hickok
Department of Mathematics
Columbia University
New York, NY, USA
Osama Al Dalahmah
Department of Pathology and Cell Biology
Columbia University
New York, NY, USA
Valerio Galanti
Department of Computer Science
Columbia University
New York, NY, USA
Andrew J. Blumberg
Department of Mathematics,
Department of Computer Science,
Irving Institute for Cancer Dynamics
Columbia University
New York, NY, USA
ABSTRACT
We introduce two new methods for boundary detection in high-dimensional point cloud data, intended to work in situations with non-uniform density, high ambient dimension, and substantial noise. Our first method fits a separating hyperplane on local neighborhoods after doing local dimension reduction—this method works best when one can reliably estimate the intrinsic dimension of the data. Our second method measures the directional uniformity of local neighborhoods, and has the best overall performance on synthetic data. In addition to pointwise numerical boundary scores, our algorithms yield an estimated normal vector at each boundary point. We validate our methodology on synthetic data as well as two real examples: we analyze spatial transcriptomics data, where we show that we can detect the boundary of a tumor, and we also study LLM activation geometry.
1 INTRODUCTION
The manifold hypothesis specifies that point cloud data is sampled from a distribution supported on a low-dimensional manifold. A natural variant of this setup is to assume that the support is instead a manifold with boundary. In this case, determining the location of the boundary and a normal vector to it become fundamental questions. Algorithms to determine the boundary have many applications. For example, in spatial transcriptomics data, each point on a grid has a gene expression vector that lies in for n approximately 20000. Detecting boundary regions in genomic space allow us to determine qualitative changes in underlying tissue, for example transitions from cancerous tumor regions to healthy cells. Another application of interest is to study the geometry of LLM activations. Recent mechanistic interpretability work has discovered that residual-stream activations often lie on curved submanifolds rather than linear subspaces (Gurnee & Tegmark, 2024; Engels et al., 2025; Gurnee et al., 2026; Berdnikov & Liokumovich, 2026). Model behavior can be influenced by adding a “steering” vector at intermediate activations (Turner et al., 2024; Panickssery et al., 2024), but these interventions work best when one is able to stay on the underlying manifold (Wurgaft et al., 2026). Knowing the boundary points as well as having estimated boundary normals is useful for steering interventions and other interpretability problems. More broadly, boundary detection can be used for general-purpose methods such as clustering (Wang et al., 2018; Averbuch-Elor et al., 2020).
Our hyperplane method works the best among all tested methods when the local dimension can be reliably estimated. When the estimated dimension m is larger than the true dimension, it finds the correct boundary of the data as though it were m-dimensional. Our directional uniformity method is more robust when noise levels prevent accurate dimension estimates.
The hyperplane method is mathematically grounded by theorems proving that boundary points can be reliably distinguished from interior points in a way that scales well with intrinsic dimension. We empirically validate both methods on synthetic data.
Finally, we show that our methodology is effective on spatial transcriptomics data for identifying a tumor boundary, and we also apply it to find the boundary of LLM activations for the character-counting manifold of (Gurnee et al., 2026) for open-weight models.
We have released the source code and scripts for reproducing our figures and experiments on github: https://github.com/aghickok/boundary_detection.
1.2 RELATED WORK
There are several boundary-detection methods that rely on the fact that boundary points have lower density than interior points. BORDER (Xia et al., 2006) counts the number of “reverse k nearest neighbors” (RkNN), i.e., the number of points for which the query point is a kNN. Boundary points tend to have fewer kNNs. Averbuch-Elor et al. (2020) and Du et al. (2021) also use reverse kNNs for boundary detection, as an intermediate step towards clustering. In more detail, Averbuch-Elor et al. (2020) and Du et al. (2021) calculate , where is a Gaussian or Cauchy kernel, respectively. Reverse unreachability (RU) (Li et al., 2018) is different; it uses the representation matrix from Roweis & Saul (2000) to approximate each point as a linear combination of its neighbors, and then reverse unreachability is defined as . All of these methods perform poorly when the point cloud has non-uniform density.
Some methods are only designed to be used for very low-dimensional data. The direction centrality measure (Peng et al., 2022) is defined for data in and the level-set method (Ding et al., 2015) was only applied to 2D data. Both methods can be theoretically generalized to higher dimensions, but scale poorly with ambient dimension and are not practical for data that is more than two dimensional.
The last class of methods uses geometric structure to detection boundaries in data of any dimension. Border Edge Pattern Selection (BEPS) (Li & Maguire, 2011), CO (Wang et al., 2018), and LoDD (Peng et al., 2025) all start by projecting the nearest neighbors to the unit sphere centered at the query point . Let and define . BEPS is similar to our hyperplane method—the BEPS score is the percentage of neighbors on the positive side of the hyperplane orthogonal to . It is far less robust to noise than either of our methods, though, because the direction of the vector is sensitive to noisy perturbations off the manifold, especially on interior points where .
The CO score (Wang et al., 2018) uses the same vector but scales by density and measures the alignment between neighbors. At query point , the score is , where is a “mass” term that is high in regions with low density. Like the other density-based methods, CO performs poorly on data with non-uniform density.
The LoDD score is , where is the set of eigenvalues of the covariance matrix for the centered, normalized neighbor vectors and is a hyperparameter that is set to .5 in Peng et al. (2025) and in our experiments in this paper. The LoDD score has a maximum of 1 that is achieved when the eigenvalues are equal and sum to 1. It is higher for interior points because is uniformly distributed on the -dimensional sphere. LoDD has the strongest overall performance of all the existing methods we tested in the literature, but it is less robust than ours to noise, especially in high ambient dimensions. Unlike our methods (or BEPS or CO), LoDD does not produce normal vectors at each point—just pointwise boundary scores.

(a)
(b)
(c)
Figure 1: Hyperplane optimization on points sampled from half and full balls. Accuracy is the percentage of points that lie on the positive side of the hyperplane orthogonal to .
2 HYPERPLANE METHOD FOR BOUNDARY DETECTION
The idea of our hyperplane (HP) boundary-detection algorithm, detailed in Algorithm 1, is that if is a boundary point on an -dimensional manifold, then it has a neighborhood that is diffeomorphic to an -dimensional half ball. A half space is defined by a hyperplane in . If is a boundary point, then it is possible to find a hyperplane such that most its neighbors lie on the same side of the hyperplane. On the other hand, if is an interior point, then any hyperplane will split the neighborhood in half, with roughly half the points on one side and half on the other side.
We assign each point a boundary score that is the percentage of its neighborhood lying on the same side of an “optimal” hyperplane. Boundary points have scores near 1, and manifold points have scores near .5. Near a transverse intersection of manifolds, the score is usually higher than .5 but lower than 1—for example, near a transverse intersection of two manifolds, the score is near .75. (See Figure 6, for example.) The algorithm steps are described below.
2.1 THE ALGORITHM
-
Local PCA: For each point , we use local PCA to reduce the dimension of its local neighborhood , where is a parameter that controls the size of the neighborhood. If the dimension of the manifold is known, then we reduce to dimensions; otherwise, we use a spectral gap threshold condition. Let be the neighborhood after dimension reduction and after centering so that is mapped to .
-
Hyperplane optimization: We solve for an “optimal” hyperplane that best separates the data points onto a single side of the hyperplane. Every hyperplane is determined by an orthogonal vector with norm . A point lies on the “positive” side of the hyperplane if . A hyperplane is good if most of the points lie on the positive side of the hyperplane. To formulate this, we solve the optimization problem
The function is proportional to the mean (signed) distance to the hyperplane, and the constraint normalizes the sum so that it cannot be arbitrarily large. By the method of Lagrange multipliers, the solution to our optimization problem is .
- Boundary score: The boundary score for point is the percentage of neighboring points that lie on the positive side of the hyperplane. Boundary and interior points have scores close to 1 and .5, respectively.
As an alternative to our hyperplane optimization step, one could instead aim to maximize the number of points such that . In contrast, maximizing encourages but does not force points to lie on the positive hyperplane side. The advantage of our formulation is that it has a fast, closed-form solution. Algorithm 1 runs in about 1s for points in .
For example, suppose a point cloud is sampled from the intersection of the xy plane and the xz plane in . For a point on the xy plane with small but positive y coordinate, the optimal hyperplane P is one that is parallel to the xz plane with normal vector . The boundary score will be close to .75 because about half the points on the xy plane and all the points on the xz plane will be on the positive side of P.
Algorithm 1 Boundary Detection
Input: Point cloud , neighborhood size , PCA spectral gap threshold (default )
Output: Boundary score for each
1: for all do
2: -nearest neighbors of in
3:
4:
5:
6:
7:
8: end for
9: return
To illustrate the hyperplane optimization step of the algorithm, we sample points from half or full -dimensional balls and calculate . See Figure 1. For each experiment, we define the “accuracy” to be the percentage of points that lie on the positive side of the hyperplane determined by —this is analogous to the boundary score defined previously. When the points are sampled from a half ball—which models the boundary-point case—the accuracy stays close to 1, even for the smallest neighborhood size that we tested (). By contrast, when the points are sampled from a full ball—which models the interior-point case—the accuracy is close to . The gap between interior and boundary points persists as the dimension increases to . This is preliminary evidence that the optimized hyperplane reliably distinguishes between boundary and interior points.
2.2 CONCENTRATION INEQUALITIES FOR THE BOUNDARY SCORES
The theorems below can be used to guide a choice of neighborhood size k given a manifold dimension n, or to pick a threshold on the boundary scores for identifying boundary points. Our goal is to quantify the distribution of boundary scores when x is either an interior point or a boundary point. To do so, we consider the random variable
which counts the number of points that lie on the positive side of the hyperplane determined by . In our theoretical results below, we assume that the points are drawn uniformly at random from either an -dimensional ball (to model the situation where is an interior point) or an -dimensional half ball (to model the situation where is a boundary point). The boundary score behaves similarly to , and we are interested in its probability distribution. The challenge is that the terms in the sum are generally not independent because depends on all , so is not a binomial random variable. Below, we prove that boundary scores for boundary and interior points concentrate near 1 and 1/2, respectively.
Theorem 2.1. Let be points sampled independently and uniformly at random from an n-dimensional ball. Then there are constants , such that for any , we have
for all dimensions n and all .
Theorem 2.2. Let be points sampled independently and uniformly at random from an n-dimensional half ball. For any , we have
3 DIRECTIONAL UNIFORMITY METHOD FOR BOUNDARY DETECTION
Our directional uniformity (DU) method is related to the Rayleigh uniformity test for deciding whether a spherical sample is uniform or not (Mardia & Jupp, 1999). Suppose that for each point x,

Figure 2: The vectors for points (orange) in a local neighborhood of a point (red) within a larger point cloud that is sampled from (left) a thin strip in with noise and (right) a half plane.
we consider a local neighborhood of size . We project each neighbor onto a sphere centered at and calculate the vector . If is a manifold point, then the neighbors are uniformly distributed on the sphere, so . If is a boundary point, then is nonzero and parallel to the boundary normal. We define the boundary score
Note that expected boundary point scores are strictly less than 1 and depend on dimension n.
Algorithm 2 Directional-Uniformity (DU) Boundary Detection
Input: Point cloud , neighborhood size
Output: Boundary score for each
1: for all do
2: -nearest neighbors of in
3:
4:
5: end for
6: return
Robustness-to-noise is the main advantage of Equation (3) instead of simply . The former equation measures the alignment of with its neighbors . Although there is always correlation between and due to the overlap in neighborhoods, there is stronger alignment when is a boundary point because is nonzero.
More importantly, ambient noise can thicken an -dimensional manifold into a higher-dimensional object, and it is challenging for boundary detection methods to distinguish between the boundary of the ground-truth -dimensional manifold and the boundary of the higher-dimensional object; Equation (3) helps to mitigate that. For example, in Figure 2, a 1D horizontal line segment in has noise added so that it is a thin 2D subset. A point at the top (or bottom) of the subset has a neighborhood that is genuinely a half ball, so is as large as it is for a “true” boundary point. However, because it is a thin 2D strip, the points at the bottom of the neighborhood are boundary points on the opposite side. For points at the top and bottom, the vectors point down and up, respectively. Therefore, there are cancellations in Equation (3) so that it is small, even though most of the vectors are large. This correctly signifies that the point is not on the true boundary (the left and right endpoints of the line segment). For comparison, the right panel of Figure 2 shows for points in a neighborhood of a point on the boundary of a half plane. The norm is close to that of the point on the line segment, but is larger. At a fixed neighborhood size and high noise level, Equation (3) is less likely than to flag interior points as boundary points.
4 BOUNDARY DETECTION ON SYNTHETIC DATA
Non-uniform density. Many methods in the literature erroneously detect low-density interior points as boundary points. To test this, we sample points non-uniformly from a 2D disk where

Figure 3: Boundary scores for two synthetic data sets with low noise levels.
there is a low-density region in the interior. For each method, we calculate AUC values (shown in Table 1) for boundary points vs. deep interior points (the low-density region). See Figure 12 for the pointwise scores. RU (Li et al., 2018), BORDER (Xia et al., 2006), and BP (Averbuch-Elor et al., 2020; Du et al., 2021) explicitly rely on the idea that boundary points have lower density, so it is unsurprising that they have AUC values below .5. The CO method (Wang et al., 2018) performs similarly poorly (AUC .447) because of a “mass” term that increases the score at low-density points. The only methods that perform well on the non-uniform-density data set are LoDD, BEPS, our HP method, and our DU method, which all have AUC = 1.
| DU (us) | Hyperplane (us) | LoDD | BEPS | RU | CO | BORDER | BP (Gauss.) | BP (Cauchy) |
|---|---|---|---|---|---|---|---|---|
| 1.000 | 1.000 | 1.000 | 1.000 | 0.474 | 0.447 | 0.474 | 0.425 | 0.436 |
Table 1: Boundary ( ) vs deep-interior ( ) AUC for N = 10,000 points sampled non-uniformly from a 2D disk. In the interior, there is a “well” ( ) where the density is 1/9 that of the density in the outer region ( ). The density increases linearly in between.
Surfaces with non-trivial geometry. For the remainder of Section 4, our primary focus is comparing LoDD (Peng et al., 2025) and BEPS (Li & Maguire, 2011) with our HP and DU methods. We test the four methods on six synthetic data sets with low levels of Gaussian noise; see Figure 3 for the cone and saddle-skewer, and Figure 13 for four more. BEPS performs reasonably well, but it has a high number of false positives (interior points that score as high as boundary points) on three of the surfaces (the cone, Saturn, and the three disks). LoDD struggles with data points that have intrinsic dimension one, such as the skewer in the saddle-skewer. The interior 1D points have LoDD scores that are as low as points near the surface boundaries. (LoDD scores are close to 0 on boundary points and higher on the interior, unlike the other three methods.) HP scores boundary points close to 1, while manifold points have low boundary scores close to .5. Points near (but not on) a transverse intersection of two surfaces have moderate hyperplane boundary scores near .75. Similarly, DU scores are higher at boundary points and lower (close to 0) at interior points. This data set shows that all four methods are reasonably accurate on surfaces with complex topologies and curvature, except that LoDD confuses interior 1D points with boundary points and BEPS is prone to false positives, sometimes confusing isolated interior points for boundary points.
High ambient dimension. In high ambient dimension with low noise, BEPS cannot distinguish between boundary points and interior points, and LoDD scores have high variance on interior points. For example, see Figure 4. BEPS scores are roughly constant across all points, and many interior points have LoDD scores that are as low as boundary-point LoDD scores. In contrast, our HP and DU methods both highlight a clear boundary, scoring interior points much lower, although HP has a small amount of interior noise. A limitation of HP in high ambient dimensions is that it scores self-
The ground-truth disk boundary is the set of points x where . This boundary has measure zero, so zero of the sampled points are on the boundary. Instead, we conservatively define the empirical boundary to be the set of points with . In later sections, we lower this threshold to .95 with justification given in Section C.2, where we also show the results for other threshold choices.

Figure 4: Boundary scores ( , ) on the Henneberg minimal surface embedded in with isotropic Gaussian noise ( ), plotted in .

Figure 5: Analysis of boundary scores on disks embedded in with Gaussian noise (size points, with ).
intersections as high as boundary points. (In lower ambient dimensions, HP assigns score to points near intersections.) For the remainder of this subsection, we focus on HP, DU, and LoDD.
Next, we study 2D disks embedded in ( ) with isotropic Gaussian noise ( ). In Figure 5(a), we calculate AUC values for interior vs. boundary points . Both the hyperplane and DU methods have AUC values near 1 at all , while LoDD's performance degrades as increases. That is, HP and DU perform better than LoDD on point clouds with high ambient dimension.
For each method (excluding BEPS), we measure the strength of the relationship between a point's norm and its boundary score. A good method should score all interior points at an approximately constant value and then monotonically change as one approaches the boundary. For each method we fit a monotonic function to the scores as a function of radius and calculate the coefficient of determination . Figure 5(b) shows that the DU method has the highest value (near 1) at each , while LoDD has the lowest values, reflecting its high variance within the interior of the disk.
High noise levels. At higher levels of noise, local PCA may overestimate the local dimension. This affects HP. If the estimated dimension m is larger than the true manifold dimension n, then HP will
We define the empirical boundary to be the set of points with , and the empirical interior to be the set of points with . We ignore the points with norms in between because their classification is ambiguous. See Section C.2 for more details on how we derived our definitions of interior and boundary points and Figure 20 for AUC values for alternative choices.

Figure 6: Boundary scores on noisy intersecting line segments.

Figure 7: Boundary scores at high noise, for 2D disks ( ) embedded in with Gaussian noise . We use neighborhood size . Boundary and interior points are defined as points with norm > .95 and < .8, respectively, with norm computed in the xy plane.

Figure 8: For points near the boundary of a 2D disk or -ball ( ), we compare the estimated boundary normal with the ground-truth normal . We plot median error and IQR.
find the boundary of it as an m-dimensional object rather than an n-dimensional object. In Figure 6, we show an example where a point cloud is sampled from two intersecting orthogonal line segments with Gaussian noise . At this noise level, with default neighborhood size , local PCA over-estimates the intrinsic dimension—99.1% of points are assigned local dimension 2. HP thus detects the edges of the thickened arms as boundary points, because this is the boundary when the object is treated as 2-dimensional. Increasing the neighborhood size to resolves the issue because at the larger neighborhood size, local PCA correctly estimates dimension 1 at most points except near the intersection. Interestingly, LoDD and BEPS suffer from the same limitation, but increasing the neighborhood size does not help them. DU is able to correctly identify true boundary points at both neighborhood sizes.
In Figure 7, we study each method's boundary-detection performance as we increase the noise level . The point clouds are sampled from 2D disks embedded in with isotropic Gaussian noise. Again, we see that at higher noise levels, HP often misclassifies interior points as boundary points because local PCA overestimates the dimension as 3 instead of 2. An interior point with high coordinate is seen as the “boundary” of the thickened disk. However, if we fix dimension 2 for the local PCA dimension, then HP is able to correctly recover the disk boundary. We plot the AUC values as a function of in Figure 7(a). At the highest noise level ( ), HP with fixed dimension (AUC .969) performs best, followed by DU (AUC .932), then LoDD (AUC .868), and then finally BEPS (AUC .818) and HP with the spectral-gap threshold condition (AUC .816). In the high-noise experiments, BEPS and HP (spectral gap threshold) are almost identical because both methods optimize for a hyperplane (in different ways) that maximizes the number of points on a single side of the hyperplane. When the local dimension is overestimated, HP suffers from the same limitations as BEPS. We see the same behavior when the 2D disk is embedded in higher-dimensional with noise level , in Figure 7(b). See Figure 16 for scatter plots of the boundary scores at and . This suggests that HP should be used if the intrinsic dimension can be reliably estimated, but otherwise, it is best to use DU.
High intrinsic dimension. All methods (hyperplane, DU, LoDD, and BEPS) are able to detect the boundary of an n-dimensional object. We sample points from n-balls embedded in for . For each method, the AUC value is 1 for each n, where boundary and interior points are points with norm > .95 and < .8, respectively. See Figure 17 for boundary scores.
Boundary normals. Both of our boundary detection methods yield normal directions at each point, in addition to numerical scores. For HP, we take the vector (line 5 of Algorithm 1) and lift it from its PCA coordinates back into the ambient space to get a normal . For DU, the

Figure 9: Glioblastoma slice ST1A1.
vector is the same as the vector used by BEPS (Li & Maguire, 2011) and CO (Wang et al., 2018). In Figure 8, we test the accuracy of these vectors on 2D disks and n-balls. For 2D disks in , HP generally yields a more accurate normal direction estimate than DU, with the performance gap narrowing as the noise increases. For HP, fixing the dimension 2 works better than using a spectral gap threshold condition at lower noise levels ( ), but at the highest noise level ( ), the top two local principal components do not align as well with the tangent space. For 2D disks in , the hyperplane normal is significantly more accurate than as increases. For n-balls, both methods (and variants) are equally accurate; we suspect that this is usually true for manifolds with codimension zero. Overall, HP generally yields a much more accurate boundary normal direction compared to DU.
5 BOUNDARY DETECTION IN SPATIAL TRANSCRIPTOMICS DATA
As a first application, we apply our methods to spatial transcriptomics data, which measures gene expression across a tissue section, to recover cell-state boundaries in glioblastoma. Glioblastoma is an aggressive brain tumor that diffusely infiltrates the brain, making it difficult to distinguish regions where tumor cells are abundant or sparse. Malignant cells also occupy distinct transcriptional states (Neftel et al., 2019) that may be amenable to different therapies, further motivating the identification of boundaries within the tumor. We analyze tissue slice ST1A1 from Al-Dalahmah et al. (2023).
Each capture area measures the combined expression of multiple cells. To interpret our boundary scores, we use published cell-state abundance estimates obtained by Robust Cell Type Decomposition (RCTD) (Cable et al., 2022), which deconvolves this expression into contributions from different cell states. Following Al-Dalahmah et al. (2023), we combine the malignant-cell subpopulations gl_Mes1 and gl_Mes2 into an astrocyte-like/mesenchymal group (Mes), and gl_Pro1 and gl_Pro2 into a proliferative group (Pro). These represent distinct malignant states that have prognostic and therapeutic implications. Figure 9 shows their spatial distributions and the mesenchymal/proliferative contrast, calculated as Mes minus Pro.
In Figure 9, both HP and DU assign higher boundary scores along the tissue edge and near parts of the transition between Mes- and Pro-enriched regions. After pre-processing (see Section C.3), we reduce gene expression to 30 principal components and concatenate these with the two spatial coordinates, yielding a point cloud of size (the number of spatial spots) in . We view this as the graph of an expression function over spatial coordinates, motivating fixed dimension two for HP. For both methods, we construct each spot's neighborhood by taking the intersection of nearest neighbors with respect to both spatial coordinates and gene expression coordinates. Our results suggest that our methods can detect internal transitions between tumor states without using cell-state labels or predefined tumor-marker genes.
6 LLM ACTIVATION GEOMETRY
As as second application, we reproduce the character-counting manifold of Gurnee et al. (2026) on two open-weight models (Pythia-2.8B and Llama-3.1-8B) and apply our boundary-detection methods. Using text from the C4 (English) data set (Raffel et al., 2020), we strip newlines and then re-insert them every k characters, rounded to the nearest word boundary, for .
Averaged manifold, character position
Averaged manifold,
DU boundary (k = 100)

Averaged manifold, line width
Averaged manifold,
HP boundary (dim = 2, k = 100)
Normals: DU k = 100 (top 10%)

Averaged boundary scores of per-token DU (k=100)
Normals: HP dim=2 k=100 (top 10%)

(a)
Averaged boundary scores of per-token HP (spectral-gap k=100)
(b)
(c)
Averaged boundary scores of per-token HP (spectral-gap k=100)
(d)
Figure 10: Boundary detection on the character-counting manifold for Pythia-2.8B.
This produces 28 versions of each document, each with fixed line width w. Every non-newline token has a character position i within its line of width w. We extract the layer-4 residual-stream activations and average the activations for each , yielding point clouds of size for each model. Figure 10 shows the Pythia-2.8B point cloud; see Figure 19 for Llama-3.1-8B. See Section C.4 for details of our procedure.
In Figure 10(b), both of our boundary detectors correctly assign higher scores to the ground-truth boundary of the averaged manifold, which is . For HP, we use dimension because the surface is intrinsically parameterized by character position and line width . We also show the vector fields of estimated boundary normals in Figure 10(c) for the top 10% scoring points; the vectors tend to point inwards on the surface, as they should.
Lastly, we test HP and DU on the un-averaged, per-token point cloud (size per model). See Figure 10(d). This is much more challenging because the intrinsic dimension of the space is much higher (and unknown), and there are other, unknown boundaries in the token point cloud. After calculating boundary scores at each point, we average the boundary scores for the tokens at each . The averaged boundary scores are consistently higher at the ground-truth boundary.
7 CONCLUSIONS
We presented two new methods for identifying boundary points and calculating boundary normal vectors in high-dimensional, noisy data. We justified the hyperplane method mathematically, and we rigorously tested both methods empirically against others in the literature on synthetic data. Finally, we showed that our boundary detection methods are effective on real-world applications by using them to identify a tumor boundary in a spatial transcriptomics data set and to characterize the boundary of a manifold in LLM activations.
AI USE STATEMENT
We used generative AI to write almost all of the code and to assist with isolated steps within the proofs of Lemma B.3, Lemma B.4, Lemma B.5, and Lemma B.6.
We have reviewed all AI-assisted work. In particular, we have reviewed the code and checked all mathematical arguments for correctness. We take responsibility for the final content of this work, including text, claims or artifacts produced with the aid of generative AI.
ACKNOWLEDGMENTS
Hickok was supported by NSF grant DMS-2303402. Al Dalahmah was partially supported by NIH grant 1R21NS136647 NINDS. Blumberg was partially supported by NSF grants DMS-2311338 and IIS-2552120.
REFERENCES
Osama Al-Dalahmah, Michael G. Argenziano, Adithya Kannan, Aayushi Mahajan, Julia Furnari, Fahad Paryani, Deborah Boyett, Akshay Save, Nelson Humala, Fatima Khan, Juncheng Li, Hong Lu, Yu Sun, John F. Tuddenham, Alexander R. Goldberg, Athanassios Dovas, Matei A. Banu, Tejaswi Sudhakar, Erin Bush, Andrew B. Lassman, Guy M. McKhann, Brian J. A. Gill, Brett Youngerman, Michael B. Sisti, Jeffrey N. Bruce, Peter A. Sims, Vilas Menon, and Peter Canoll. Re-convolving the compositional landscape of primary and recurrent glioblastoma reveals prognostic and targetable tissue states. Nature Communications, 14(1):2586, 2023. doi:10.1038/s41467-023-38186-1.
Hadar Averbuch-Elor, Nadav Bar, and Daniel Cohen-Or. Border-peeling clustering. IEEE Transactions on Pattern Analysis and Machine Intelligence, 42(7):1791–1797, 2020. ISSN 1939-3539.
Aleksandr Berdnikov and Yevgeny Liokumovich. Sky sphere representation in language models. arXiv:2607.27092, 2026.
Dylan M. Cable, Evan Murray, Luli S. Zou, Aleksandrina Goeva, Evan Z. Macosko, Fei Chen, and Rafael A. Irizarry. Robust decomposition of cell type mixtures in spatial transcriptomics. Nature Biotechnology, 40(4):517–526, 2022. doi: 10.1038/s41587-021-00830-w.
Xuemei Ding, Yuhua Li, Ammar Belatreche, and Liam P. Maguire. Novelty detection using level set methods. IEEE Transactions on Neural Networks and Learning Systems, 26(3):576–588, 2015. ISSN 2162-2388.
Mingjing Du, Ru Wang, Ru Ji, Xia Wang, and Yongquan Dong. ROBP a robust border-peeling clustering using Cauchy kernel. Information Sciences, 571:375–400, 2021. doi: 10.1016/j.ins.2021.04.089.
Joshua Engels, Eric J. Michaud, Isaac Liao, Wes Gurnee, and Max Tegmark. Not all language model features are one-dimensionally linear. In International Conference on Learning Representations (ICLR), 2025.
Walter Gautschi. Some Elementary Inequalities Relating to the Gamma and Incomplete Gamma Function. Journal of Mathematics and Physics, 38(1-4):77–81, 1959. ISSN 0097-1421.
Wes Gurnee and Max Tegmark. Language models represent space and time. In International Conference on Learning Representations (ICLR), 2024.
Wes Gurnee, Emmanuel Ameisen, Isaac Kauvar, Julius Tarng, Adam Pearce, Chris Olah, and Joshua Batson. When models manipulate manifolds: The geometry of a counting task. arXiv:2601.04480, 2026.
Xiaojie Li, Jiancheng Lv, and Zhang Yi. An Efficient Representation-Based Method for Boundary Point and Outlier Detection. IEEE Transactions on Neural Networks and Learning Systems, 29(1):51–62, 2018. ISSN 2162-2388.
Yuhua Li and Liam Maguire. Selecting Critical Patterns Based on Local Geometrical and Statistical Information. IEEE Transactions on Pattern Analysis and Machine Intelligence, 33(6):1189–1201, 2011. ISSN 1939-3539.
Kanti V. Mardia and Peter E. Jupp. Directional Statistics. Wiley Series in Probability and Statistics. Wiley, 1st edition, 1999. ISBN 9780471953333 9780470316979.
Cyril Neftel, Julie Laffy, Mariella G. Filbin, Toshiro Hara, Marni E. Shore, Gilbert J. Rahme, Alyssa R. Richman, Dana Silverbush, McKenzie L. Shaw, Christine M. Hebert, John Dewitt, Simon Gritsch, Elizabeth M. Perez, L. Nicolas Gonzalez Castro, Xiaoyang Lan, Nicholas Druck, Christopher Rodman, Danielle Dionne, Alexander Kaplan, Mia S. Bertalan, Julia Small, Kristine Pelton, Sarah Becker, Dennis Bonal, Quang-De Nguyen, Rachel L. Servis, Jeremy M. Fung, Ravindra Mylvaganam, Lisa Mayr, Johannes Gojo, Christine Haberler, Rene Geyeregger, Thomas Czech, Irene Slavc, Brian V. Nahed, William T. Curry, Bob S. Carter, Hiroaki Wakimoto, Priscilla K. Brastianos, Tracy T. Batchelor, Anat Stemmer-Rachamimov, Maria Martinez-Lage, Matthew P. Frosch, Ivan Stamenkovic, Nicolo Riggi, Esther Rheinbay, Michelle Monje, Orit Rozenblatt-Rosen, Daniel P. Cahill, Anoop P. Patel, Tony Hunter, Inder M. Verma, Keith L. Ligon, David N. Louis, Aviv Regev, Bradley E. Bernstein, Itay Tirosh, and Mario L. Suvà. An Integrative Model of Cellular States, Plasticity, and Genetics for Glioblastoma. Cell, 178(4):835–849.e21, 2019. doi: 10.1016/j.cell.2019.06.024.
Nina Panickssery, Nick Gabrieli, Julian Schulz, Meg Tong, Evan Hubinger, and Alexander Matt Turner. Steering Llama 2 via contrastive activation addition. arXiv:2312.06681, 2024.
Dehua Peng, Zhipeng Gui, Dehe Wang, Yuncheng Ma, Zichen Huang, Yu Zhou, and Huayi Wu. Clustering by measuring local direction centrality for data with heterogeneous density and weak connectivity. Nature Communications, 13(1):5455, 2022. ISSN 2041-1723.
Dehua Peng, Zhipeng Gui, Jie Gui, and Huayi Wu. A Robust and Efficient Boundary Point Detection Method by Measuring Local Direction Dispersion. IEEE Transactions on Circuits and Systems for Video Technology, 35(8):7409–7422, August 2025. ISSN 1558-2205.
Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, and Peter J. Liu. Exploring the limits of transfer learning with a unified text-to-text transformer. Journal of Machine Learning Research, 21(140):5485–5551, 2020.
Sam T. Roweis and Lawrence K. Saul. Nonlinear Dimensionality Reduction by Locally Linear Embedding. Science, 290(5500):2323–2326, 2000.
Alexander Matt Turner, Lisa Thiergart, Gavin Leech, David Udell, Juan J. Vazquez, Ulisse Mini, and Monte MacDiarmid. Steering language models with activation engineering. arXiv:2308.10248, 2024.
Zhiqiang Wang, Zhiwen Yu, C. L. Philip Chen, Jane You, Tianlong Gu, Hau-San Wong, and Jun Zhang. Clustering by local gravitation. IEEE Transactions on Cybernetics, 48(5):1383–1396, 2018. ISSN 2168-2275.
Daniel Wurgaft, Can Rager, Matthew Kowal, Vasudev Shyam, Sheridan Feucht, Usha Bhalla, Tal Haklay, Eric Bigelow, Raphaël Sarfati, Thomas McGrath, Owen Lewis, Jack Merullo, Noah Goodman, Thomas Fel, Atticus Geiger, and Ekdeep Singh Lubana. Manifold steering reveals the shared geometry of neural network representation and behavior. In Third Conference on Language Modeling, 2026.
Chenyi Xia, W. Hsu, M.L. Lee, and B.C. Ooi. BORDER: Efficient computation of boundary points. IEEE Transactions on Knowledge and Data Engineering, 18(3):289–303, 2006. ISSN 1558-2191.
A ADDITIONAL EXPERIMENTAL FIGURES
A.1 HYPERPLANE OPTIMIZATION IN HALF AND FULL BALLS
To illustrate the intuition for HP, we calculate the vector , the solution to Equation (1), for points sampled from 2D and 3D balls and half balls. In Figure 1(a), we showed and its orthogonal hyperplane (line) for points sampled from a 2D half ball. In Figure 11, we show and its orthogonal hyperplane for points in 2D half and full balls and for points in 3D half and full balls. In all cases, the “accuracy” (the percentage of points such that ) is close to 1 for the half balls and close to .5 for the full balls.

(a)
(b)
(c)
(d)
Figure 11: We calculate the vector that is the solution to Equation (1) in our hyperplane method, where the accuracy of is the percentage of points such that . (A) 2D half ball with normal and points, with accuracy .98, (B) 2D full ball with and accuracy .5, (C) 3D half ball with normal and , with accuracy .99, and (D) 3D full ball with and accuracy .6.

Figure 12: We sample points non-uniformly from a 2D disk. In the interior, there is a “well” ( ) where the density is 1/9 that of the density in the outer region ( ). The density increases linearly in between. For each method, we calculate the AUC value for boundary points ( ) vs. interior well points ( ), using neighborhood size . In the top row, we show the methods that are able to handle non-uniform density. In the bottom row, we show the methods that confuse boundary points and low-density interior points.
A.2 NON-UNIFORM DENSITY
In Section 4, we tested boundary detection methods on a 2D disk with non-uniform density and reported AUC values in Table 1. In Figure 12, we show scatter plots of the pointwise boundary scores for each method.
A.3 SURFACES WITH NON-TRIVIAL GEOMETRY
In Section 4, we calculated boundary scores for the hyperplane method, DU, LoDD, and BEPS on a cone and a saddle-skewer data set with low noise levels. In Figure 13 below, we show the boundary scores for four more synthetic data sets.
A.4 HIGH AMBIENT DIMENSION
In Section 4, we calculated boundary scores for the hyperplane method, DU, LoDD, and BEPS for surfaces in high ambient dimension with Gaussian noise. Figure 4 showed the Henneberg minimal
Venus
noise = 0.001
LoDD

Hyperplane

Directional uniformity

BEPS

Henneberg
noise = 0.01




Saturn
noise = 0.01
Three disks
noise = 0.01
0.2 0.4 0.6 0.8
LoDD score
0.6 0.8
hyperplane score
1.0
0.0 0.1 0.2
directional uniformity score
0.6 0.8
BEPS score
1.0
Figure 13: Boundary scores for four synthetic data sets with low noise levels. Each point cloud has N = 10,000 points, and we use neighborhood size k = 100.

Figure 14: Boundary scores for three synthetic data sets embedded in with noise. Scores here are plotted in .

Figure 15: Boundary scores on disks embedded in with Gaussian noise , with points. We use neighborhood size . We plot only the first two coordinates.
surface in and Figure 5 analyzed the boundary scores for disks in . In Figure 14, we show the boundary scores for three more surfaces in , and in Figure 15, we show the boundary scores for 2D disks in with noise.
A.5 HIGH NOISE LEVELS
In Section 4, we tested our hyperplane and DU methods against LoDD and BEPS on 2D disks embedded in with increasing noise level . In Figure 16, we show the boundary scores for disks in at the highest noise level .

Figure 16: Boundary scores for 2D disks embedded in with isotropic Gaussian noise , projected here to .
A.6 HIGH INTRINSIC DIMENSION
In Figure 17, we show the boundary scores for points sampled from a 10-dimensional ball in . All methods achieve AUC 1 except for reverse unreachability (AUC .01). For the AUC calculation, we define boundary and interior points as points with norm > .95 and .8, respectively.

Figure 17: Boundary scores on a point cloud with points sampled from a 10-dimensional ball in , with isotropic Gaussian noise ( ). The ground-truth boundary is difficult to display in 2D because it is 9-dimensional, so instead we take a thin 2D slice (a slightly thickened disk) the ball, plotting the 1500 points closest to the xy plane. Because of the curvature of the boundary (a sphere), the boundary appears thicker than the 2D balls in earlier figures, but this is an artifact of the way we are taking a slice and projecting to .
A.7 SPATIAL TRANSCRIPTOMICS
In Section 5, we analyzed glioblastoma slice ST1A1 from Al-Dalahmah et al. (2023). In Figure 9, we showed HP and DU scores at neighborhood sizes and , respectively. In Figure 18 below, we show the boundary scores at neighborhood sizes for each method.
A.8 LLAMA-3.1-8B ACTIVATION GEOMETRY
We reproduce the character-counting manifold of (Gurnee et al., 2026) for Llama-3.1-8B using the methodology in Section C.4. In Figure 19, we show the averaged manifold and our detected boundaries. We also show the average boundary scores at each character position i and line width w when we compute boundary scores for the un-averaged, per-token point cloud. See Figure 10 for Pythia-2.8B.
Hyperplane, k=75

Directional uniformity, k=75
Hyperplane, k=100

Directional uniformity, k=100
Hyperplane, k=150

Directional uniformity, k=150



Figure 18: HP and DU boundary scores on the ST1A1 glioblastoma slice at neighborhood sizes .
Averaged manifold, character position

Averaged manifold, line width
Averaged manifold,
DU boundary (k = 100)
Averaged manifold,
HP boundary (dim = 2, k = 100)
Normals: DU k = 100 (top 10%)
Averaged boundary scores of per-token DU (k=100)

Normals: HP dim=2 k=100 (top 10%)

(a)
Averaged boundary scores of per-token HP (spectral-gap k=100)
(b)
(c)
(d)
Figure 19: Boundary detection on the character-counting manifold for Llama-3.1-8B. In (c), we calculate normal vectors only for the top 10% scoring boundary points.
B MATHEMATICAL PROOFS
B.1 PROOF OF THEOREM 2.1 FOR INTERIOR MANIFOLD POINTS
Suppose that are sampled independently and uniformly at random from an -dimensional ball. Let and let be defined as in Equation (2). Define
Proof of Theorem 2.1. By Chebyshev's inequality,
The first summand is bounded above by because . By Lemma B.6, there are constants such that for all . Therefore,
Below, we prove Lemma B.6 and other supporting lemmas. First, we establish basic statistics about a point drawn uniformly at random from an -dimensional ball. The mean is by symmetry of the ball.
Lemma B.1. The covariance matrix for is .
Proof. First, we note that is independent of . Let be the radial coordinate of . For any , we have
where is the pdf for in an -dimensional ball. We have that is proportional to the volume of an -dimensional sphere (not ball) of radius , so for a constant . Because , we must have . Therefore,
By symmetry of the ball,
for , so .
We will use the following lemma in an application of the Berry-Esseen theorem to bound the probability .
Lemma B.2. The third moment of is
where is the volume of a unit n-dimensional ball.
Proof. The slice of the ball where is an -dimensional ball of radius , which has volume . Therefore, the pdf is
where . The third moment is
Substituting ,
□
Lemma B.3. For all dimensions n and neighborhood sizes k,
where is a universal constant from the Berry-Esseen theorem.
Proof. Note that
Therefore,
because . The last equality holds because and are independent vectors in the -ball that are equally likely to have angle and angle .
Next, we prove the upper bound on . Conditioning on , we have
The sum is a sum of iid random variables with mean 0 because . We will apply the Berry-Esseen theorem to approximate it by a normal random variable; as preliminaries, we need its variance and third moment of each term in the sum. By Lemma B.1, we have . To calculate the third moment , note that
where . By rotational symmetry we may assume that . Therefore, and so . By Lemma B.2,
By the Berry-Esseen theorem,
where is a universal constant. Finally, we upper bound . The cdf of a normal variable decreases monotonically after 0, so
All together,
for all . Consequently, the right-hand side is an upper bound for by Equation (4).
Finally, we upper bound to finish the proof. The volume of a unit n-ball is . By Gautschi's inequality (Gautschi, 1959),
Therefore,
We will use Lemma B.4 and Lemma B.5 below to bound using an application of the multi-dimensional Berry-Esseen theorem.
Lemma B.4. Suppose that are unit vectors in with angle . Let be the matrix whose columns are and let . If is sampled uniformly at random from the -ball, then
where is the orthogonal projection matrix onto .
Proof. First, note that . Therefore,
Because , we have
Because is an orthogonal projection matrix,
We have
For , we have because the components are independent and mean-centered. For , we have . Therefore, . By Lemma B.6, we have . All together,
Because is an orthogonal projection matrix onto a plane (the span of non-parallel vector ), its eigenvalues are , so . By Equation (5), .
Lemma B.5. Let for some , and suppose that . Define
Then
Proof. We have because are normally distributed with variance 1 and correlation . Therefore,
Therefore, for nonzero ,
(6)
Therefore, it suffices to show that . Let , where is the correlation of . We will calculate for ; the case is symmetric. We have
Letting denote the joint pdf for , we have
To calculate the conditional CDF, we note that factors as
so the pdf for is the pdf of a normal random variable with mean and variance . Therefore,
Because for any ,
The same upper bound holds for . Combining Equation (6) and Equation (7) completes the proof.
Lemma B.6. We have for all , and there are constants such that
for all .
Proof. For the variance, observe that is a Boolean random variable with probability of success . For the covariance, we have
By Lemma B.3, there are constants such that
for all .
The focus of the rest of the proof is to upper bound . Let . For , we have
so if and only if . Conditioning on and , we get
where the conditional probability is
where for .
Let for , and consider the 2D vector . The right-hand side of Equation (10) is . Therefore,
We have that is the sum of iid 2D random variables:
with mean 0 because by symmetry of the ball. Using the fact that the variance of the ith component of is by Lemma B.1, we get that the covariance matrix for is
We normalize so that each component has variance 1. Let and let . The main probability of interest is
where
because and are in the unit ball. The covariance matrix for is
where is the angle between and .
Let . We will upper bound using the multi-dimensional Berry-Esseen theorem. We can write as the sum of iid random variables , where
where and is the matrix with columns . The covariance matrix is invertible whenever . Therefore when , the multi-dimensional Berry-Esseen theorem implies that
where is a universal constant and
By Lemma B.4, we have when . Therefore,
for all fixed such that . Vectors have angle with probability 1, so
Next, we show that is a good approximation to in the expectation over . First, note that
Use the notation to denote the probability when the angle between and is . By Lemma B.5,
Therefore when we integrate over all in the n-ball, we get
By Equation (11),
Additionally, we note that
Consequently,
By Equation (8), Equation (9), Equation (12), Equation (13), and Equation (14), there are constants such that
for all .
23
□
B.2 PROOF OF THEOREM 2.2 FOR BOUNDARY POINTS
Next, we consider the case where is a set of points sampled from an -dimensional half ball, modeling the boundary score of a point on the boundary of an -dimensional manifold.
Proof of Theorem 2.2. The random variable is non-negative. By Markov's inequality,
Applying Lemma B.11 completes the proof.
Below, we prove the supporting lemmas, starting with statistics about a point sampled uniformly at random from the half ball. Without loss of generality, we assume that it is the half ball where the first coordinate is .
Notation B.7. Let and let denote the standard deviation of the ith component . Let denote the cdf for the first coordinate , and let denote the pdf. We will denote the volume of a unit n-dimensional ball by .
Lemma B.8. The pdf for the first coordinate of is
Proof. The slice of the half ball where is an -dimensional ball of radius , which has volume . Therefore,
where . This is the volume of the half ball.
Lemma B.9. The mean has components
Proof. By symmetry, for . For ,
by Lemma B.8. Using the substitution ,
Lemma B.10. The variance of the ith component of is
Proof. The same proof as Lemma B.1 shows that for all , because the pdf for is the same in both the full and half ball.
Therefore, the variance is
Lemma B.11. Let be points drawn independently and uniformly at random from an n-dimensional half ball where the first coordinate is , and let . Then
Proof. Define . Note that if and only if , so . First, will show that concentrates near . Then, we will condition on being near to derive an upper bound on . When is sufficiently close to , the conditional probability is small.
First, we bound the norm of . Let . For the th component,
by Chebyshev's inequality and Lemma B.10. Let be the event that . Applying a union bound yields
Now we condition on the event . For any , we have that
(15)
We can write
where the last equality follows by Lemma B.9. If , then
Therefore,
when . This yields
Combining with Equation (15) gives us
where is the CDF for the first coordinate of . The CDF is monotonically increasing and satisfies
By Lemma B.8, the pdf is monotonically decreasing, so
Therefore,
Substituting into Equation (16) gives us
for all .
To finish the proof, we will optimize the choice of as a function of and . The right-hand side approaches as or , so it achieves a minimum. Write , where and . The only critical point occurs when
At the critical point, we have
By Equation (17),
C METHODOLOGICAL DETAILS FOR EXPERIMENTS
C.1 INTRINSIC DIMENSION ESTIMATION
HP requires local dimension estimation (Step 3 of Algorithm 1). Unless otherwise stated, we use a spectral gap threshold to determine the dimension. Given a neighborhood for point , let be the eigenvalues of the covariance matrix (for the local neighborhood) in descending order. The local dimension estimate at is the minimum index such that . If no such index exists, we use dimension . The default threshold is .
C.2 AUC VALUES FOR SYNTHETIC DATA EXPERIMENTS
In Section 4, we calculated AUC values for interior vs. boundary points of disks (and -dimensional balls) embedded in . Because the ground-truth boundary of a disk or ball has measure 0, there are not any points on the ground-truth disk (or -ball) boundary, so we defined the “empirical” boundary to be the set of points with norm larger than a threshold and the “empirical” interior to be the set of points with norm smaller than a threshold . We used and in Section 4. For the disks embedded in , the norm was calculated with respect to the first two coordinates (the plane that contains the disk), and for the -dimensional balls in , we used the -dimensional Euclidean norm. In this section, we present the AUC values for different choices of . Our conclusions do not qualitatively change when we use a different threshold .
In Figure 5, we considered the AUC values for 2D disks embedded in with increasing ambient dimension , at fixed boundary threshold . In Figure 20, we show the AUC values for varying thresholds . At each threshold , the DU method performs best, followed by HP, followed by LoDD.
In Figure 7(B), we calculated AUC values for 2D disks embedded in with increasing noise , at fixed boundary threshold . In Figure 21, we show the AUC values for
LoDD Hyperplane DU

Figure 20: Point clouds are sampled from 2D disks embedded in for with Gaussian noise level . Each point cloud has points, and we use neighborhood size . Interior points are defined to be points with norm less than .8, and boundary points are defined to be points with norm larger than , which increases from to across the panels. In each panel, we plot the AUC values as a function of ambient dimension for each of the three methods.
LoDD Hyperplane (gap threshold) Hyperplane (fixed dim 2) DU BEPS

Figure 21: At each noise level , we sample a point cloud from a 2D disk in with isotropic Gaussian noise. Each point cloud has points, and we use neighborhood size . Interior points are defined to be points with norm less than .8, and boundary points are defined to be points with norm larger than , which increases from to across the panels. In each panel, we plot the AUC values as a function of noise level for each of the three methods.
varying thresholds . For , the relative performance of each method is the same as when , where the hyperplane method with fixed dimension does best, closely followed by DU. For , DU outperforms every method at the lowest noise levels and .
In Figure 7(C), we calculated AUC values for 2D disks embedded in with increasing dimension and fixed noise level , at fixed boundary threshold . In Figure 22, we show the AUC values for varying thresholds . At all threshold , the hyperplane method with fixed dimension performs best, followed by DU, followed for LoDD, followed by BEPS and the hyperplane method with a spectral gap threshold condition.
LoDD Hyperplane (gap threshold) Hyperplane (fixed dim 2) DU BEPS

Figure 22: At each ambient dimension , we sample a point cloud from a 2D disk in with isotropic Gaussian noise . Each point cloud has points, and we use neighborhood size . Interior points are defined to be points with norm less than .8, and boundary points are defined to be points with norm larger than , which increases from to across the panels. In each panel, we plot the AUC values as a function of ambient dimension for each of the four methods.
C.3 SPATIAL TRANSCRIPTOMICS
C.3.1 DATA PREPROCESSING
The raw data has 741 spatial spots and 27,984 genes.
Quality control. We do gene quality control by discarding genes that are detected at fewer than 3 spots. This results in the removal of 12,372 genes.
Library-size normalization. We normalize each spot to a common total count of 10,000. More precisely, if is the number of transcripts of gene g at spot i, the library size at spot i is . We rescale the counts so that each spot has library size 10,000.
Log transform. For each spot and gene , we apply a log transform , where is the output from the library-size normalization step.
Highly variable genes. We select the 3,000 most highly-variable genes, discarding the rest.
Scaling. We normalize each gene so that it has mean 0 and variance 1 by mapping each to its z-score. More precisely, if and are the mean and standard deviation for gene expression across spots, we calculate . We clip values at max z-score 10, i.e., , so that no single gene dominates the PCA step below.
PCA dimension reduction. Let be the gene expression values at spot after the preprocessing steps above. We use PCA to reduce to 30 dimensions.
C.3.2 NEIGHBORHOOD CALCULATION FOR THE BOUNDARY DETECTION ALGORITHMS
Both HP and DU require a local neighborhood at each point (see lines 2 of Algorithm 1 and Algorithm 2, respectively). We define the neighborhoods as follows.
For each spot, we concatenate the 30-dimensional PCA gene expression coordinates with the 2D spatial coordinates, yielding a 32-dimensional vector at each spot. The gene and spatial coordinates have very different scales, so to determine the nearest neighbors of each spot, it does not make sense to naively calculate Euclidean distance in .
Instead, we consider spatial and gene distance independently. For integer , let denote the nearest neighbors of the th spot with respect to gene coordinates (Euclidean distance in ), and let denote the nearest neighbors of the th spot with respect to spatial coordinates (Euclidean distance in ). At neighborhood size parameter , we define the neighborhood of spot to be the intersection
for the minimum integer such that the intersection has size .
C.4 LLM ACTIVATION GEOMETRY
In Section 6, we applied our boundary detection algorithms to study LLM activation geometry. The results for Pythia-2.8B were shown in Figure 10, and the results for Llama-3.1-8B were shown in Figure 19. Here, we detail our methodology.
C.4.1 DATA SET
We stream documents from the C4 (English) data set (Raffel et al., 2020), keeping those that have at least 400 characters excluding whitespace. For each document and each , we remove all newlines and then re-insert them every characters, breaking at the nearest word boundary so that each line has at most characters. We continue extracting documents from C4 until we reach at least 250,000 non-newline tokens in total. This is satisfied by the first 28 documents. (See Table 2 for total token counts for Pythia-2.8B and Llama-3.1-8B.) This process yields 28 documents widths = 784 total sequences. We cap each sequence at 512 tokens, including newlines.
Each non-newline token is labeled by its character position and line width . The character position of a token is defined to be the number of characters used from the beginning of the line through the end of the token.
| Pythia-2.8B | Llama-3.1-8B | |
|---|---|---|
| Total tokens | 271,100 | 269,651 |
| Non-newline tokens | 250,437 | 250,641 |
Table 2: Number of tokens extracted for each model.
C.4.2 MODELS AND LAYER SELECTION
We test two models, Pythia-2.8B and Llama-3.1-8B, which have dimensions and , respectively. Both models have 32 layers. For each token in our data set, we extract the residual-stream activations at layer 4 in both models. We chose layer 4 after visual inspection of the averaged character-counting manifold for candidate layers 4, 11, 16, 24, and 29.
C.4.3 AVERAGED MANIFOLD
For each , we average the residual-stream vectors at layer 4 for tokens with character position i and line width w. We discard if there are fewer than 5 tokens with position i and line width w. This gives us N = 2,311 points for the Pythia-2.8B manifold and N = 2,335 points for the Llama-3.1-8B, manifold.
C.4.4 BOUNDARY DETECTION ON THE AVERAGED MANIFOLD
First, we use PCA to reduce the averaged manifold ( for each model) to 30 dimensions. Then, we run the DU method and the hyperplane method with fixed dimension 2, both with neigh-
Occasionally, we encounter a token with characters itself. These tokens are put onto their own line, thus creating a line that is over k characters. These lines are rare.
If every token had position , there would be at most 2,310 possible labels . For a line of width w, every token has position with the exception of tokens that have length . A token with more than w characters forms its own line. This gives us occasional tokens with label for , which is why the averaged manifolds for both Pythia-2.8B and Llama-3.1-8B have more than 2,310 points.
borhood size . (The manifold is intrinsically 2-dimensional because it is parameterized by character position and line width 2.)
The hyperplane method yields a vector , in local PCA coordinates, at each point, which we lift to a vector in the ambient 30-dimensional PCA basis. The DU method gives us a vector at each point. In Figure 10 and Figure 19, we show the vectors for points whose boundary scores are in the top decile.
C.4.5 BOUNDARY DETECTION ON THE UN-AVERAGED, PER-TOKEN MANIFOLD
Instead of averaging the residual-stream activations for each , we consider the entire point cloud of size size (one point per token). Again, we use PCA to reduce to 30 dimensions. Then, we run the DU method and the hyperplane method with neighborhood size . We use a spectral gap threshold condition (with default threshold ) for the hyperplane method instead of fixing dimension 2 because the intrinsic dimension is no longer 2. At each , we average the boundary scores for all tokens at position within a line of width .
C.4.6 3D VISUALIZATION
For both models, the first principal component of the averaged manifold is dominated by a few outliers, so in Figure 10 and Figure 19, we plot in PC2-PC3-PC4 coordinates.
D OTHER BOUNDARY DETECTION VARIANTS
Both CO (Wang et al., 2018) and BEPS (Li & Maguire, 2011) use the vector at each point , where are its nearest neighbors. The CO score at point is
where . The CO score is high on low-density points, regardless of whether they are interior or boundary points, so the CO method struggles with non-uniform density. The difference between our DU method and the CO method is that we removed the term and normalized the score so that it is always less than or equal to 1.
We tested several other boundary detection variants (see Table 3), with results shown in Figure 23. Each variant uses either the vector or a slightly different vector where the neighbor-displacement vectors are not normalized, and then each variant has a score that is constructed from the chosen vector. The cosine variant uses but measures the cosine between and instead of taking the dot product; this variant isolates the effect of neighbor alignment between vectors, which was the rationale in Wang et al. (2018). We find that the cosine variant works poorly because the vectors of all neighbors tend to be similar due to the fact that their neighborhoods are similar, regardless of whether they are on a boundary or not. The magnitude variant works almost as well as DU on disks and -balls, but as discussed in Section 3, the DU variant is more robust to noise. The two variants that use do not work well with non-uniform density because is large when the density is low. The DU variant was the best overall performer across varying noise levels, varying dimension, and non-uniform density.
| Variant | Vector | Score |
|---|---|---|
| CO (Wang et al., 2018) | ||
| Directional uniformity | ||
| CO magnitude | ||
| Cosine | ||
| Sum displacement | ||
| Mean direction |
Table 3: Other boundary-detection methods that we tested.
CO
(high = boundary)
AUC = 0.266

Directional uniformity
(high = boundary)
AUC = 0.935
Cosine
(high = boundary)
AUC = 0.700
CO magnitude
(high = boundary)
AUC = 0.963
Sum-displacement
(high = boundary)
AUC = 0.252
Mean-direction
(high = boundary)
AUC = 0.412

(a)
2D disk in with Gaussian noise (N = 10,000, k = 100)
2D disk in
(N = 10,000, k = 100, )

n-ball in
(N = 10,000, k = 100, )
(b)
Figure 23: We compare the variants from Table 3. (A) Scores on the non-uniformly sampled disk from Figure 12 with N = 10,000 points and neighborhood size k = 100. AUROC scores are for boundary points (norm > .98) vs deep interior points (norm < .23), like in Figure 12. AUROC scores for boundary vs. interior points on 2D disks and n-balls, where interior and boundary points are defined as having norms < .8 and > .95, respectively.