A note before you read: This is a deeply technical article. It walks through the mathematics and code behind a specific engineering decision in MMM Pilot’s pipeline. If you’re looking for a practical overview of hyperparameter tuning, we recommend our guide to Robyn hyperparameter tuning instead. This post is written for practitioners and engineers who want to understand what happens under the hood — and want to evaluate the approach on its merits.


The Problem: What Happens After Your First Model Run?

When you run a Marketing Mix Model with Robyn, the platform’s Nevergrad optimiser searches thousands of hyperparameter combinations across the ranges you defined. It produces a Pareto front — a set of candidate models that balance statistical fit, business plausibility, and decomposition accuracy.

Among those Pareto outputs, Robyn generates violin plots that show where the optimiser converged for each hyperparameter. These plots carry valuable information: if the distribution clusters tightly around a narrow region, the optimiser is sending a clear signal. If it spreads across the entire range, the data doesn’t strongly prefer one value over another.

The practical challenge is this: what do you do with that visual signal? For an experienced analyst, the violin tells a story — tighten this bound, leave that one alone, run again. But translating that visual intuition into specific numeric ranges for a second run is manual, imprecise, and inconsistent between analysts.

We wanted to find a way to automate that translation — not perfectly, but usefully. This post describes the approach we’ve implemented and the reasoning behind it.


The Core Idea: Read the Violin Programmatically

Our goal was simple in principle: given the distribution of hyperparameter values across all Pareto-optimal solutions, suggest tighter [min, max] bounds for the next iteration.

A naïve approach would be to take the minimum and maximum of the sampled values and use those as the new bounds. But this has an obvious problem: it ignores the shape of the distribution. A single outlier in the tail would keep the bound wide, even if 95% of the samples cluster in a much narrower region.

A slightly better approach would use fixed quantiles — say, the 15th and 85th percentiles — as the new bounds. This captures the bulk of the distribution and ignores the tails. It’s more robust than min/max, and it’s where we started.

But quantiles alone miss something important: the position of the current bound relative to the distribution’s density. If the current lower bound already sits in a dense region of the violin (many solutions sampled near it), moving it inward could discard a region the optimiser was actively exploring. Conversely, if the bound sits in an empty tail, moving it is almost free — nothing useful is happening out there.

This observation led us to a density-aware approach.


The Method: KDE Proportional Density-Ratio

The approach we settled on combines quantile targets with a Kernel Density Estimate (KDE) of the sampled values. Here’s how it works, step by step.

Step 1: Compute Quantile Targets

Robyn’s hyperparameters fall into two groups: saturation parameters (alpha and gamma), which control the diminishing returns curve via the Hill function, and Carry-Over Effect parameters (shapes and scales for Weibull decay, or theta for geometric decay), which control how advertising effects carry over time. Our method treats them uniformly — for each hyperparameter, per channel, we compute the 15th and 85th percentiles of the sampled values from the Pareto front:

p_low  <- quantile(vals, 0.15)
p_high <- quantile(vals, 0.85)

These quantiles represent where we could move the bounds — the upper limit of adjustment. At most 15% of the sample mass is excluded on each side.

Step 2: Fit a KDE Over the Sampled Values

We fit a kernel density estimate spanning the full configured range [current_min, current_max]:

kde_fit <- density(vals, from = curr_min, to = curr_max, n = 512)

This gives us a smooth approximation of the probability density at any point within the range — the same underlying information that the violin plot visualises.

Step 3: Compute the Density Ratio at Each Bound

For each bound (lower and upper), we evaluate the KDE density and compare it to the peak density:

peak_dens   <- max(kde_fit$y)
d_at_min    <- approx(kde_fit$x, kde_fit$y, xout = curr_min, rule = 2)$y
ratio_lower <- d_at_min / peak_dens

The ratio tells us: how dense is the distribution at this bound, relative to its densest point?

  • A ratio near 0 means the bound is in an empty tail — the optimiser found nothing useful there.
  • A ratio near 1 means the bound is right at the peak — moving it would cut into the heart of the distribution.

Step 4: Scale the Movement

The density ratio is converted into a movement scale factor using a configurable threshold (default: 0.30):

scale_lower <- max(0, 1 - ratio_lower / density_threshold)

The behaviour is intuitive:

Density Ratio Scale Factor What Happens
0.0 (empty tail) 1.0 Full move to quantile target
0.15 (sparse) 0.5 Half move
0.30+ (dense) 0.0 No move — bound stays put

The new bound is then interpolated between the current position and the quantile target:

new_min <- curr_min + scale_lower * (p_low - curr_min)

A bound in an empty region moves fully to the quantile. A bound in a dense region doesn’t move at all. Bounds in between move proportionally.

Step 5: Safety Guards

