Predict a native diffusion curve
This tutorial uses Innovate’s 0.7 development API. It predicts a Logistic curve from supplied parameters and checks the result independently. Start with the development installation; an older package from a registry may expose a different API.
Learning outcomes
Section titled “Learning outcomes”After running the example, you can pass a Polars table to Rust, interpret the prediction column, confirm that input identifiers survive the native call, and check that invalid time grids produce an error.
Prerequisites
Section titled “Prerequisites”Use the repository checkout with Python 3.15.2, Rust 1.99.1, and the locked environment installed. You need basic Python and dataframe familiarity. The example uses three synthetic query times, requires no dataset download, and performs no network request.
The time unit is arbitrary but must agree with the parameters. With time in
years, k has units of inverse years and x0 is measured in years; L is
the asymptotic level in your chosen adoption units.
From the repository root, run the checked file in the installed environment:
.venv-native/bin/python -I examples/native_forecast.pyThe displayed source is imported from that exact file. It is not a separately maintained copy.
"""Check native Logistic prediction against an independent analytic reference.
Synthetic values have arbitrary adoption units; no empirical fit or calibratedforecast uncertainty is implied. Run with the installed development package."""
import jsonimport math
import polars as pl
from innovate import predict
def main() -> None: """Validate predictions, preserved identity, LazyFrames and invalid grids.""" times = [0.0, 1.0, 2.0] parameters = {"L": 100.0, "k": 1.0, "x0": 1.0} frame = pl.DataFrame({"time": times, "id": ["a", "b", "c"]}) forecast = predict("logistic", frame, parameters)
# This independent closed form is a test oracle, not a production fallback. expected = [100.0 / (1.0 + math.exp(-(time - 1.0))) for time in times] actual = forecast["prediction"].to_list() assert all( math.isclose(value, reference, rel_tol=1e-12, abs_tol=1e-12) for value, reference in zip(actual, expected, strict=True) ) assert forecast["id"].to_list() == ["a", "b", "c"] assert forecast["time"].to_list() == times assert frame.columns == ["time", "id"] assert predict("logistic", frame.lazy(), parameters).equals(forecast)
try: predict("logistic", pl.DataFrame({"time": [0.0, 0.0]}), parameters) except ValueError: duplicate_time_rejected = True else: duplicate_time_rejected = False assert duplicate_time_rejected, "The native contract must reject duplicate times."
print( json.dumps( { "duplicate_time_rejected": duplicate_time_rejected, "ids": forecast["id"].to_list(), "predictions": [round(value, 6) for value in actual], }, sort_keys=True, ) )
if __name__ == "__main__": main()Read the checks in order. First compare Rust’s result with the analytic Logistic curve. Then verify row identity and unchanged input columns, compare eager and lazy input, and finally submit duplicate times to exercise the error contract. A failed check stops the script with a nonzero exit status.
Expected results
Section titled “Expected results”The command prints this JSON after its assertions pass. CI compares the actual output with the same contract value displayed here:
{"duplicate_time_rejected": true, "ids": ["a", "b", "c"], "predictions": [26.894142, 50.0, 73.105858]}If Python cannot import innovate._native, the native package has not been
built into that interpreter. Return to the installation instructions. An
assertion failure is evidence of a discrepancy; do not edit the expected values
to match a failing implementation without investigating it.
Interpretation
Section titled “Interpretation”The curve is L / (1 + exp(-k * (t - x0))). At t = x0 = 1, its level is
exactly half of L = 100, hence the central prediction of 50. The other two
values lie symmetrically around it. These are levels, not incident adoptions
per time step. The independent analytic expression belongs to the example’s
test oracle; Innovate’s scientific execution remains in Rust.
The input frame keeps its identifiers and ordering. A LazyFrame is collected at the native boundary. Arrow IPC currently copies buffers, so the example makes no claim of zero-copy transport.
Check your understanding
Section titled “Check your understanding”Before reading the answers, use the displayed formula to answer these questions:
- Does the prediction of 50 at time 1 mean that 50 new adoptions occurred between times 0 and 1? Calculate the change over that interval.
- If you change the time unit from years to months, what values of
kandx0preserve the same curve? What happens toL? - What is the instantaneous slope at the midpoint, and how do its units differ from the prediction column?
Compare your answers
- The prediction is a level. Its increase from time 0 to time 1 is
approximately
50 − 26.894142 = 23.105858adoption units. - Multiply the time coordinates and
x0by 12, givingx0 = 12; dividekby 12, givingk = 1/12per month.L = 100retains the same adoption units. The dimensionless productk * (t − x0)remains unchanged. - Differentiating the Logistic expression gives the midpoint slope
L * k / 4 = 25adoption units per year. This instantaneous derivative differs from the change accumulated over a whole year.
These are interpretation exercises. The executable example checks the supplied three-point curve; it does not run the modified time-unit exercise for you.
Limitations
Section titled “Limitations”This example supplies parameters; it does not estimate them from observations, select a model, establish causal effects or calibrate predictive intervals. A numerical identity on three synthetic points does not validate the Logistic model for a real population. Time must be finite and strictly increasing. Passing this tutorial does not close the wider scientific migration ledger.
Continue with the current Python API and the native scientific conventions. The documentation quality contract explains what execution evidence does and does not establish.