Fit and forecast successive generations
This tutorial uses the native norton_bass model with the
successive_generations variant. It combines diffusion within generations with
transfer between generations. The original model family was developed by
Norton and Bass (1987); the explicit
equations and conventions below describe the fixture tested by this implementation.
Learning outcomes
Section titled “Learning outcomes”You will recover six parameters from a known synthetic case, preserve fixed launch-time assumptions in fitted state, and verify forecasts at times beyond the fitting window. You will distinguish a generation’s level and signed net rate from a cumulative count of first adoptions.
Prerequisites
Section titled “Prerequisites”Install the native development environment and read the fitting guide. The script requires Polars and the installed native package. All observations are synthetic and no external data or network request is used.
The first generation launches at time zero and the second at time four. These
launches are fixed model options, not estimated parameters. Use one consistent
time unit: p and q then have inverse-time units, launch times use the time
coordinate, and m1 and m2 use the chosen adoption units.
Run the example from the repository root:
.venv-native/bin/python -I examples/native_norton_bass.py"""Check two-generation fitting and forecasts against analytic diffusion curves."""
import jsonfrom math import exp, isclose, isfinite
import polars as pl
from innovate import fit, predict
def fraction_and_rate(time: float, p: float, q: float) -> tuple[float, float]: """Return the Bass fraction and its right derivative after a fixed launch.""" if time < 0: return 0.0, 0.0 exponential = exp(-(p + q) * time) denominator = 1 + q / p * exponential return (1 - exponential) / denominator, (p + q) ** 2 / p * exponential / denominator**2
def analytic(time: float) -> tuple[tuple[float, float], tuple[float, float]]: """Evaluate the two-generation transfer equations independently in Python.""" f1, d1 = fraction_and_rate(time, 0.03, 0.2) f2, d2 = fraction_and_rate(time - 4, 0.02, 0.3) levels = (1000 * f1 * (1 - f2), (1500 + 1000 * f1) * f2) rates = (1000 * (d1 * (1 - f2) - f1 * d2), 1000 * d1 * f2 + (1500 + 1000 * f1) * d2) return levels, rates
def main() -> None: """Validate synthetic recovery and held-out levels and signed rates.""" parameters = {"p1": 0.03, "q1": 0.2, "m1": 1000.0, "p2": 0.02, "q2": 0.3, "m2": 1500.0} options = {"variant": "successive_generations", "launch_times": [0.0, 4.0]} table = pl.DataFrame({"time": [i * 0.5 for i in range(41)]}) observed = predict("norton_bass", table, parameters, model_options=options) for time, first, second in observed.iter_rows(): expected, _ = analytic(time) assert isclose(first, expected[0], abs_tol=1e-9, rel_tol=1e-12) assert isclose(second, expected[1], abs_tol=1e-9, rel_tol=1e-12)
result = fit("norton_bass", observed, model_options=options, observed_columns=["prediction_1", "prediction_2"]) assert result.diagnostics["optimizer"]["converged"] is True assert isinstance(result.envelope["result"]["state"], dict) for name, expected in parameters.items(): assert isclose(result.parameters[name], expected, rel_tol=0.001)
future = pl.DataFrame({"time": [21.0, 25.0, 30.0]}) forecast = result.predict(future) rates = result.predict(future, quantity="rate") assert forecast.columns == ["time", "prediction_1", "prediction_2"] assert rates.columns == ["time", "rate_1", "rate_2"] assert forecast["time"].to_list() == future["time"].to_list() assert rates["time"].to_list() == future["time"].to_list() for level_row, rate_row in zip(forecast.iter_rows(), rates.iter_rows(), strict=True): expected_levels, expected_rates = analytic(level_row[0]) for actual, expected in zip(level_row[1:] + rate_row[1:], expected_levels + expected_rates, strict=True): assert isfinite(actual) and isclose(actual, expected, abs_tol=0.01, rel_tol=0) # Signed generation rates may be negative during substitution. assert rates["rate_1"][0] < 0 print( json.dumps( {"converged": True, "forecast_rows": forecast.height, "parameters_checked": len(parameters)}, sort_keys=True ) )
if __name__ == "__main__": main()The script checks native predictions against separate equations at 41 times from 0 to 20 before fitting those values. It requests both observation columns explicitly, checks recovery of all six parameters, and then predicts at times 21, 25 and 30. The last checks compare both levels and signed rates with the independent calculation and require a negative rate for the declining first generation.
Expected results
Section titled “Expected results”The successful run prints:
{"converged": true, "forecast_rows": 3, "parameters_checked": 6}Parameter recovery uses a relative tolerance of 0.001. Held-out levels and rates use an absolute tolerance of 0.01 in their respective units. These tolerances are declared regression criteria for this synthetic case. They are not accuracy bounds for every parameter combination or dataset.
Interpretation
Section titled “Interpretation”For time since launch u >= 0, the fixture’s Bass fraction is
F(u) = (1 - exp(-(p + q) * u)) / (1 + (q / p) * exp(-(p + q) * u)).
Before launch it is zero. Write F1 for the first generation’s fraction and
F2 for the second generation’s fraction evaluated at t - 4. The tested
levels are:
- First generation:
1000 * F1 * (1 - F2). - Second generation:
(1500 + 1000 * F1) * F2.
The first level can fall as the second generation gains users. Its derivative
includes the negative transfer term -1000 * F1 * dF2/dt. A negative value is
therefore meaningful net change, not an invalid negative number of gross
adoptions. Summing the two levels cancels the transfer term and gives
1000 * F1 + 1500 * F2.
Reader task: what are the limiting levels as both fractions approach one?
The first tends to zero and the second to 2500. Before the second launch,
F2 is zero, so only the first generation contributes. These checks explain
both the launch convention and the distinction from fixed-pool replacement.
Limitations
Section titled “Limitations”The fit uses noiseless synthetic data and fixed launch times. Successful parameter recovery does not establish identifiability with sparse real data, uncertainty coverage, robustness to measurement error or the suitability of this model for a particular technology. A convergence flag alone is insufficient.
The example does not infer gross adoption, churn or individual user histories from net generation levels. It also does not estimate launch times or validate other Norton–Bass variants. Read the native capabilities for the supported options and remaining qualification gates. The original Bass (1969) paper provides the diffusion model’s scientific context; citing that model does not validate this application.