VotingHelper Module¶
Aggregation and voting utilities for ensemble predictions.
- class HMB.VotingHelper.VotingHelper[source]¶
Bases:
objectVotingHelper: Collection of voting and aggregation utilities.
Each method takes a list of predictions and optionally a list of weights (same length). Methods return a single aggregated scalar or label depending on the strategy.
- WeightedMajorityVoting(predictions, weights)[source]¶
Compute a weighted majority vote over labels.
- Parameters:
predictions (iterable) – Iterable of labels.
weights (iterable) – Iterable of numeric weights (same length as predictions).
- Returns:
The label with the highest cumulative weight.
- Return type:
label
- MajorityVoting(predictions)[source]¶
Simple majority vote (unweighted).
- Parameters:
predictions (iterable) – Iterable of labels.
- Returns:
The most common label.
- Return type:
label
- WeightedAverageVoting(predictions, weights)[source]¶
Weighted average of numeric predictions.
- Parameters:
predictions (iterable) – Iterable of numeric predictions.
weights (iterable) – Iterable of numeric weights (same length as predictions).
- Returns:
Weighted mean.
- Return type:
- AverageVoting(predictions)[source]¶
Simple arithmetic mean of numeric predictions.
- Parameters:
predictions (iterable) – Iterable of numeric predictions.
- Returns:
Arithmetic mean.
- Return type:
- WeightedMedianVoting(predictions, weights)[source]¶
Weighted median: returns a scalar median taking weights into account.
- Parameters:
predictions (iterable) – Iterable of numeric predictions.
weights (iterable) – Iterable of numeric weights (same length as predictions).
- Returns:
Weighted median.
- Return type:
- MedianVoting(predictions)[source]¶
Unweighted median for numeric predictions.
- Parameters:
predictions (iterable) – Iterable of numeric predictions.
- Returns:
Median value.
- Return type:
- WeightedModeVoting(predictions, weights)[source]¶
Weighted mode: returns the label with the highest cumulative weight.
For numeric or non-numeric labels, this method aggregates weights per unique label and returns the label with the maximum total weight. This is equivalent to WeightedMajorityVoting.
- Parameters:
predictions (iterable) – Iterable of labels (numeric or non-numeric).
weights (iterable) – Iterable of numeric weights (same length as predictions).
- Returns:
Weighted mode label or numeric value.
- Return type:
label or float
- ModeVoting(predictions)[source]¶
Unweighted mode (most common element).
- Parameters:
predictions (iterable) – Iterable of labels.
- Returns:
Most common label.
- Return type:
label
- WeightedGeometricMeanVoting(predictions, weights)[source]¶
Weighted geometric mean for positive numeric predictions.
- Parameters:
predictions (iterable) – Iterable of positive numeric predictions.
weights (iterable) – Iterable of numeric weights (same length as predictions).
- Returns:
Weighted geometric mean.
- Return type:
- GeometricMeanVoting(predictions)[source]¶
Geometric mean for positive numeric predictions.
- Parameters:
predictions (iterable) – Iterable of positive numeric predictions.
- Returns:
Geometric mean.
- Return type:
- WeightedHarmonicMeanVoting(predictions, weights)[source]¶
Weighted harmonic mean for positive numeric predictions.
- Parameters:
predictions (iterable) – Iterable of positive numeric predictions.
weights (iterable) – Iterable of numeric weights (same length as predictions).
- Returns:
Weighted harmonic mean.
- Return type:
- HarmonicMeanVoting(predictions)[source]¶
Unweighted harmonic mean for positive numeric predictions.
- Parameters:
predictions (iterable) – Iterable of positive numeric predictions.
- Returns:
Harmonic mean.
- Return type:
- WeightedQuadraticMeanVoting(predictions, weights)[source]¶
Weighted root-mean-square (quadratic mean).
- Parameters:
predictions (iterable) – Iterable of numeric predictions.
weights (iterable) – Iterable of numeric weights (same length as predictions).
- Returns:
Weighted root-mean-square.
- Return type:
- QuadraticMeanVoting(predictions)[source]¶
Unweighted root-mean-square.
- Parameters:
predictions (iterable) – Iterable of numeric predictions.
- Returns:
Root-mean-square.
- Return type:
- WeightedCubicMeanVoting(predictions, weights)[source]¶
Weighted cubic mean (signed) -> (mean of cubes)^(1/3).
- Parameters:
predictions (iterable) – Iterable of numeric predictions.
weights (iterable) – Iterable of numeric weights (same length as predictions).
- Returns:
Weighted cubic mean.
- Return type:
- CubicMeanVoting(predictions)[source]¶
Unweighted cubic mean.
- Parameters:
predictions (iterable) – Iterable of numeric predictions.
- Returns:
Cubic mean.
- Return type:
- WeightedQuarticMeanVoting(predictions, weights)[source]¶
Weighted quartic mean -> 4th root of mean of 4th powers.
- Parameters:
predictions (iterable) – Iterable of numeric predictions.
weights (iterable) – Iterable of numeric weights (same length as predictions).
- Returns:
Weighted quartic mean.
- Return type:
- QuarticMeanVoting(predictions)[source]¶
Unweighted quartic mean.
- Parameters:
predictions (iterable) – Iterable of numeric predictions.
- Returns:
Quartic mean.
- Return type:
- SoftVoting(probabilityPredictions)[source]¶
Soft voting: average predicted probabilities across models.
- ConfidenceWeightedVoting(predictions, confidences)[source]¶
Weighted voting using model confidence scores.
- Parameters:
predictions (iterable) – Predicted labels.
confidences (iterable) – Confidence scores in [0, 1] or positive reals.
- Returns:
Label with highest cumulative confidence-weighted vote.
- Return type:
label
- BayesianModelAveraging(predictions, modelPosteriors)[source]¶
Bayesian Model Averaging: weight predictions by posterior model probabilities.
- Parameters:
predictions (iterable) – Predicted labels from each model.
modelPosteriors (iterable) – Posterior probabilities for each model (sum to 1).
- Returns:
Label with highest posterior-weighted cumulative probability.
- Return type:
label
- BordaCountVoting(rankedPredictions)[source]¶
Borda Count rank aggregation: higher ranks receive more points.
- Parameters:
rankedPredictions (list of lists) – Each inner list is a ranking of labels from most to least preferred.
- Returns:
Label with the highest cumulative Borda score.
- Return type:
label
- UncertaintyAwareVoting(predictions, uncertainties, uncertaintyType='inverse')[source]¶
Aggregate predictions weighted by inverse uncertainty.
- Parameters:
predictions (iterable) – Predicted labels.
uncertainties (iterable) – Uncertainty estimates (lower = more certain).
uncertaintyType (str) – “inverse” or “exponential” weighting scheme.
- Returns:
Label with highest uncertainty-adjusted cumulative weight.
- Return type:
label
- EntropyWeightedVoting(probabilityPredictions)[source]¶
Weight voting by inverse Shannon entropy of probability distributions.
- DiversityWeightedVoting(predictions)[source]¶
Weight predictions by model diversity (pairwise disagreement).
- CondorcetVoting(rankedPredictions)[source]¶
Condorcet voting: winner defeats all others in pairwise comparisons.
- Parameters:
rankedPredictions (list of lists) – Each inner list is a ranking of labels from most to least preferred.
- Returns:
Condorcet winner if one exists, else fallback to Borda winner.
- Return type:
label
- CalibrationAwareVoting(predictions, calibrationScores)[source]¶
Weight predictions by model calibration quality (higher = better calibrated).
- Parameters:
predictions (iterable) – Predicted labels.
calibrationScores (iterable) – Calibration metrics in [0, 1] where 1 = perfectly calibrated.
- Returns:
Label with highest calibration-weighted cumulative vote.
- Return type:
label
- MetaWeightLearning(basePredictions, trueLabels)[source]¶
Learn optimal linear combination weights from validation data.
- CopelandVoting(rankedPredictions)[source]¶
Copeland voting: score candidates by net pairwise wins (wins minus losses).
- Parameters:
rankedPredictions (list of lists) – Each inner list is a ranking of labels from most to least preferred.
- Returns:
Candidate with highest Copeland score (net pairwise wins).
- Return type:
label
- RobustMeanVoting(predictions, trimFraction=0.1)[source]¶
Trimmed mean aggregation: exclude extreme values before averaging.
- ProductOfExpertsVoting(probabilityPredictions, expertWeights=None)[source]¶
Log-linear pooling: combine probabilities via weighted product (normalized).
- CorrelationAwareWeightedVoting(predictions, baseWeights=None)[source]¶
Weight predictions by inverse correlation to promote ensemble diversity.
- AttentionWeightedVoting(predictions, contextFeatures, attentionDim=16)[source]¶
Attention-based aggregation: compute dynamic weights via scaled dot-product attention.
- Parameters:
- Returns:
Aggregated prediction for each sample position using attention-derived weights.
- Return type:
- HedgeAdaptiveVoting(predictions, initialWeights=None, learningRate=0.1, feedback=None)[source]¶
Online adaptive voting using Hedge algorithm with exponential weighting and regret bounds.
- Parameters:
predictions (list of lists) – Shape (n_models, n_samples) of predicted labels.
initialWeights (iterable, optional) – Initial weight for each model (default: uniform).
learningRate (float) – Learning rate for weight updates (0 to 1).
feedback (list of lists, optional) – Shape (n_models, n_samples) of per-sample losses.
- Returns:
Contains aggregated predictions and final adaptive weights.
- Return type:
- FedAvgVoting(localPredictions, clientWeights=None, clientDataSizes=None)[source]¶
Federated averaging aggregator: combine local model predictions weighted by client data size.
- Parameters:
localPredictions (list of lists) – Shape (n_clients, n_samples) of local predictions.
clientWeights (iterable, optional) – Explicit weight for each client (default: data-size proportional).
clientDataSizes (iterable, optional) – Number of samples per client for proportional weighting.
- Returns:
Aggregated prediction for each sample position using federated weighting.
- Return type:
- MedianOfMeansVoting(predictions, nBuckets=5, randomSeed=42)[source]¶
Median-of-means aggregation: robust to Byzantine faults and adversarial model contributions.
- Parameters:
- Returns:
Aggregated prediction for each sample position using robust median-of-means.
- Return type:
- QuantileAggregationVoting(quantilePredictions, targetQuantile=0.5)[source]¶
Quantile-based aggregation: combine predictive distributions via quantile averaging.
- Parameters:
- Returns:
Aggregated prediction at the target quantile level.
- Return type:
float or label
- ConformalPredictionVoting(probabilityPredictions, calibrationScores, targetCoverage=0.95)[source]¶
Conformal prediction aggregation: return prediction sets with guaranteed marginal coverage.
- Parameters:
- Returns:
Prediction set containing labels that satisfy conformal coverage guarantee.
- Return type:
- DynamicEnsembleSelectionVoting(predictions, competenceScores=None, neighborhoodSize=3)[source]¶
Dynamic ensemble selection: weight models by local competence estimates per sample.
- Parameters:
- Returns:
Aggregated prediction for each sample position using dynamic competence weighting.
- Return type:
- WassersteinBarycenterVoting(distributionPredictions, weights=None, nGrid=100)[source]¶
Wasserstein barycenter aggregation: combine predictive distributions via optimal transport.
- Parameters:
distributionPredictions (list of dicts) – Each dict maps numeric values to probability mass. Example: [{“1.0”: 0.2, “2.0”: 0.5, “3.0”: 0.3}, …]
weights (iterable, optional) – Weight for each distribution (default: uniform).
nGrid (int) – Number of grid points for discretized Wasserstein computation (default: 100).
- Returns:
Aggregated prediction at the Wasserstein barycenter (median of barycenter distribution).
- Return type:
- CausalInvariantVoting(predictions, environmentLabels, groundTruth=None)[source]¶
Causal aggregation: weight models by invariant predictive performance across environments.
- Parameters:
- Returns:
Aggregated prediction for each sample position using environment-invariant weighting.
- Return type:
- GraphNeuralAggregation(predictions, adjacencyMatrix, aggregationSteps=2, activationType='relu', fixedLabels=None)[source]¶
GNN-style aggregation: propagate predictions through model dependency graph via message passing.
- Parameters:
predictions (list of lists) – Shape (n_models, n_samples) of predicted labels.
adjacencyMatrix (list of lists) – Shape (n_models, n_models) adjacency matrix for model graph.
aggregationSteps (int) – Number of message-passing iterations (default: 2).
activationType (str) – Activation function for message aggregation: “relu”, “tanh”, or “identity”.
fixedLabels (list, optional) – Fixed ordered list of all possible labels for consistent embedding dimensions.
- Returns:
Aggregated prediction for each sample position using graph-propagated weights.
- Return type: