---
title: Metric Reservoir Sampling Techniques
url: https://www.emergentmind.com/topics/metric-reservoir-sampling
type: topic
---

# Metric Reservoir Sampling Techniques

Metric reservoir sampling denotes a family of bounded-memory streaming samplers in which retention, eviction, or weighting is driven by a metric, score, decay function, or objective-specific quantity rather than by uniform replacement alone. The cited literature suggests that the phrase does not identify a single canonical algorithm. Instead, it spans fixed-size weighted priority reservoirs for subset sums, graph streams, and repeated-key aggregates; confidence- and time-weighted buffers for continual learning and visual tracking; temporally biased reservoirs with explicit decay semantics; and reservoir reuse inside stochastic estimators of metric quantities such as Sliced Wasserstein Distance. A separate geometric line studies sampling of metric measure spaces via \(\varepsilon\)-nets and snowflaked metrics; that line is related terminologically but is not a reservoir algorithm in the streaming sense [0803.0473] [1703.02625] [1703.02693] [2108.09592] [1204.2912] [1801.09709] [1906.05677] [2510.01061] [1103.3843].

## 1. Multiple meanings of “metric” in reservoir sampling

In one major usage, the metric is a scalar importance weight that enters a threshold or priority law. In \(\mathrm{VAROPT}_k\), items have weights \(w_i>0\), inclusion probabilities are of threshold form
\[
p_i=\min\{1,w_i/\tau_k\},
\]
and sampled items receive adjusted weight
\[
\hat w_i=\max\{w_i,\tau_k\}.
\]
The objective is “variance-optimal unbiased estimation of subset sums” under a fixed sample size \(k\) [0803.0473]. In graph streams, Graph Priority Sampling maintains a reservoir \(\hat K_t\) of size \(m\), assigns each arriving edge \(k\) a random key \(u(k)\sim \mathrm{Uni}(0,1]\), an adaptive weight \(w(k)=W(k,\hat K)\), and a priority
\[
r(k)=\frac{w(k)}{u(k)}.
\]
The sample is the top-\(m\) priority edges, and the metric is the weight function \(W(k,\hat K)\), which may depend on graph structure, attributes, or variance-reduction surrogates [1703.02625]. For repeated-key streams, Priority-Based Aggregation maintains per-key priorities \(W_{k,t}/u_k\) and unbiased aggregate estimates in a fixed-size cache over non-unique keys [1703.02693].

In a second usage, the metric is an application-specific value signal. Confidence Reservoir Sampling in task-free online continual learning keeps the outer reservoir-style admission test but changes eviction by scoring memory items with
\[
\mathcal S := EX + c\cdot MI,
\]
where \(EX=n/a\) is an exploitation rate and \(MI=m_{t+1}-m_t\) is a margin increment based on softmax confidence [2108.09592]. In online visual tracking, time-weighted reservoir sampling assigns each sample a time-based weight
\[
w=q^{\mathbb I}
\]
and a key
\[
k=u^{1/w},
\]
so that recent samples are more likely to remain in bounded foreground and background buffers used for online Mahalanobis metric learning [1204.2912].

In a third usage, the metric is temporal age. Temporally-biased sampling schemes specify a decay function \(f(\alpha)\) over item age and aim to maintain inclusion probabilities proportional to that decay, while controlling memory usage through a reservoir cap or a target size [1801.09709] [1906.05677].

In a fourth usage, reservoir sampling is embedded inside a stochastic estimator of a metric. ReSWD stores projection directions and scores each direction by
\[
D(\theta)=W_p(\pi_\theta\mu,\pi_\theta\nu),
\]
then uses weighted reservoir sampling to retain “informative projection directions” across optimization steps for lower-variance Sliced Wasserstein estimation [2510.01061].

## 2. Fixed-size weighted and priority reservoirs

The foundational fixed-size formulation is the weighted subset-sum problem addressed by \(\mathrm{VAROPT}_k\). After processing a stream prefix \([n]\), the sampler stores a reservoir \(S\subseteq [n]\) of size at most \(k\), and any subset sum
\[
w_I=\sum_{i\in I}w_i
\]
is estimated by
\[
\hat w_I=\sum_{i\in I\cap S}\hat w_i.
\]
The threshold \(\tau_k\) is defined by
\[
\sum_{i\in[n]}\min\{1,w_i/\tau_k\}=k,
\]
and the scheme satisfies three defining properties: inclusion probabilities proportional to size in threshold form, a sample of at most \(k\) items, and no positive covariances between distinct adjusted weights. Its central claim is optimality of average subset-sum variance for every subset cardinality \(m\), and it supports the streaming recurrence
\[
\mathrm{VAROPT}_k([n])=\mathrm{VAROPT}_k(\mathrm{VAROPT}_k([n-1])\cup\{n\})
\]
as well as a mergeability law over disjoint partitions [0803.0473].

