Join the newly launched Discord
community for real-time discussions, peer support, and direct interaction with the Meridian team!
meridian.model.knots.l1_distance_weights
Stay organized with collections
Save and categorize content based on your preferences.
Computes weights at knots for every time period.
meridian
.
model
.
knots
.
l1_distance_weights
(
n_times
:
int
,
knot_locations
:
np
.
ndarray
[
int
,
np
.
dtype
[
int
]]
)
->
np
.
ndarray
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.
The number of time points.
The location of knots within 0, 1, 2,..., (n_times-1)
.
A weight array with dimensions (n_knots, n_times)
with values summing up
to 1 for each time period when summing over knots.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License
, and code samples are licensed under the Apache 2.0 License
. For details, see the Google Developers Site Policies
. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-09-05 UTC.
[[["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 2025-09-05 UTC."],[[["\u003cp\u003eThis function calculates weights for each time period based on its proximity to neighboring knots.\u003c/p\u003e\n"],["\u003cp\u003eWeights are determined by the L1 distance between a time period and its two neighboring knots, with closer knots having a greater influence.\u003c/p\u003e\n"],["\u003cp\u003eIf a time point matches a knot, that knot receives full weight; if outside the knot range, the nearest endpoint knot gets full weight.\u003c/p\u003e\n"],["\u003cp\u003eThe function returns a weight array of \u003ccode\u003e(n_knots, n_times)\u003c/code\u003e, where the weights for each time period sum up to 1 when aggregated across all knots.\u003c/p\u003e\n"],["\u003cp\u003eThese weights are used to model trend and seasonality, and each given time will have two non-zero weights in the array.\u003c/p\u003e\n"]]],["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"],null,["\u003cbr /\u003e\n\n|----------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/google/meridian/blob/v1.2.0/meridian/model/knots.py#L74-L128) |\n\nComputes weights at knots for every time period. \n\n meridian.model.knots.l1_distance_weights(\n n_times: int, knot_locations: np.ndarray[int, np.dtype[int]]\n ) -\u003e np.ndarray\n\nThe two neighboring knots inform the weight estimate of a particular time\nperiod. The amount each of the two neighboring knots inform the weight at a\ntime period depends on how close (L1 distance) they are to the time period. If\na time point coincides with a knot location, then 100% weight is given to that\nknot. If a time point lies outside the range of knots, then 100% weight is\ngiven to the nearest endpoint knot.\n\nThis function computes an `(n_knots, n_times)` array of weights that are used\nto model trend and seasonality. For a given time, the array contains two\nnon-zero weights. The weights are inversely proportional to the L1 distance\nfrom the given time to the neighboring knots. The two weights are normalized\nsuch that they sum to 1.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|------------------|----------------------------------------------------------|\n| `n_times` | The number of time points. |\n| `knot_locations` | The location of knots within `0, 1, 2,..., (n_times-1)`. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| A weight array with dimensions `(n_knots, n_times)` with values summing up to 1 for each time period when summing over knots. ||\n\n\u003cbr /\u003e"]]