---
title: Sample-and-Query Model
url: https://www.emergentmind.com/topics/sample-and-query-model
type: topic
---

# Sample-and-Query Model

Searching arXiv for recent papers on “sample-and-query model” and closely related formulations.
In the cited literature, the “Sample-and-Query Model” denotes a family of access abstractions in which an algorithm does not traverse or materialize its full underlying object, but instead works through sampled information together with restricted query access. The underlying object may be a static dataset summarized by a fixed-size uniform sample, a query-conditioned synthetic sample generator for approximate analytics, a designed measurement system over hidden variables, a black-box model queried on selected inputs, a vector exposed through sample-and-query primitives, or a quantum-encoded state exposed through approximate sample-and-query access [2208.06753] [2101.02914] [1712.00157] [2602.18934] [2412.01889]. Across these settings, the common structural idea is that computation is driven by a controlled interface—sampling, querying, or both—rather than unrestricted full-data access.

## 1. Access pattern and formal variants

In the cited work, the model is not a single universal formalism. Instead, it appears as a recurrent pattern: preprocessing, partial acquisition, or oracle interaction produces a restricted interface; later algorithms answer queries, infer global properties, or recover hidden structure using only that interface. In database-oriented settings, the sample is often a retained subset of tuples. In algorithmic and quantum settings, the “sample” may instead be an \(\ell_2\)-distributed index draw, copies of a state, or local partial instantiations of a random object. In security settings, the sample is often a selected set of candidate inputs or real seed examples chosen before spending black-box queries.

| Setting | Sample primitive | Query primitive |
|---|---|---|
| Finite-population sketching | Uniform sample without replacement | Predicate frequency query on retained sample |
| AQP and learned AQP | Stratified or generated tuples | Aggregate / group-by evaluation |
| Designed acquisition | Random parity measurements | Recovery from queried measurements |
| Vector / quantum access | \(\ell_2\)-distributed sampling or approximate sample access | Entry query or amplitude query |
| Local random objects | Partial on-the-fly instantiation | Local structural queries |

One influential exact classical formulation is sample-and-query access to a vector \(v \in \mathbb{C}^d\): query any entry \(v(i)\), sample \(i\) from \(\Distribution(i)=|v(i)|^2/\|v\|^2\), and read \(\|v\|\). The quantum-compatible relaxation replaces exact access by approximate query, approximate sample, and approximate norm estimation, yielding ASQ and \(\ASQ[\phi]\) interfaces [2412.01889]. At the opposite end of the design space, some database papers treat a fixed retained sample itself as the synopsis, while others augment it with auxiliary statistics, generative models, or partition aggregates [2208.06753] [2103.15994].

## 2. Finite-population inference from retained samples

A particularly clean sample-and-query formulation arises when preprocessing scans a dataset of size \(n\), stores a uniform sample \(S\) of exactly \(s\) items without replacement, and later answers arbitrary predicate-frequency queries from that sample alone. If a query predicate matches \(m\) records in the full dataset and \(k\) records in the sample, then the correct sampling law is hypergeometric, with
\[
p(n,m,s,k)\equiv \binom{n}{s}^{-1}\binom{m}{k}\binom{n-m}{s-k}.
\]
The left and right tails are
\[
L(n,m,s,k)\equiv \sum_{i=0}^{k} p(n,m,s,i), \qquad
R(n,m,s,k)\equiv \sum_{i=k}^{\min(s,m)} p(n,m,s,i),
\]
and exact finite-population PAC bounds are obtained by inversion:
\[
m_u(n,s,k,\delta)\equiv \max\{\, m \mid L(n,m,s,k)\ge \delta \,\},
\]
\[
m_d(n,s,k,\delta)\equiv \min\{\, m \mid R(n,m,s,k)\ge \delta \,\}.
\]
This gives high-confidence bounds on the unknown count \(m\), or equivalently on the true frequency \(m/n\), for any post hoc predicate that can be evaluated on sampled items [2208.06753].

