WorksComputer Science
Hypothesis Selection via Weighted Medians
Abstract
Given distributions (hypotheses) and samples from an unknown target distribution , proper hypothesis selection seeks a distribution whose total variation distance to is close to the best achievable within the known distributions. We give an algorithm that, using target samples, running in time, with probability at least , returns satisfying The algorithm achieves the optimal approximation factor and sample complexity. The running time improves the dependence on the failure probability from polynomial to logarithmic in the state-of-the-art bound of Aamand, Aliakbarpour, Chen, and Silwal (COLT 2026), thereby answering their Question~2.
Introduction
Selecting a probability distribution from a finite class is a basic task in statistical learning. The target distribution need not belong to the class: the aim is to compete with the best available distribution using samples from the target. In hypothesis selection, the quality of this approximation is measured in total variation distance, and the challenge is to obtain statistical guarantees with a running time that scales favorably with the number of distributions.
Let be a class of distributions, each a probability measure on a measurable space , and let be the unknown target distribution. Fix a common dominating measure for , , and write for the density of . We have sample access to and sample and density-query access to every ; the density of is not available to the algorithm. Writing , the goal is to return a probability measure such that, with probability at least ,
Here is the additive error and is the failure probability. The selection is proper if ; otherwise, the algorithm is allowed to be improper.
Statistical guarantees. Classical minimum-distance methods achieve approximation factor using samples from [11, 8]. The factor 3 is also optimal for proper selection with a sample size independent of the domain size [7, 1]. Allowing an improper output improves the achievable factor to 2 [7, 5]. Thus, for proper selection, the remaining issue is how efficiently the optimal statistical guarantee can be attained.
Computational guarantees. Classical factor-3 selectors have cubic or quadratic running times in [8, 10]. Aliakbarpour, Bun, and Smith [2] obtained a nearly linear dependence on , with running time and optimal target-sample complexity. Aamand, Aliakbarpour, Chen, and Silwal [1] improved the running time to for . Selected bounds are compared in
Table 1. Proper hypothesis selection with approximation factor 3. All rows use target samples; for polynomially small failure probability, this is . More results are collected in [1 Table 1].
Table 1. Aamand et al. ask whether proper selection can simultaneously achieve factor 3, target samples, and running time [1 Question 2]. We answer this question affirmatively.
Theorem 1.1 (Fast proper hypothesis selection). Let , , and . With probability at least , Algorithm 1 returns a distribution which satisfies
The algorithm uses target samples, and runs in time.
Overview of the method
The algorithm compares the input distributions with the target through a common median measure. Starting from uniform weights, it updates the weights so that the median measures are close, on average, to a best input distribution.
At round , the algorithm maintains positive weights summing to one. For each point , let be the lower weighted median of under these weights, and let be the measure with density . Since need not have mass one, we measure its distance to by , where denotes the total variation norm.
Balanced median tests indicate whether lies below or above , with fractional tie values ensuring . These tests yield gains that guide multiplicative weight updates: positive gains increase the corresponding weights, while negative gains decrease them. Since the median measure is not normalized and is difficult to sample from directly, each round uses one target sample and one sample from an easy-to-sample proposal distribution to compute the gains. Importance weights correct for the difference between the proposal and the median measure, with the proposal chosen to keep these weights bounded.
The balance of the tests gives , so the updates preserve the total weight without renormalization. A standard multiplicative-weights argument [3], combined with the Azuma–Hoeffding inequality, shows that each input distribution’s average conditional gain is at most . The tests also ensure that
where records the previous rounds. Thus, with high probability, every distribution satisfies , where . Applying the triangle inequality through then bounds the average distance between and by
The same proposal samples provide bounded, unbiased estimates of , including a correction for the mass of . Azuma-Hoeffding inequality shows that, with high probability, for every input distribution, the average estimate is close to the average distance, namely . The algorithm returns the input distribution with the smallest estimated average distance to the median measures. Uniform concentration of the distance estimates and the choice of imply
Averaging the triangle inequality through gives
Tracking the constants yields with probability at least after rounds. Each round evaluates the input densities and computes weighted medians only at the two sampled points, using time and one target sample.
Preliminaries
Problem setting and computational model
Let be probability distributions on a measurable space , and let be the unknown target distribution on the same space. Fix a common -finite dominating measure for , and write
Here is the density of the distribution relative to . The target density is used only as mathematical notation and is not available to the algorithm. We access through a sample oracle, and each through a sample oracle and a density oracle that evaluates at any supplied point . Every sample-oracle call returns a fresh independent draw from the requested measure.
For accuracy and failure probability , our goal is to return a distribution such that
with probability at least over the samples and the algorithm’s internal randomness. The selection is proper because the output must be one of the input distributions.
We use an exact-real oracle model: sample-oracle calls, density evaluations, arithmetic operations (addition, subtraction, multiplication, or division), comparisons, ceiling operations, and draws from uniform distributions each take unit time. The algorithm’s running time is the total number of such operations. The sample complexity only counts the number of samples drawn from the target distribution .
Notation and density conventions
Write , use ln for the natural logarithm and log for the base-two logarithm, and set . Throughout the paper, fix , breaking ties by a fixed rule.
Uppercase symbols denote measures and their lowercase counterparts denote densities relative to . In particular, , , and denote the densities of the mixtures , , and the median measure introduced in ??.
Since is the density of with respect to , denotes the probability of a measurable set . The same convention applies to , , and , although need not have mass one.
Total variation and finite measures
For a finite signed measure on , write for its total variation norm. If has density relative to , then . For probability measures , , we use
For finite nonnegative measures , and any measurable function with , the total variation norm gives
We also use the triangle inequality for this norm, which applies even when the intermediate measure is not a probability measure. In particular, for probability measures , and a finite nonnegative measure ,
When , the quantity denotes half the total variation norm, rather than the total variation distance between two probability measures.
A useful identity accounts explicitly for the mass of such a measure. If has density and mass , then
Indeed, and give this identity directly. The correction is needed because the median measures used by the algorithm are not normalized.
Fast proper hypothesis selection
In this section, we present a fast proper hypothesis selection algorithm, Algorithm 1, and prove Theorem 1.1, which is restated below for convenience. § 1.1 provides an overview of the algorithm.
Theorem 3.1 (Theorem 1.1 restated). Let , , and . With probability at least , Algorithm 1 returns a distribution which satisfies
The algorithm uses target samples, and runs in time.
Weighted medians and balanced median tests
We now introduce the mixture of the input distributions defined by a weight vector, the median measure constructed from the mixture, and the balanced median tests that compare the median with each input distribution. All of these objects are updated in each round of the algorithm, and the round subscript is omitted in this section.
Let be a vector of positive weights with , and let be the corresponding mixture of input distributions. Then is a probability measure with density .
Let be the lower weighted median of : the smallest value whose cumulative weight is at least . The function is measurable, since it is selected from finitely many measurable density functions using measurable comparisons. Define the median measure by . Its mass need not be one, so we do not normalize it.
Let be the total weight on density values below , with and defined analogously. Define the balanced median tests by
The tests are measurable signed functions that indicate whether is below or above the median, with a fractional tie value that exactly balances the total weight on each side. Replacing the tie value by a fixed sign or by zero does not preserve in general, which is crucial for the multiplicative weight updates. The denominator is positive because the median is an input value and all weights are positive.
Lemma 3.2 (Weighted-median identities). For every and ,
In particular, is a finite nonnegative measure with .
Proof of Lemma 3.2. Fix . The lower-median definition gives and . Since , these inequalities imply
Thus the tie value lies in , proving the first identity.
Summing the three cases of Eq. (3) gives
The third identity follows directly from the sign of .
Finally, at least half the weight lies on values at least , so
Integrating gives since is a probability measure.
Rounded weights and proposal distribution
In each round, the algorithm compares the median measure with the target distribution to guide the weight updates. Sampling from the target is straightforward, but the median measure is not normalized and is difficult to sample from directly. We therefore introduce a proposal distribution which is easy to sample from and use importance weights to correct for the difference between the proposal and the median measure. The subscript is also omitted in this section.
Directly sampling from the mixture is also difficult, since the mixture weights are arbitrary real numbers. We thus round the weights to dyadic probabilities, which allows exact sampling from the rounded mixture in linear time, using a uniform integer draw and a sample from one of the input distributions.
Choose the least power of two , so , once for the entire algorithm. Given , first set . Increase by , so that the final integer weights sum to , and define the rounded weights, mixture, and density by
Lemma 3.3 (Proposal properties). For every and ,
Proof of Lemma 3.3. Before increasing , positivity of the weights gives , and hence . The remaining integer mass is nonnegative, and adding it to preserves and . Dividing by gives the first two inequalities.
Multiplying by and summing gives . Together with from Lemma 3.2, we get .
Sampling from . Draw in unit time. Scan the cumulative sums to find the unique index such that , and return a fresh sample from . The index equals with probability , so the procedure returns a sample from . The sampling time is : the uniform draw and candidate-sample query each take unit time, and the cumulative scan takes time.
The iterative procedure
We now describe the iterative procedure, in which we use the balanced median tests to guide how to update the weights such that the new median measure is closer to the target.
Define the number of rounds
Let be the filtration generated by the random choices in the algorithm, with containing the fixed input. At round , the weights , median measure , tests , and proposal are fixed. Draw independent fresh samples and , and define
Since every , if then all and vanish. Ratios with denominator are defined to be zero. This convention preserves the integral identities, and assigns that set probability zero. The expectation calculations in § 3.4.2 make this explicit.
Gains and distance estimates. is the importance weight that corrects for the difference between the proposal and the median measure. § 3.4.2 proves that
By the definition of the tests, a positive gain suggests that lies, on average, on the same side of the median as the target, so increasing the weight of would move the median measure closer to the target, while a negative gain suggests the opposite. Starting from uniform weights, we update the weights of the input distributions based on the gains. It’ll be shown that this update rule ensures that the average distance between the median measures and the target distribution across all rounds is small.
The distance estimates are collected in each round to estimate the average distance between the median measures and each input distribution. Since , it’ll be shown that the distance estimate lies in an interval of length four, independently of and the current weights. This bound is crucial for the concentration analysis via the Azuma-Hoeffding inequality in Lemma 3.7. In contrast, the direct estimate introduces the ratio , whose bound depends on .
Each round takes linear time. The algorithm represents implicitly through the weights and the densities of the input distributions. In each round, it computes the weighted median and tests only at and . Using the idea of median-of-medians [6], Section A shows that the weighted median can be computed in time. Then the tests can be computed in time by scanning the input densities and accumulating the weights. Rounding, proposal sampling, density evaluation, and the updates also take time, giving a total of per round.
Algorithm 1: Proper hypothesis selection via weighted medians
Input: Sample oracle for ; sample and density oracles for ; accuracy and failure probability .
Output: An input distribution .
Choose as the least power of two at least ; set
Initialize and for every
for do
Use to define and by Eq. (3)
Construct and using the rounding procedure of Lemma 3.3
Draw independent fresh samples and
Evaluate all , the two weighted medians and their tests, and
Compute by Eq. (4)
for do
Compute and by Eq. (5) and Eq. (6)
Return for
Analysis of the algorithm
In this section, we analyze the performance of Algorithm 1 and prove Theorem 3.1. Each round of the algorithm draws one sample from the target distribution, and runs in time. The total sample complexity is , and the total time complexity is , as claimed in Theorem 3.1. We now show that the output distribution satisfies with probability at least .
Bounded estimates and validity of the updates
Suppose that the current weights are positive and sum to one. By Lemma 3.3, , so and
Together with from Lemma 3.2, these bounds imply
Validity of the update. The initial weights are positive and sum to one. The balance identity , in Lemma 3.2 holds pointwise, and therefore
Consequently,
Moreover, , so every update factor is positive. Induction shows that all weight vectors, medians, and proposals are well defined, and that Eq. (7) holds in every round.
With this in place, the following standard multiplicative-weights argument [3] bounds the cumulative gain of each input distribution.
Lemma 3.4 (Deterministic gain bound). For every ,
Proof of Lemma 3.4. Since and , it holds that
where the first inequality uses for , and the second uses . The weights are positive and sum to one, so and . Rearranging gives
Finally, since , we have . Together with , this gives
Conditional expectations
Recall the filtration from § 3.3. Define
Note that need not have mass one.
Lemma 3.5 (Conditional expectations). For every round and coordinate ,
Proof of Lemma 3.5. Conditional on , the current weights, median, tests, and proposal are fixed, and and are fresh and independent. By the sign identity in Lemma 3.2,
Importance sampling gives
On the set , which has measure zero under , we have already defined the ratio to be zero. The expectation can therefore be written as an integral over . After canceling on this set, we obtain the last equality by extending the integral to all of , since wherever . Since , we obtain
Combining Eqs. (8) and (9) and applying Eq. (1) yields
For the distance estimate, Eq. (2) gives
Both and vanish wherever , so the same importance-sampling calculation yields
Substituting into Eq. (6) proves
Concentration bounds
We now show that the average gains and distance estimates concentrate around their conditional expectations. The weights, weighted medians and proposals depend on previous samples, so we use a conditional form of the Azuma–Hoeffding inequality [4, 9].
Lemma 3.6 (Azuma–Hoeffding inequality). Let be a filtration and let be a sequence of random variables, each -measurable with . Suppose that almost surely, where are -measurable and for a constant . Then for ,
The same bound holds for the lower tail.
Lemma 3.7 (Concentration of gains and distance estimates). With probability at least , the following inequalities hold simultaneously for every :
Proof of Lemma 3.7. and imply .
For a fixed , the differences have conditional mean zero and conditional range of length five by Eq. (7). Apply Lemma 3.6 with and to bound the probability that the first inequality fails for this by . A union bound over gives failure probability at most .
By Lemma 3.5, has conditional mean zero, and its conditional range has length four by Eq. (7). Apply both tails of Lemma 3.6 with and to bound the probability that the second inequality fails for this by . A union bound over gives failure probability at most .
Combining the two failure probabilities proves the simultaneous guarantee.
Combining Lemmas 3.4, 3.5 and 3.7 gives the following corollary.
Corollary 3.8. With probability at least , the following inequalities hold simultaneously for every :
Proof of Corollary 3.8. On the event of Lemma 3.7, for every , we already have the second inequality . The first inequality follows from the following chain of inequalities:
Approximation guarantee
On the event in Corollary 3.8, which has probability at least . Fix . Since the output index minimizes the estimated average distance, the average distance between the median measures and the output distribution is bounded by
where the first, third, and fourth inequalities follow from Corollary 3.8, and the second inequality follows from the definition of . Moreover, the median measures are close to the best distribution on average, and thus close to the target distribution, since
where the last inequality uses Corollary 3.8. For every , use as the intermediate measure in the triangle inequality:
Averaging the triangle inequality through rounds yields
AI Disclosure
ChatGPT was used extensively during the preparation of this work. The author suggested using a pointwise median to obtain an improper distribution with approximation factor 2 on the lower-bound instance of [1]. Then, ChatGPT proposed combining weighted medians with multiplicative weight updates. ChatGPT and Claude also assisted with exposition and editing. The author takes full responsibility for the results, proofs, and references.
Finding the weighted median in linear time
The median-of-medians algorithm of Blum et al. [6] finds the -th smallest of values in deterministic time, without sorting all the values. We can adapt this algorithm to find the weighted median of values with positive weights in time, without sorting all the values, as shown below.
Lemma A.1. Given real values with positive weights , satisfying , the smallest input value whose cumulative weight is at least can be found deterministically in worst-case time.
Proof of Lemma A.1. Initialize an active set and a residual target . Use the median-of-medians algorithm to select the ordinary median of the active values, i.e., find the -th smallest value. Write for its value, scan the active set and partition into
and compute and . Apply the following rules:
If , retain and leave unchanged.
If , return .
If , retain and replace by .
These rules ensure that the active set always contains the smallest value whose cumulative weight is at least . Since represents the median value of the active set, each nonterminal step at least halves the active-set size, including in the presence of ties. Thus the procedure terminates after at most steps. Finding the median, computing the cumulative weights, and partitioning take operations per step, for a total of
which is the desired worst-case bound.
References
- [1][AACS26] Anders Aamand, Maryam Aliakbarpour, Justin Y. Chen, and Sandeep Silwal. How fast can you find a good hypothesis? In Steve Hanneke and Tor Lattimore, editors, Proceedings of Thirty Ninth Conference on Learning Theory, volume 336 of Proceedings of Machine Learning Research, pages 1–2. PMLR, 29 Jun–03 Jul 2026. 1, 2, 12arxiv.org/abs/2509.03734
- [2][ABS24] Maryam Aliakbarpour, Mark Bun, and Adam Smith. Optimal hypothesis selection in (almost) linear time. Advances in Neural Information Processing Systems, 37:141490–141527, 2024. 1, 2DOI
- [3]Sanjeev Arora, Elad Hazan, and Satyen Kale. The multiplicative weights update method: a meta-algorithm and applications. Theory of computing, 8(1):121–164, 2012. 2, 8
- [4]Kazuoki Azuma. Weighted sums of certain dependent random variables. Tohoku Mathematical Journal, Second Series, 19(3):357–367, 1967. 10DOI
- [5]Olivier Bousquet, Mark Braverman, Gillat Kol, Klim Efremenko, and Shay Moran. Statistically near-optimal hypothesis selection. In 2021 IEEE 62nd Annual Symposium on Foundations of Computer Science (FOCS), pages 909–919. IEEE, 2022. 1arxiv.org/abs/2108.07880
- [6]Manuel Blum, Robert W. Floyd, Vaughan R. Pratt, Ronald L. Rivest, Robert Endre Tarjan, et al. Time bounds for selection. J. Comput. Syst. Sci., 7(4):448–461, 1973. 7, 12DOI
- [7]Olivier Bousquet, Daniel Kane, and Shay Moran. The optimal approximation factor in density estimation. In Conference on Learning Theory, pages 318–341. PMLR, 2019. 1arxiv.org/abs/1902.05876
- [8]Luc Devroye and Gábor Lugosi. Combinatorial methods in density estimation, volume 1. Springer, 2001. 1, 2
- [9]Wassily Hoeffding. Probability inequalities for sums of bounded random variables. Journal of the American statistical association, 58(301):13–30, 1963. 10
- [10]Satyaki Mahalanabis and Daniel Stefankovic. Density estimation in linear time. In Rocco A. Servedio and Tong Zhang, editors, 21st Annual Conference on Learning Theory - COLT 2008, Helsinki, Finland, July 9-12, 2008, pages 503–512. Omnipress, 2008. 1, 2arxiv.org/abs/0712.2869
- [11]Yannis G Yatracos. Rates of convergence of minimum distance estimators and kolmogorov’s entropy. The Annals of Statistics, 13(2):768–774, 1985. 1, 2DOI