Two guards protect against edge cases:

  1. Clamp to configured range: New bounds never expand beyond the originals. This is a tightening-only operation.
  2. Collapse guard: If the new min equals or exceeds the new max (which can happen with very few Pareto samples), the original bounds are preserved. We’d rather suggest nothing than suggest something unreliable.
# Never expand
new_min <- max(curr_min, new_min)
new_max <- min(curr_max, new_max)

# Collapse guard
if (new_min >= new_max) {
    new_min <- curr_min
    new_max <- curr_max
}

Measuring Confidence: The Intensity Score

For each hyperparameter, we compute an intensity score that summarises how strongly the optimiser converged:

intensity = 1 − (p85 − p15) / configured_range
  • Intensity ≈ 0: The samples spread across the full configured range. The optimiser didn’t converge for this parameter — there’s no clear signal.
  • Intensity ≈ 1: The samples clustered tightly. The optimiser found a narrow region it strongly prefers.

Per-channel intensity scores are averaged to produce an overall probability of improvement indicator:

Average Intensity Indicator Interpretation
< 0.2 Low Tightening is unlikely to help — the optimiser hasn’t converged
0.2 – 0.6 Medium Some signal present — moderate tightening may be useful
≥ 0.6 High Strong convergence — tightened bounds should improve the next run

This indicator is surfaced in the application interface alongside the suggested bounds, so the analyst can decide whether to accept, modify, or ignore the suggestion.


What This Approach Does Well — And Where It Has Limits

Strengths

  • Shape-aware: Unlike min/max or fixed quantile caps, the method respects the density profile of the distribution. Dense regions are left alone; sparse tails are trimmed.
  • Conservative by default: The collapse guard, the density threshold, and the never-expand clamp all bias toward caution. When in doubt, the algorithm suggests nothing rather than something aggressive.
  • Transparent: Every decision is driven by two observable quantities — the quantile position and the KDE density ratio. There are no black-box neural networks or opaque heuristics.
  • Fast: KDE fitting on 100–200 data points takes milliseconds. This adds negligible overhead to the pipeline.

Limitations and Honest Caveats

We want to be transparent about the boundaries of this approach:

  • KDE bandwidth selection matters. We use R’s density() default bandwidth (Silverman’s rule of thumb). This rule assumes a roughly unimodal distribution. For multimodal hyperparameter distributions — where the optimiser converges to two or more distinct regions — it will over-smooth, potentially blending the modes into a single broad peak. We haven’t found this to be a practical problem with typical Pareto distributions, but it’s a theoretical weakness.
  • Quantile estimates from small samples are noisy. With fewer than 30 Pareto solutions, the 15th and 85th percentiles are rough estimates. The sparse-data guard (log a warning below 5 rows; collapse guard at boundary) mitigates this, but doesn’t eliminate the uncertainty.
  • This is a heuristic, not an optimal policy. We’re not claiming this is the mathematically optimal way to shrink hyperparameter bounds. A more rigorous approach might replace Nevergrad’s search entirely with Bayesian Optimisation using Gaussian Process surrogates — guiding the hyperparameter search itself rather than analysing its output after the fact. Our method is simpler, works within the existing Robyn architecture, and — based on our testing — practically useful. But it doesn’t come with a proof of optimality.
  • The density threshold (0.30) is a tuning parameter itself. We chose it based on experimentation across several dozen model runs with varying channel counts and data lengths. It works well in practice, but it’s not derived from first principles.
  • Funnel scores are stored but not currently used for bound adjustment. Each channel carries a funnel_performance_score (0.0 = top-of-funnel, 1.0 = bottom-of-funnel) from the field mappings. The infrastructure is in place to use these as prior nudge factors on alpha/gamma ranges, but the current implementation relies purely on the Pareto distribution. We’re evaluating whether funnel-based priors improve or complicate the suggestions.

Why We Chose This Over Alternatives

Before arriving at this approach, we considered several alternatives:

Fixed quantile caps (no KDE): Simpler, but treats all bounds equally regardless of how much density exists at the bound position. A bound at the 15th percentile could be in a dense region (shouldn’t move) or an empty tail (should move a lot). Without KDE, you can’t distinguish the two.

Bayesian Optimisation as a Nevergrad replacement: Rather than running Nevergrad and then analysing the distribution post-hoc, Bayesian Optimisation with Gaussian Process surrogates could guide the hyperparameter search itself — building a probabilistic model of the objective landscape during the search and selecting next evaluations intelligently. This is a more theoretically rigorous approach to the broader hyperparameter tuning problem, but it would replace Robyn’s existing optimisation pipeline rather than complement it. Our method works within the existing architecture.

AI/LLM-based suggestions: We experimented with prompting a language model to analyse the violin distributions and suggest bounds. The results were inconsistent: sometimes excellent, sometimes nonsensical. For a component that feeds directly into model configuration, we wanted deterministic, auditable logic.