Graph Priority Sampling specializes the same priority-sampling paradigm to graph streams. Each arriving edge is provisionally inserted, the edge of lowest priority
\[
k^*=\arg\min_{k'\in \hat K}r(k')
\]
is identified if the reservoir exceeds capacity, the threshold is updated by
\[
z^*\leftarrow \max\{z^*,r(k^*)\},
\]
and \(k^*\) is evicted. Selected edges are normalized with
\[
p(k)=\min\{1,w(k)/z^*\}.
\]
The graph-specific novelty is that \(W(k,\hat K)\) can encode “number of sampled adjacent edges,” “number of triangles completed by the edge,” or a variance-oriented metric such as
\[
W(k,\hat K)=9\,|\hat \vartriangle(k)|+1.
\]
For subgraphs \(J\), the estimator is the product of constituent edge estimators,
\[
\hat S_{J,t}=\prod_{i\in J}\hat S_{i,t},
\]
and the paper establishes unbiasedness through a martingale formulation of graph stream order sampling [1703.02625].

Priority-Based Aggregation adapts order sampling to repeated keys. The stream consists of weighted items \((k_t,x_t)\), the true per-key aggregate is
\[
X_{k,t}=\sum_{s\le t,\;k_s=k}x_s,
\]
and the summary stores at most \(m\) keys. The key technical device is “a single persistent random variable across the lifetime of each key in the cache.” Priority evolves as
\[
r_{k,t}=\frac{W_{k,t}}{u_k},
\]
where \(W_{k,t}\) is accumulated weight since the latest admission of key \(k\). The algorithm keeps the top-\(m\) current priorities, uses a monotone threshold \(z^*\), and maintains unbiased estimates \(\hat X_{k,t}\) for per-key aggregates [1703.02693].

For distributed weighted reservoirs with fixed positive weights, an exact bottom-\(k\) view is also available. Each item receives an exponential key
\[
v_i=-\ln(\mathrm{rand})/w_i,
\]
and the reservoir contains the \(k\) smallest keys. This directly supports weighted and unweighted reservoir sampling in a distributed mini-batch streaming model, and the paper explicitly notes that the method remains valid when weights are “fixed metric-derived weights” known at arrival time [1903.00227]. In the with-replacement setting, each reservoir slot can be maintained as an independent one-item weighted sampler with replacement probability \(w_n/W_n\), and skip-based acceleration is obtained from the threshold
\[
W_{\text{skip}}=\frac{W}{q^{1/m}},
\]
with accepted multiplicity sampled from a zero-truncated binomial law [2403.20256].

## 3. Learned confidence, topology, and recency as reservoir metrics

Confidence Reservoir Sampling treats uniform replacement as suboptimal for continual learning because it preserves “equilibrium/fairness of storage, but not informativeness.” The admission gate remains reservoir-style:
```text
i = randint(0, t)
if i <= mem_sz:
    ...
```
but eviction is metric-driven. The score
\[
\mathcal S := EX + c\cdot MI
\]
combines exploitation rate
\[
EX=\frac{n}{a}
\]
with margin increment
\[
MI=m_{t+1}-m_t,
\qquad
m=p_y(x;\theta)-\max_{y'\neq y}p_{y'}(x;\theta).
\]
The paper defines two replacement strategies: deterministic eviction
\[
j=\arg\max_{k\in \mathcal M}\mathcal S_k
\]
and probabilistic eviction
\[
P(j)=\frac{\mathcal S_j}{\sum_k \mathcal S_k}.
\]
High-score examples are “more appropriate to replace” because they are either highly exploited or less informative. Empirically, ER-C improves average accuracy on MNIST-S, MNIST-P, CIFAR10-S, and Mini-S, and reduces forgetting on all four datasets, but the paper does not provide a formal theorem for CRS [2108.09592].

In visual tracking, the reservoir metric is explicitly time-based. The tracker maintains separate finite buffers \(\mathcal B_f\) and \(\mathcal B_b\) for foreground and background samples, used both as basis matrices for non-sparse reconstruction and as training pools for triplet-based Mahalanobis metric learning. For each new sample, time-weighted reservoir sampling sets
\[
w=q^{\mathbb I},\qquad u\sim \mathrm{Uniform}(0,1),\qquad k=u^{1/w},
\]
and inserts the sample if the corresponding class buffer is not full or if \(k\) exceeds the smallest stored key. The paper states that this balances “sample diversity and adaptability,” because the procedure is still reservoir-style random sampling while assigning later samples larger weights. Weighted reservoir sampling performs better than ordinary reservoir sampling in CLE on multiple sequences, and the implementation uses \(\Omega=300\) and \(q=1.6\) in experiments [1204.2912].