The statistical claim is unusually sharp. The bounds are “sharp” when exact tail inversion is performed exactly, and “off by only one” when approximate tail computation preserves the threshold ordering near the optimum. The local numerical difficulty is governed by
\[
\Delta(m)=L(n,m,s,k)-L(n,m+1,s,k)
      =p(n,m,s,k)\frac{s-k}{n-m},
\]
which quantifies how much precision is needed to distinguish adjacent feasible counts. The lower bound reduces by symmetry to the upper-bound computation via
\[
m_d(n,s,k,\delta)=n-m_u(n,s,s-k,\delta).
\]
The computational backbone is binary search over \(m\), using monotonicity of \(L(n,m,s,k)\) in \(m\), together with high-accuracy hypergeometric tail evaluation. The paper gives two implementations: direct combinatorial term computation with Loader-style interleaved multiply/divide, and a Stirling-log method based on
\[
\ln n! \approx n\ln n - n + \frac{1}{2}\ln(2\pi n) + \frac{1}{12n} - \frac{1}{360n^3} + \frac{1}{1260n^5} - \frac{1}{1680n^7}.
\]
For a stored explicit sample, counting \(k\) is \(O(s)\); then inversion is \(O(s\log n)\) with direct term evaluation or \(O(k\log n)\) with the Stirling-based method. The same framework also handles simultaneous guarantees across multiple queried predicates by replacing \(\delta\) with \(\delta/(2j)\) per side for \(j\) queries [2208.06753].

## 3. Approximate query processing and database realizations

In approximate query processing, the sample-and-query model usually appears as a reusable synopsis or as a query-specific sampling controller. A canonical reusable-sample formulation is CVOPT, which builds a single stratified sample under memory budget \(M\) to support many future `GROUP BY` aggregates. Its objective is not variance of one scalar answer, but a norm of per-group coefficients of variation. For single aggregate, single group-by, with group \(i\) of size \(n_i\), mean \(\mu_i\), standard deviation \(\sigma_i\), weight \(w_i\), and stratum sample size \(s_i\), the paper derives
\[
\mathrm{Var}(y_i)=\frac{\sigma_i^2(n_i-s_i)}{n_i s_i},
\qquad
\mathrm{CV}(y_i)=\frac{1}{\mu_i}\sqrt{\frac{\sigma_i^2(n_i-s_i)}{n_i s_i}},
\]
and the optimal allocation for the weighted \(\ell_2\) objective is
\[
s_i = M \cdot \frac{\sqrt{w_i}\,\sigma_i/\mu_i}
{\sum_{j=1}^r \sqrt{w_j}\,\sigma_j/\mu_j}.
\]
The framework extends to multiple aggregates and multiple group-bys by stratifying at the finest joint granularity and optimizing the resulting coefficients \(\beta_c\) per finest stratum [1909.02629].

A different AQP line treats sample size itself as the optimization variable. MISS formulates Sample Size Optimization as
\[
\min_{\mathbf n} C(\mathbf n)
\quad \text{s.t.} \quad
\Pr\!\bigl(d(\hat\theta,\theta)\le \epsilon\bigr)\ge 1-\delta,
\]
with \(C(\mathbf n)=\sum_i n_i\), and models query error by a power law such as \(d(\hat\theta,\theta)\approx a n^{-b}\). In the multi-group case it fits
\[
H(\mathbf n;\boldsymbol\beta)=\beta_0-\sum_{i=1}^m \beta_i \log n_i
\]
from bootstrap-estimated error profiles, then predicts sample sizes by solving the induced constrained optimization. This is not a fixed-sample reuse model; it is query-specific adaptive sample refinement during query answering [1807.11054].

PASS makes the hybrid form explicit. It stores a tree of exact partial aggregates over data partitions, and leaf-level stratified samples. A query is decomposed into fully covered partitions, answered exactly from precomputed summaries, and partially overlapping leaves, answered from samples. The query-time uncertainty is therefore confined to
\[
\pm \lambda \cdot \sqrt{\sum_{P_i\in R_{partial}} w_i^2\cdot V_i(q)},
\]
rather than to the whole predicate region. The physical design objective is a minimax partition optimization over query error, and the paper gives 1D dynamic programs and multidimensional k-d-tree approximations [2103.15994].

Learned AQP introduces a further variant: query-conditioned sample generation rather than direct answer prediction. A conditional Wasserstein GAN is trained on tuples with group labels, or with bucket-plus-group labels for predicate-aware group-by queries, so that the generator can synthesize tuples from \(p(\mathbf{x}\mid A=a)\) or \(p(\mathbf{x}\mid \text{bucket}=b,A=a)\). The generated tuples are then fed into standard aggregate estimators, and the method can be combined with CVOPT-style allocation and online aggregation [2101.02914].

Open-world query processing pushes the model beyond unbiased sampling. Mosaic distinguishes populations, samples, and metadata, and lets users ask `CLOSED`, `SEMI-OPEN`, or `OPEN` queries over a population relation represented only by samples plus marginals. If inclusion probabilities are known, weights are \(1/\Pr_S(t)\); if unknown, the system proposes IPF-style reweighting against metadata for `SEMI-OPEN`, and a marginal-constrained sliced-Wasserstein generator for `OPEN` [1912.07777]. Closely related in spirit, PAO interleaves predicate sampling and query optimization: it repeatedly samples unknown predicate selectivities, computes a candidate plan, finds a selectivity cube in which that plan is \(\alpha\)-optimal, and stops once Hoeffding-based confidence in that cube exceeds \(\delta\) [1511.01782].

## 4. Designed queries, query difficulty, and query-to-sampling conversion

Not all sample-and-query models begin from a passive retained sample. In query-based data acquisition, the “sample” may itself be a response to a designed query. A clean example is reconstruction of a hidden binary vector
\[
x=(X_1,X_2,\dots,X_k)^T \in \{0,1\}^k
\]
from parity queries
\[
Y_i = \operatorname{mod}\!\left(\sum_{j=1}^k v_{ij}X_j,\,2\right),
\qquad i=1,\dots,n.
\]
Here each query is specified by a binary design vector \(v_i\), and the average query degree
\[
\bar d = \sum_{d=1}^k d\,\Omega_d
\]
measures query difficulty. With a Soliton degree law, the fundamental trade-off is
\[
n = \Theta\!\left(\max\left\{k,\frac{k\log k}{\bar d}\right\}\right),
\]
so harder parity queries reduce the required number of samples until the irreducible \(k\)-equation barrier dominates [1712.00157].

Another strand runs in the opposite direction: replacing active query patterns by oblivious sampling. For property testing over a fixed alphabet, every non-adaptive constant-query tester can be converted into a sample-based tester in which each coordinate is sampled independently with probability \(p\). In the one-sided case, the conversion yields
\[
p=O\!\left(\frac{\log(|\Xi|)q^3}{\epsilon}\,n^{-1/q^2}\right),
\]
so the expected number of inspected coordinates is
\[
pn=\Theta(n^{1-1/q^2}),
\]
a sublinear power of \(n\). The combinatorial mechanism is the extraction of generalized sunflowers, called pompoms, from the support hypergraph of the original tester [1504.00695]. This result is noteworthy because it shows that, at least for non-adaptive constant-query testers, sophisticated property-specific query distributions can sometimes be replaced by a universal sample-only access pattern.

## 5. Learning and security: query allocation around informative samples