The KDE density-ratio method sits in a pragmatic middle ground: more informed than raw quantiles, simpler than Bayesian Optimisation, and fully deterministic.


A Worked Example

Consider a channel Facebook_S with alpha configured as [0.5, 3.0] (range = 2.5). After a Robyn run, the Pareto front contains 120 solutions. The sampled alpha values cluster between 1.0 and 2.2, with a few outliers near the bounds.

  1. Quantile targets: p15 = 1.05, p85 = 2.15
  2. KDE at lower bound (0.5): Density is near zero — the optimiser never explored here. Ratio ≈ 0.02. Scale = max(0, 1 − 0.02/0.30) ≈ 0.93.
  3. KDE at upper bound (3.0): Density is very low. Ratio ≈ 0.05. Scale ≈ 0.83.
  4. New bounds: lower = 0.5 + 0.93 × (1.05 − 0.5) ≈ 1.01. Upper = 3.0 + 0.83 × (2.15 − 3.0) ≈ 2.29.
  5. Suggested range: [1.01, 2.29] — reduced from 2.5 to 1.28 (49% tighter).
  6. Intensity: 1 − (2.15 − 1.05) / 2.5 = 1 − 0.44 = 0.56 → Medium.

The algorithm tightened both bounds significantly because neither sat in a dense region. If the lower bound had been at 1.0 (right in the cluster), its density ratio would have been high, the scale factor would have been near zero, and the bound wouldn’t have moved — even though the quantile target suggests it could.


How This Fits Into the MMM Pilot Pipeline

In practice, this algorithm runs automatically after every model run as part of the post-processing pipeline. The user doesn’t need to know about KDE fitting or density ratios. They see:

  • Suggested new bounds for each channel and parameter
  • An intensity indicator (Low / Medium / High) showing how strongly the optimiser converged
  • A probability of improvement summary for the overall model

The user can accept the suggestions for their next run, adjust them, or ignore them entirely. The suggestions are never applied automatically — they’re presented as recommendations with transparent confidence signals.

This keeps the analyst in control while removing the manual work of interpreting violin plots and translating visual patterns into numeric ranges.


Frequently Asked Questions

What is KDE and how is it used in hyperparameter tuning?

Kernel Density Estimation (KDE) is a non-parametric method for estimating the probability density function of a random variable. In this context, we fit a KDE over the hyperparameter values from Pareto-optimal model solutions. The resulting density curve tells us where the optimiser concentrated its best solutions — similar to what a violin plot visualises, but as a continuous function we can query programmatically. We use the density at each bound to decide how aggressively to tighten it.

How is this different from just using the min and max of the Pareto results?

Using the raw min/max of sampled values ignores the distribution shape. A single outlier in the tail would keep the bound wide, even if 99% of solutions cluster elsewhere. Our approach uses quantiles (15th and 85th percentiles) as targets, then scales the movement based on KDE density. Bounds in empty tails move; bounds in dense regions stay. This produces tighter, more informed suggestions.

Does this guarantee better model results on the next run?

No. This method suggests bounds that focus the search space on regions the optimiser found promising in the previous run. It’s a practical heuristic that tends to improve convergence speed and model stability — but it’s not a guarantee. The intensity score and probability indicator help you assess whether the suggestion is likely to be useful before you apply it.

What happens if there aren’t enough Pareto solutions for reliable estimates?

The algorithm includes a sparse-data guard. If fewer than 5 Pareto solutions are available, a warning is logged. If the quantile computation produces collapsed bounds (min ≥ max), the original bounds are preserved and the intensity score is set to zero — effectively telling the user: “we don’t have enough data to make a useful suggestion.”

Can I override the automated suggestions?

Yes, always. Suggestions are presented as recommendations, never applied automatically. You can accept them, modify individual bounds, or ignore them entirely. The intensity indicator helps you decide which suggestions are well-supported by the data and which are based on weaker signals.

Why not use Bayesian Optimisation for this?

Bayesian Optimisation solves a different part of the problem. It replaces the search algorithm itself (Nevergrad in Robyn’s case), guiding the hyperparameter exploration by building a probabilistic surrogate model during the search. Our KDE method works downstream — it analyses the distribution that Nevergrad already produced and suggests where to focus the next search. They’re complementary rather than alternatives. We chose to work within Robyn’s existing Nevergrad pipeline and add value at the post-processing stage, where the method is simpler, fully deterministic, and produces suggestions that are easy to explain and audit.


Start With Sensible Defaults — Then Let the Data Guide You

Setting hyperparameter ranges for an MMM doesn’t have to begin with a blank spreadsheet. MMM Pilot provides channel-type defaults for your first run, then uses the method described above to suggest refinements based on where the optimiser actually converged.

You stay in control of every bound. The platform handles the interpretation of the distribution — so you can focus on what the results mean for your marketing strategy.

Explore how MMM Pilot handles hyperparameter management →

Try MMM Pilot — no R required →