---
title: 'TopoHG: Topology Hard Sample Generation'
url: https://www.emergentmind.com/topics/topology-hard-sample-generation-topohg
type: topic
---

# TopoHG: Topology Hard Sample Generation

Searching arXiv for the cited TopoHG-related papers to ground the article in current literature.
Querying arXiv for "Learning to Sample Hard Instances for Graph Algorithms" and related "Topology Hard sample Generation" works.
Topology Hard Sample Generation (TopoHG) denotes a family of methods that concentrate sampling or synthesis on topologically informative or algorithmically difficult instances. In the graph-algorithm setting, the term is instantiated by HiSampler, a general, problem-agnostic framework that learns a probabilistic generator over small graphs whose mass is concentrated on instances that are maximally hard for a target algorithm \(A\) [1902.09700]. In later usage within tubular structure segmentation, TopoHG refers to a test-time hard-sample generation strategy that creates local pseudo-breaks in confidently predicted tubular regions and trains a model to restore continuity under teacher-student consistency supervision [2508.00442]. Taken together, the literature suggests that TopoHG is best understood not as a single architecture, but as a recurring design pattern in which topology-aware perturbation, sampling, or guidance is used to expose failure modes and improve analysis, benchmarking, or adaptation.

## 1. Origins in hard-instance generation for graph algorithms

The earliest formulation in the present corpus is HiSampler, introduced for graph problems in "Learning to Sample Hard Instances for Graph Algorithms" [1902.09700]. Its stated objective is to obtain a probabilistic generator of hard instances rather than only a finite set of instances. The motivation is twofold: hard instances help analyze an algorithm for accelerating it, and they help build a good benchmark for evaluating performance. The paper further argues that evolutionary algorithms can generate only a finite number of hard instances, making it difficult to extract meaningful patterns from a small number of instances.

In this formulation, TopoHG is explicitly described as a general, problem-agnostic framework for learning a probabilistic generator over small graphs that concentrates mass on instances that are maximally hard for a given graph algorithm \(A\) [1902.09700]. The framework is notable for avoiding hand-engineered features and for modeling the distribution of hard instances without parameters or rules supplied by domain experts. The paper states, "To the best of our knowledge, this is the first method to learn the distribution of hard instances using machine learning" [1902.09700].

A central conceptual point is that the target object is a distribution rather than a single adversarial example. This changes the role of hard-sample generation: instead of searching for isolated worst cases, the method seeks a learned source of varied hard instances from which one can both sample benchmarks and infer recurring structural motifs.

## 2. Probabilistic model, objective, and optimization

For a fixed number of vertices \(n\), a simple undirected graph \(G\) is represented by the upper-triangular part of its adjacency matrix, with
\[
G \in \{0,1\}^{m}, \qquad m = \frac{n(n-1)}{2}.
\]
HiSampler defines a parameterized distribution \(P_\theta\) in two stages. First, it samples latent noise
\[
z \sim \mathcal N(0, I_{d_0}),
\]
with latent dimension \(d_0\). Second, an \(l\)-layer MLP \(N_\theta : \mathbb R^{d_0}\to\mathbb R^m\) maps \(z\) to edge probabilities
\[
\pi_\theta(z) = \sigma(N_\theta(z)) \in [0,1]^m,
\]
after which the graph is sampled coordinate-wise as independent Bernoullis conditioned on \(\pi_\theta(z)\) [1902.09700]. The conditional distribution is
\[
P_\theta(G \mid z) = \prod_{i=1}^m \pi_i(z)^{G_i}(1-\pi_i(z))^{1-G_i},
\]
and the marginal graph distribution is
\[
P_\theta(G) = \int p(z)\,P_\theta(G \mid z)\,dz.
\]

Hardness is measured by a scalar \(T(A,G)\in\mathbb R_+\), obtained by actually running the target algorithm \(A\) on \(G\). Depending on the experiment, this is either a discrete count such as the number of recursive calls or branching decisions, or wall-clock time in microseconds or milliseconds [1902.09700]. The learning objective is
\[
J(\theta) = \mathbb E_{G\sim P_\theta}[T(A,G)],
\]
equivalently \(L(\theta) = -J(\theta)\).