In adversarial learning and privacy attacks, the sample-and-query model becomes a resource-allocation problem: which candidate inputs should be queried, and how much information should be extracted from each? LoMime addresses label-only membership inference by moving almost all online query cost into a one-time extraction phase. Starting from a small auxiliary set \(D_A\), it constructs a candidate pool \(D_Q^t\) by perturbation and replication, then filters it by entropy sampling,
\[
Q_{\text{entropy}^t = \arg\max_{Q \subseteq D_Q^t,\ |Q| = B} H\big(S^{t-1}(Q)\big),
\]
entropy-gradient clustering, and loss-based sampling before querying the target model \(M\). The queried labels train a surrogate \(S\), and membership inference is then performed offline on \(S\) using the decision-boundary distance
\[
d_{\text{boundary}}(x_i)=\min_{\delta_i \in \mathbb{R}^d}\|\delta_i\|_2
\quad \text{s.t.} \quad S(x_i+\delta_i)\neq S(x_i).
\]
The central access shift is from repeated target queries per attacked record to amortized extraction followed by offline querying of the surrogate [2602.18934].

QEDG studies hard-label, data-free model stealing under a similar query-economics lens. Synthetic inputs are generated by optimizing
\[
\mathcal{L}_G = \mathcal{L}_{\mathrm{clf}} + \alpha \mathcal{L}_{\mathrm{harm}} + \beta \mathcal{L}_{\mathrm{div}},
\]
where \(\mathcal{L}_{\mathrm{harm}}\) pushes samples toward low-variance, decision-boundary-adjacent regions of the substitute, and \(\mathcal{L}_{\mathrm{div}}\) spreads them along the boundary. Since each target query returns only a hard label, the method adds “query-free sample augmentation” for non-disputed samples and upweights disputed samples during substitute training [2412.15276].

SPSG is a particularly literal sample-and-query stealing model. With only a limited number of real images, it queries a victim classifier on the original sample \(x\) and on structured superpixel perturbations
\[
x_j^c = x + \varepsilon E_j^c,
\qquad
g_j^c \approx \frac{f(x + \varepsilon E_j^c) - f(x)}{\varepsilon},
\]
thereby estimating superpixel sample gradients rather than merely obtaining one label per image. The substitute is then trained with output matching and gradient matching. The practical advantage is that superpixel querying reduces per-sample query counts from pixel-level finite differences such as \(150{,}528\) to values like \(137\), \(256\), or \(457\), depending on segmentation [2406.18540].

PSS-MIA turns black-box membership inference into an explicit pre-query selection problem. For each candidate sample \(z\), it computes the Loss-Gap Ranking score
\[
r(z) = \mu_{\mathrm{out}(z)} - \mu_{\mathrm{in}(z)},
\]
where \(\mu_{\mathrm{in}(z)}\) and \(\mu_{\mathrm{out}(z)}\) are true-label losses under reference models trained with and without \(z\). Only the top-ranked subset is then queried and passed to a downstream MIA. Under a \(0.1\%\) FPR constraint, this pre-query ranking saves at least \(83.1\%\), \(60.6\%\), and \(80.4\%\) of the query budget on CIFAR-10, CIFAR-100, and CINIC-10, respectively [2606.30081].

## 6. Quantum and local-access generalizations

Quantum work makes the access abstraction explicit. For a vector \(x \in \mathbb{C}^d\), approximate query access returns \(\hat x(i)\) with additive error \(\epsilon\) and two-sided error probability at most \(1/3\) in time \(\Query(\epsilon)\). Approximate sample access returns an index from
\[
\Distribution_x(i)=\frac{|x(i)|^2}{\|x\|^2}
\]
with one-sided failure probability at most \(1/3\), and approximate norm access estimates \(\|x\|^2\). Together these yield ASQ; the oversampling relaxation \(\ASQ[\phi]\) allows sampling from a dominating vector \(\tilde x\) satisfying
\[
|\tilde x(i)|\ge |x(i)|,\qquad \|\tilde x\|^2\le \phi\|x\|^2.
\]
The model is realizable from state preparation and block encodings: if an \(\mathfrak n\)-qubit state \(\ket{\psi}\) can be prepared in time \(T\), then
\[
\QNorm(\epsilon)=0,\qquad \Sample=T,\qquad \Query(\epsilon)=\BigO(T\epsilon^{-2}\mathfrak n).
\]
This interface is then used to build compositional algorithms such as approximate linear combinations and inner-product estimators [2412.01889].

A complementary result studies lower bounds by relating quantum sample access to quantum query access. For a quantum state-testing problem \(\mathcal P\), let \(\mathsf S(\mathcal P)\) be the number of copies of the state needed in the sample model and \(\mathsf Q_\diamond(\mathcal P)\) the block-encoding query complexity. The paper proves the lifting theorem
\[
\mathsf{Q}_\diamond(\mathcal{P}) =
\Omega\!\left(\frac{\sqrt{\mathsf{S}(\mathcal{P})}}{\log \mathsf{S}(\mathcal{P})}\right),
\]
showing an essentially quadratic relation between sample and query complexity. Applications include lower bounds \(\widetilde \Omega(\beta)\) for Gibbs sampling and \(\widetilde \Omega(1/\sqrt{\Delta})\) for the entanglement entropy problem [2308.01794].

A non-quantum but closely related local-access perspective appears in work on huge random objects. There the goal is not to retain a sample of a fixed object, but to answer local queries while incrementally constructing only the necessary parts of a random object sampled from the target distribution. A local-access implementation must satisfy two conditions: there exists a single consistent object \(X\) such that all answers equal \(F_i(X)\), and the induced distribution \(\hat{\mathsf X}^\Pi\) must satisfy
\[
\|\hat{\mathsf X}^\Pi-\mathsf X^\Pi\|_1 \le \epsilon.
\]
The paper gives such implementations for random graphs, Dyck paths, rooted and binary trees, well-bracketed expressions, and uniform graph colorings, supporting queries such as Vertex-Pair, Next-Neighbor, Random-Neighbor, Height, and First-Return [1711.10692].

## 7. Limits, trade-offs, and conceptual significance

The literature repeatedly emphasizes that sample-and-query access trades completeness of access for sharper control of storage, query cost, or exposure. The trade-offs differ by domain. In retained-sample frequency inference, only predicates reducible to success/failure labeling on sampled records are supported, simultaneous validity across many queried conditions requires union-bound correction, and high numerical precision may be necessary because neighboring hypergeometric tails can differ on the order of \(\delta/(nk)\) [2208.06753]. In reusable AQP synopses, guarantees are strongest for the optimized query family; no significantly sublinear sample can support all arbitrary future groupings and predicates accurately, and many methods remain centered on AVG-like estimators rather than a fully general SQL semantics [1909.02629].

Other systems expose different limitations. MISS is explicitly query-specific rather than a one-sample-for-all-queries synopsis [1807.11054]. Mosaic’s `OPEN` semantics are approximate and assumption-dependent, and the paper does not provide formal confidence intervals or universal identifiability guarantees when sampling probabilities are unknown [1912.07777]. Query-to-sampling conversion in property testing is presently limited to non-adaptive constant-query testers over a fixed alphabet, with exponent \(1/q^2\) rather than the conjectured \(1/q\) [1504.00695]. In ASQ, randomized access and finite precision complicate the closure arguments that were straightforward in exact classical SQ models [2412.01889].

In learning and security, the central constraints are different: black-box queries may be expensive, rate-limited, or logged, so the problem becomes one of concentrating queries on high-value samples or boundary regions. This is why extraction-based MIAs, pre-query ranking, and superpixel probing all separate sample selection from query expenditure [2602.18934] [2606.30081] [2406.18540]. A plausible implication is that “sample-and-query” is best treated not as a single theorem or interface, but as an access-design principle: specify what can be sampled, what can be queried, what consistency guarantee links those operations to the hidden full object, and what trade-off is accepted in exchange for avoiding unrestricted access.

Source: https://www.emergentmind.com/topics/sample-and-query-model