The two neighboring knots inform the weight estimate of a particular time
period. The amount each of the two neighboring knots inform the weight at a
time period depends on how close (L1 distance) they are to the time period. If
a time point coincides with a knot location, then 100% weight is given to that
knot. If a time point lies outside the range of knots, then 100% weight is
given to the nearest endpoint knot.
This function computes an (n_knots, n_times) array of weights that are used
to model trend and seasonality. For a given time, the array contains two
non-zero weights. The weights are inversely proportional to the L1 distance
from the given time to the neighboring knots. The two weights are normalized
such that they sum to 1.
Args
n_times
The number of time points.
knot_locations
The location of knots within 0, 1, 2,..., (n_times-1).
Returns
A weight array with dimensions (n_knots, n_times) with values summing up
to 1 for each time period when summing over knots.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-05-05 UTC."],[],["The `l1_distance_weights` function calculates weights for each time period based on neighboring knots. It outputs a `(n_knots, n_times)` array, where each time period's weight is influenced by the two closest knots. Weights are inversely proportional to the L1 distance from the time period to the knots and normalized to sum to 1. If a time point is at a knot, that knot gets 100% weight; outside the knot range, the nearest endpoint knot gets 100%.\n"]]