Because \(T(A,G)\) is a non-differentiable black-box quantity, the optimization uses the score-function estimator REINFORCE. A single Monte Carlo estimator is written as
\[
\nabla_\theta J(\theta)
\approx
T(A,G)\,\nabla_\theta \sum_{i=1}^m \left[G_i\log \pi_i(z) + (1-G_i)\log(1-\pi_i(z))\right].
\]
In practice, each iteration samples \(z\), computes \(\pi\), samples \(G\), evaluates \(r=T(A,G)\), and applies
\[
\theta \leftarrow \theta + \alpha\, r\, \nabla_\theta \log P_\theta(G \mid z).
\]

The variant HiSampler-PER augments vanilla REINFORCE with an experience pool containing the top-\(K\) hardest graphs seen so far, and replays a uniformly chosen element from that pool at each iteration [1902.09700]. Because truly hard graphs occupy a tiny corner of the graph space, this prioritized replay mechanism is presented as a way to accelerate convergence toward high-hardness regions.

## 3. Architecture, protocol, and empirical behavior

The generator is a fully connected feedforward network of depth \(l\), with a representative configuration
\[
10 \rightarrow 100 \rightarrow 500 \rightarrow m,
\]
ReLU hidden activations, and a final sigmoid output layer [1902.09700]. Although the decoder factorizes edges conditionally as independent Bernoullis, the paper emphasizes that shared parameters \(\theta\) and nonlinear activations induce rich nonlinear dependencies among edges.