These constructions suggest two application-specific patterns. First, the reservoir can remain structurally classical while the eviction rule becomes metric-driven, as in CRS. Second, the metric can be folded directly into the key distribution, as in time-weighted tracking reservoirs.

## 4. Temporal metrics and decay-controlled reservoirs

Temporally-biased sampling formalizes age as the metric. The target condition is that, for items \(x\in B_i\) and \(y\in B_j\) at time \(t_k\),
\[
\Pr[x\in S_k]/\Pr[y\in S_k]=f(\alpha_{i,k})/f(\alpha_{j,k}),
\]
where \(f\) is a nonnegative, nonincreasing decay function and \(\alpha_{i,k}=t_k-t_i\) is age [1906.05677]. In the exponential case,
\[
f(\alpha)=e^{-\lambda \alpha},
\]
and the earlier formulation writes the ratio law as
\[
\frac{\Pr[i\in S_t]}{\Pr[j\in S_t]}=e^{-\lambda (t''-t')}
\]
for \(i\in B_{t'}\) and \(j\in B_{t''}\) [1801.09709].

The simpler scheme, T-TBS, probabilistically maintains a target sample size but does not enforce a hard cap. In the exponential case it uses per-step retention
\[
p=e^{-\lambda}
\]
and arrival acceptance
\[
q=\frac{n(1-e^{-\lambda})}{b},
\]
where \(b\) is the mean batch size. T-TBS exactly preserves exponential temporal bias, but sample size is controlled only in expectation [1801.09709].

R-TBS is the reservoir-based construction. It introduces a latent sample
\[
L=(A,\pi,C),
\]
where \(A\) is a set of \(\lfloor C\rfloor\) full items, \(\pi\) is at most one partial item, and \(C\) is sample weight. Realization includes all full items and includes the partial item with probability \(\mathrm{frac}(C)\), so
\[
\mathbb E[|S|]=C.
\]
The critical primitive is downsampling: if \(L'\) is produced from \(L\) with weight \(C'<C\), then for every item \(x\),
\[
\Pr[x\in S']=(C'/C)\Pr[x\in S].
\]
In the exponential-decay case, R-TBS maintains
\[
\Pr[x\in S_k]=\rho_k f(\alpha_{i,k}),
\qquad
C_k=\rho_k W_k=\min(W_k,n),
\]
and is proved to maximize expected sample size and minimize sample-size variance among valid samplers with the same maximal expected sample size [1906.05677]. The earlier exponential-only treatment presents the same idea in terms of item weights
\[
w_t(i)=e^{-\lambda(t-\tau_i)},
\qquad
W_t=\sum_{j=1}^t |B_j|e^{-\lambda(t-j)},
\]
with inclusion law
\[
\Pr[i\in S_t]=\Bigl(\frac{C_t}{W_t}\Bigr)w_t(i),
\qquad
C_t=\min(n,W_t).
\]
That formulation emphasizes the bridge to classical reservoir sampling: when there is no decay and batches are singletons, it reduces to the classical uniform reservoir law [1801.09709].

For general decay functions, the later paper consolidates old batches into a single exponentially decaying latent sample and introduces a headroom parameter \(n'>n\). The resulting scheme trades off footprint, sample-size stability, and decay fidelity, while providing explicit controls \(\delta_1\) and \(\delta_2\) on approximation error and bounded footprint [1906.05677].

## 5. Reservoirs inside metric estimators and constrained candidate streams

ReSWD applies weighted reservoir sampling to the Monte Carlo estimator of Sliced Wasserstein Distance. At optimization step \(t\), the reservoir stores tuples
\[
(\theta_i,w_i,k_i,t_i),
\]
where \(\theta_i\) is a projection direction, \(w_i\) its associated weight, \(k_i\) its reservoir key, and \(t_i\) its insertion time. Each candidate direction is scored by
\[
D(\theta)=W_p(\pi_\theta\mu,\pi_\theta\nu),
\]
and receives a weighted-reservoir key
\[
k(\theta)=u^{1/D(\theta)},\qquad u\sim\mathcal U(0,1).
\]
Historical entries are decayed by
\[
\tilde w_i \leftarrow w_i e^{-(t-t_i)/\tau},
\qquad
\tilde k_i \leftarrow k_i e^{-(t-t_i)/\tau},
\]
the next reservoir keeps the \(K\) directions with smallest keys, and the loss is computed with the self-normalized estimator
\[
\widehat S_p(\mu,\nu)=\sum_{i=1}^K
\frac{1/q(\theta_i)}{\sum_j 1/q(\theta_j)}\,D(\theta_i).
\]
The paper presents this as an unbiased Monte Carlo estimate, monitors
\[
\mathrm{ESS}=\frac{(\sum_i w_i)^2}{\sum_i w_i^2},
\]
and resets the reservoir when \(\mathrm{ESS}<\alpha K\) with \(\alpha=0.5\). Empirically, ReSWD improves final matching score on synthetic benchmarks and improves several color-correction metrics relative to standard SWD, while adding modest overhead [2510.01061].

A different but related extension appears in sampling over joins. The generalized reservoir sampler with predicate maintains a uniform sample of \(k\) real items from a stream that may also contain dummy items. It uses Li-style skipping with
\[
q=\left\lfloor \frac{\ln(u)}{\ln(1-w)} \right\rfloor,
\qquad
w\gets w\cdot u^{1/k},
\]
but updates the reservoir only when the skipped-to item satisfies the predicate \(\theta\). The paper proves exact uniformity over real items and an instance-optimal expected running time
\[
O\!\left(\sum_{i=1}^N \min\left(1,\frac{k}{r_i+1}\right)\right)
\]
when primitive access costs are constant. Its synthetic evaluation uses an edit-distance predicate over strings. This suggests a route for metric-thresholded reservoirs in which the admissible set is defined by a metric predicate and reservoir logic operates over a denser candidate stream that may contain non-eligible items [2404.03194].

## 6. Guarantees, limits, and conceptual boundaries

The strongest guarantees appear when the metric reduces to a fixed thresholdable weight or to a controlled decay law. \(\mathrm{VAROPT}_k\) gives “variance optimal unbiased estimation of subset sums,” preserves exact threshold marginals, and has no positive covariances [0803.0473]. GPS proves unbiased edge and subgraph estimators through a martingale formulation, even when subgraph estimators are products of edge estimators computed at different points in the stream [1703.02625]. PBA proves unbiased estimates of true aggregates under repeated keys [1703.02693]. Exponential R-TBS provides exact decay-controlled inclusion probabilities together with a guaranteed upper bound on sample size, and the later treatment proves optimality in expected sample size and sample-size stability [1801.09709] [1906.05677].

The guarantees weaken when the metric is adaptive, model-dependent, or heuristic. CRS is motivated by replay saturation and margin dynamics, but the paper explicitly provides no theorem, proof of optimality, or isolated complexity analysis for the reservoir component [2108.09592]. ReSWD repeatedly states that the estimator remains unbiased, but the manuscript does not provide a full theorem-proof derivation of unbiasedness for the exact self-normalized estimator [2510.01061]. Time-weighted reservoir sampling for tracking is justified by adaptability and diversity, not by an exact inclusion law over the original stream [1204.2912].

A further boundary concerns what counts as reservoir sampling at all. “A Simple Sampling Method for Metric Measure Spaces” defines
\[
q_{\mu,s}(x,y)=\left(\mu(B[x,d(x,y)])+\mu(B[y,d(x,y)])\right)^s
\]
and studies \(\varepsilon\)-nets, quasimetric metrization, and bilipschitz equivalence to sampling subsets of some \(\mathbb R^N\). It is a geometric sampling theory, not a one-pass bounded-memory reservoir algorithm [1103.3843]. Conversely, parallel weighted reservoir methods based on fixed exponential keys
\[
v_i=-\ln(U_i)/w_i
\]
are directly applicable when metric information can be encoded as fixed positive per-item weights at arrival time, but the same paper states that they do not directly solve adaptive diversity-aware settings in which weights depend on the current reservoir or on pairwise distances among sampled items [1903.00227].

The literature therefore suggests a precise but plural understanding of metric reservoir sampling. In the most developed cases, it means fixed-size weighted or temporally weighted reservoir maintenance with explicit threshold formulas, mergeability, martingale unbiasedness, or variance optimality. In more application-specific cases, it means retaining the outer reservoir skeleton while replacing uniform eviction by a confidence, topology, or recency metric. And in metric-estimation problems such as SWD, it means storing and reusing metric evaluation components—projection directions rather than data items—inside a bounded reservoir to reduce variance.

Source: https://www.emergentmind.com/topics/metric-reservoir-sampling