The reported evaluation covers seven algorithms spanning four graph problems: DSATUR and a MiniSat reduction for 3-coloring; a branch-and-bound algorithm \(B'\) for minimum vertex cover; BK, MCS, and FMC for maximum clique; and Nauty for graph isomorphism [1902.09700]. The key hyperparameters are fixed across problems: hidden dimensions \(10\to100\to500\to m\), Adam with learning rate \(10^{-4}\), latent dimension \(d_0=10\), PER pool size \(K=10\), and total evaluation budget \(B=10\,000\) graphs. Initialization uses a final-layer bias
\[
b = -\log(1/p^* - 1)
\]
so that \(\pi_i\) starts near a "hard" edge density \(p^*\) found by a small sweep.

The baselines are random sampling from Erdős-Rényi \(G(n,p^*)\), a generic evolutionary algorithm with population size \(30\), uniform crossover, and adaptive mutation, and rule-based constructions from the literature such as phase-transition heuristics and gadget graphs [1902.09700]. Across all seven targets, HiSampler-PER is reported to find instances whose hardness \(T\) is several to many orders of magnitude larger than random or rule-based sampling, while also consistently outperforming the generic evolutionary search.

A representative example is DSATUR with \(n=50\). The hardest random \(G(n,p^*)\) sample yields about \(4\times10^2\) recursive calls, whereas HiSampler-PER produces graphs requiring approximately \(6.1\times10^8\) calls, described as a factor of about \(10^6\) harder [1902.09700]. For MiniSat-based 3-coloring at \(n=200\), the hardest random sample requires about \(690\) solver decisions and HiSampler-PER reaches about \(2.7\times10^3\). The paper states that prioritized replay consistently outperforms vanilla REINFORCE.

The qualitative analysis is equally important. Inspection of the hardest DSATUR instances reveals a tight 4-clique attached to the rest of the graph only via a long path of low-degree vertices [1902.09700]. The interpretation given is that DSATUR colors the bulk of the graph first and fails only later on the clique, which forces combinatorial backtracking. Frequent-subgraph mining with gSpan on \(1000\) samples from the learned \(P_\theta\) identifies 4-cliques with support approximately \(999/1000\), as well as longer chains with degree-2 connectors leading into small unsatisfiable cores. The paper further reports that these motifs suggest a preprocessing rule deleting degree-\(\le 2\) vertices, described as provably equivalent and sufficient to eliminate the bottleneck that the learned generator exposed.

## 4. TopoHG in test-time adaptation for tubular structure segmentation

A distinct later use of the term appears in "TopoTTA: Topology-Enhanced Test-Time Adaptation for Tubular Structure Segmentation," where TopoHG denotes the second-stage hard-sample generation strategy inside a two-stage test-time adaptation pipeline [2508.00442]. Here the objective is not graph-instance generation but topological continuity refinement under domain shift.

The motivation is stated in explicitly topological terms. Tubular structure segmentation is described as especially sensitive to domain shifts because changes in topological structures can compromise segmentation integrity, while local variations in texture and contrast can disrupt topological continuity [2508.00442]. Stage 1, based on TopoMDCs, addresses large-scale structural discrepancies such as thickness, curvature, and branching. Stage 2, TopoHG, addresses fine-grained continuity failures by generating hard test-time samples through local perturbation of high-confidence tubular regions.

The procedure has three steps. First, key-point selection uses the teacher pseudo-label \(\hat y'\) to identify highly confident pixels,
\[
\mathcal P = \{(u,v)\mid \hat y'(u,v) > \tau\}, \qquad \tau = 0.95,
\]
and samples
\[
N_p = k \times |\mathcal P|
\]
distinct key points with a small coefficient \(k\), for example \(k=0.002\) [2508.00442]. Second, for each key point, the method extracts an \(s\times s\) foreground patch with \(s=30\) and searches its non-overlapping 8-neighborhood for a background patch minimizing aggregate foreground confidence. If the selected background patch exceeds the threshold \(\tau^{\mathrm{bg}}=0.05\), that key point is discarded. Third, the foreground and background patches are transformed by FFT, and only the low-frequency region selected by a binary mask \(m_{\mathrm{low}}\) is swapped:
\[
x_p^{\mathrm{swap}}
=
\mathrm{iFFT}\Bigl(
(1-m_{\mathrm{low}})\odot f_p^{\mathrm{fg}}
+
m_{\mathrm{low}}\odot f_p^{\mathrm{bg}}
\Bigr).
\]
The resulting patch is then blended with the pseudo-label,
\[
x_p'
=
x_p^{\mathrm{swap}}\odot \hat y'_p
+
x_p^{\mathrm{fg}}\odot (1-\hat y'_p),
\]
and pasted back into the image to create the hard sample \(x'\) [2508.00442].

Learning proceeds in a teacher-student framework. The teacher predicts \(\hat y'=\mathcal F(x;\theta';\delta)\) on the original image, the student predicts \(\hat y''=\mathcal F(x';\theta;\delta)\) on the hard sample, and a weighted symmetric cross-entropy is minimized:
\[
\mathcal L_{\mathrm{CE}}
=
-\sum_{(u,v)} w(u,v)
\left[
\hat y'(u,v)\log \hat y''(u,v)
+
\hat y''(u,v)\log \hat y'(u,v)
\right],
\]
with \(w(u,v)=10\) inside pseudo-break patches that belong to foreground in \(\hat y'\), and \(w(u,v)=1\) otherwise [2508.00442]. The teacher is refreshed by exponential moving average,
\[
\theta' \leftarrow \lambda \theta' + (1-\lambda)\theta.
\]

The ablation results specifically attributed to Stage 2 report that adding TopoHG to a teacher-student baseline changes Dice from \(65.95\) to \(68.82\), clDice from \(62.20\) to \(66.61\), and \(\beta\) from \(77.90\) to \(73.63\), corresponding to a \(+3.66\) percentage-point gain in clDice and a \(-4.27\) change in Betti error [2508.00442]. In comparisons against naïve augmentations, the full two-stage TopoTTA with TopoHG attains Dice \(69.87\), clDice \(67.81\), and \(\beta=73.27\); Gaussian blur gives clDice \(66.26\), Gaussian noise \(65.00\), and spatial image swap \(66.36\) with a smaller Betti error but substantially lower Dice \(67.65\) [2508.00442]. The paper interprets pure spatial swap as over-connecting background, whereas TopoHG preserves high Dice while strengthening continuity.

## 5. Relation to topology-controlled and topology-guided generative methods

TopoHG sits in a broader landscape of topology-aware sampling and generation. One antecedent is "Efficient Topology-Controlled Sampling of Implicit Shapes," which develops a topology-controlled MCMC sampler, TC-GIMH-SS, for implicit level-set segmentations and shows how to impose hard topology constraints such as topology-preserving, genus-preserving, component-preserving, or unconstrained sampling [1205.3766]. The method chooses proposals so that the Metropolis-Hastings acceptance ratio is identically \(1\), and the summary further describes a recipe for generating "hard" or adversarial shapes by modifying the target density with an auxiliary difficulty function \(D(\ell)\). This is not called TopoHG in the paper title, but it provides a direct precedent for combining topology control with hardness-biased sampling.

Another related line is "Topology Guidance: Controlling the Outputs of Generative Models via Vector Field Topology," which studies controllable generation of 2D vector fields using a diffusion model in latent space coupled with a coordinate-based neural network [2505.06804]. There the user specifies a topological descriptor \(C\) consisting of critical-point locations, types, and stability labels. Guidance is imposed during reverse diffusion by modifying the predicted noise with the gradient of a topology energy,
\[
\tilde \epsilon(z_t,t)
=
\epsilon_\theta(z_t,t)
+
\omega \nabla_{z_t} E(z_t,t;C).
\]
The energy combines critical-point existence, type, and stability terms derived from the decoded field and the Jacobian eigenvalues at prescribed points. The reported evaluation includes alignment and Fréchet Distance metrics, with single-critical-point experiments showing alignment \(>85\%\) for sink and source, \(>93\%\) for saddle, and \(FD\approx 10\) compared with baseline \(FD=8.84\) [2505.06804]. This suggests a neighboring interpretation of topology-aware hard generation: instead of maximizing algorithmic hardness or inducing pseudo-breaks, the generator is guided toward specified topological events while remaining within the learned data distribution.

A plausible implication is that TopoHG, topology-controlled sampling, and topology guidance all share the same methodological skeleton: a base generative or sampling process is perturbed by a topology-sensitive signal, and the perturbation is evaluated not only by realism or likelihood but also by the induced structural configuration.

## 6. Extensions to topologically labeled synthetic data and conceptual scope

A further extension appears in a related specification built on "Generating Topologically and Geometrically Diverse Manifold Data in Dimensions Four and Below" [2410.07115]. In that specification, a "Topology Hard Sample Generation" pipeline produces binary 2D, 3D, or 4D images with Betti-number labels known by construction. The pipeline begins with a filled \(D\)-cube, carves out manifold-with-boundary connected sums with sampled parameters \((g,h,i,j)\), optionally applies hypervolume-preserving pixel-moving deformations and topology-preserving morphological deformations, computes exact cubical homology, and stores the sample together with \((\beta_0,\ldots,\beta_D)\) [2410.07115].

The stated hardness metrics are explicitly topological: topological complexity
\[
C_{\mathrm{top}} = \sum_{k=0}^D k\cdot \beta_k,
\]
persistence-entropy vectors \(\{E_k\}\), and minimum nonzero persistence in persistence diagrams [2410.07115]. The same specification provides examples such as a 2D genus-\(g\) curve with \(\beta_0=1,\beta_1=g,\beta_2=0\), a 3D two-torus example with \(\beta_0=1,\beta_1=4,\beta_2=1,\beta_3=0\), and a 4D \(S^1\times S^2\) tube with \(\beta_0=1,\beta_1=1,\beta_2=1,\beta_3=1,\beta_4=0\).

This broader usage sharpens an important conceptual distinction. In the graph setting, "topology" refers primarily to graph topology and algorithmic worst cases; in tubular segmentation, it refers to continuity and breakage of curvilinear structures; in topology-guided field generation, it refers to critical-point configurations; and in manifold-data generation, it refers to homology and Betti-number control. The literature therefore uses the label TopoHG heterogeneously. A common misconception would be to treat it as a single standardized model family. The evidence instead supports a narrower claim: TopoHG is a reusable methodological motif for generating structurally difficult or structurally specified samples, with the operative notion of topology determined by domain-specific invariants and failure modes.

Source: https://www.emergentmind.com/topics/topology-hard-sample-generation-topohg