Join the newly launched Discord
community for real-time discussions, peer support, and direct interaction with the Meridian team!
meridian.analysis.analyzer.DataTensors
Stay organized with collections
Save and categorize content based on your preferences.
Container for data variable arguments of Analyzer methods.
Inherits From: ExtensionType
meridian
.
analysis
.
analyzer
.
DataTensors
(
media
:
Optional
[
meridian
.
backend
.
Tensor
]
=
None
,
media_spend
:
Optional
[
meridian
.
backend
.
Tensor
]
=
None
,
reach
:
Optional
[
meridian
.
backend
.
Tensor
]
=
None
,
frequency
:
Optional
[
meridian
.
backend
.
Tensor
]
=
None
,
rf_impressions
:
Optional
[
meridian
.
backend
.
Tensor
]
=
None
,
rf_spend
:
Optional
[
meridian
.
backend
.
Tensor
]
=
None
,
organic_media
:
Optional
[
meridian
.
backend
.
Tensor
]
=
None
,
organic_reach
:
Optional
[
meridian
.
backend
.
Tensor
]
=
None
,
organic_frequency
:
Optional
[
meridian
.
backend
.
Tensor
]
=
None
,
non_media_treatments
:
Optional
[
meridian
.
backend
.
Tensor
]
=
None
,
controls
:
Optional
[
meridian
.
backend
.
Tensor
]
=
None
,
revenue_per_kpi
:
Optional
[
meridian
.
backend
.
Tensor
]
=
None
,
time
:
Optional
[
Sequence
[
str
]
|
meridian
.
backend
.
Tensor
]
=
None
)
Optional tensor with dimensions (n_geos, T, n_media_channels)
for
any time dimension T
.
Optional tensor with dimensions (n_media_channels,)
or (n_geos, T, n_media_channels)
for any time dimension T
. If the object
includes variables with modified time periods, then this tensor must be
provided at the geo and time granularity.
Optional tensor with dimensions (n_geos, T, n_rf_channels)
for any
time dimension T
.
Optional tensor with dimensions (n_geos, T, n_rf_channels)
for
any time dimension T
.
Optional tensor with dimensions (n_geos, T, n_rf_channels)
for any time dimension T
.
Optional tensor with dimensions (n_rf_channels,)
or (n_geos, T,
n_rf_channels)
for any time dimension T
. If the object includes
variables with modified time periods, then this tensor must be provided at
the geo and time granularity.
Optional tensor with dimensions (n_geos, T,
n_organic_media_channels)
for any time dimension T
.
Optional tensor with dimensions (n_geos, T,
n_organic_rf_channels)
for any time dimension T
.
Optional tensor with dimensions (n_geos, T,
n_organic_rf_channels)
for any time dimension T
.
Optional tensor with dimensions (n_geos, T,
n_non_media_channels)
for any time dimension T
.
Optional tensor with dimensions (n_geos, n_times, n_controls)
.
Optional tensor with dimensions (n_geos, T)
for any time
dimension T
.
Optional tensor of time coordinates in the "YYYY-mm-dd" string format
for time dimension T
.
Child Classes
class Spec
Methods
filter_fields
View source
filter_fields
(
fields
:
Sequence
[
str
]
)
->
Self
Returns a new DataTensors object with only the specified fields.
get_modified_times
View source
get_modified_times
(
meridian
:
meridian
.
model
.
model
.
Meridian
)
->
(
int
|
None
)
Returns n_times
of any tensor where n_times
has been modified.
This method compares the time dimensions of the attributes in the DataTensors
object with the corresponding tensors in the meridian
object. If any of the time dimensions are different, then this method
returns the modified number of time periods of the tensor in the DataTensors
object. If all time dimensions are the same, returns None
.
meridian
A Meridian object to validate against and get the original data
tensors from.
The n_times
of any tensor where n_times
is different from the times
of the corresponding tensor in the meridian
object. If all time
dimensions are the same, returns None
.
total_spend
View source
total_spend
()
->
(
meridian
.
backend
.
Tensor
|
None
)
Returns the total spend tensor.
The media_spend
tensor (if present) concatenated with the rf_spend
tensor (if present), in this order. If both tensors are missing, returns None
.
validate_and_fill_missing_data
View source
validate_and_fill_missing_data
(
required_tensors_names
:
Sequence
[
str
],
meridian
:
meridian
.
model
.
model
.
Meridian
,
allow_modified_times
:
bool
=
True
)
->
Self
Fills missing data tensors with their original values from the model.
This method uses the collection of data tensors set in the DataTensor class
and fills in the missing tensors with their original values from the
Meridian object that is passed in. For example, if required_tensors_names =
["media", "reach", "frequency"]
and only media
is set in the DataTensors
class, then this method will output a new DataTensors object with the media
value in this object plus the values of the reach
and frequency
from the meridian
object.
required_tensors_names
A sequence of data tensors names to validate and
fill in with the original values from the meridian
object.
meridian
The Meridian object to validate against and get the original
data tensors from.
allow_modified_times
A boolean flag indicating whether to allow modified
time dimensions in the new data tensors. If False, an error will be
raised if the time dimensions of any tensor is modified.
A DataTensors
container with the original values from the Meridian
object filled in for the missing data tensors.
__eq__
__eq__
(
other
)
Return self==value.
__ne__
__ne__
(
other
)
Return self!=value.
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\u003e\u003ccode\u003eDataTensors\u003c/code\u003e is a container for various data variables used as arguments in Analyzer methods, particularly those related to media, reach, and organic metrics.\u003c/p\u003e\n"],["\u003cp\u003eThis container includes optional tensors for media, media spend, reach, frequency, RF spend, organic media, organic reach, organic frequency, non-media treatments, controls, and revenue per KPI, each with specified dimensions.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eDataTensors\u003c/code\u003e includes multiple attributes that can have optional tensors relating to different types of data, such as media, reach, and organic media, all across any time dimension \u003ccode\u003eT\u003c/code\u003e and with various channel options.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eDataTensors\u003c/code\u003e class has methods \u003ccode\u003e__eq__\u003c/code\u003e and \u003ccode\u003e__ne__\u003c/code\u003e to check equality and inequality respectively, and multiple class variables, including \u003ccode\u003econtrols\u003c/code\u003e, \u003ccode\u003efrequency\u003c/code\u003e, and \u003ccode\u003emedia\u003c/code\u003e that are set to \u003ccode\u003eNone\u003c/code\u003e.\u003c/p\u003e\n"]]],["`DataTensors` is a container for data variables used in Analyzer methods, accommodating various optional tensors. These include `media`, `media_spend`, `reach`, `frequency`, `rf_spend`, `organic_media`, `organic_reach`, `organic_frequency`, `non_media_treatments`, `controls`, and `revenue_per_kpi`. Each tensor holds data with specific dimensions, typically relating to geos, time, and channels. The class includes `__eq__` and `__ne__` methods for equality comparisons. Class variables default to `None`, showing data availability.\n"],null,["\u003cbr /\u003e\n\n|----------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/google/meridian/blob/v1.2.0/meridian/analysis/analyzer.py#L56-L500) |\n\nContainer for data variable arguments of Analyzer methods.\n\nInherits From: [`ExtensionType`](../../../meridian/backend/ExtensionType.md) \n\n meridian.analysis.analyzer.DataTensors(\n media: Optional[../../../meridian/backend/Tensor.md] = None,\n media_spend: Optional[../../../meridian/backend/Tensor.md] = None,\n reach: Optional[../../../meridian/backend/Tensor.md] = None,\n frequency: Optional[../../../meridian/backend/Tensor.md] = None,\n rf_impressions: Optional[../../../meridian/backend/Tensor.md] = None,\n rf_spend: Optional[../../../meridian/backend/Tensor.md] = None,\n organic_media: Optional[../../../meridian/backend/Tensor.md] = None,\n organic_reach: Optional[../../../meridian/backend/Tensor.md] = None,\n organic_frequency: Optional[../../../meridian/backend/Tensor.md] = None,\n non_media_treatments: Optional[../../../meridian/backend/Tensor.md] = None,\n controls: Optional[../../../meridian/backend/Tensor.md] = None,\n revenue_per_kpi: Optional[../../../meridian/backend/Tensor.md] = None,\n time: Optional[Sequence[str] | ../../../meridian/backend/Tensor.md] = None\n )\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ||\n|------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `media` | Optional tensor with dimensions `(n_geos, T, n_media_channels)` for any time dimension `T`. |\n| `media_spend` | Optional tensor with dimensions `(n_media_channels,)` or `(n_geos, T, n_media_channels)` for any time dimension `T`. If the object includes variables with modified time periods, then this tensor must be provided at the geo and time granularity. |\n| `reach` | Optional tensor with dimensions `(n_geos, T, n_rf_channels)` for any time dimension `T`. |\n| `frequency` | Optional tensor with dimensions `(n_geos, T, n_rf_channels)` for any time dimension `T`. |\n| `rf_impressions` | Optional tensor with dimensions `(n_geos, T, n_rf_channels)` for any time dimension `T`. |\n| `rf_spend` | Optional tensor with dimensions `(n_rf_channels,)` or `(n_geos, T, n_rf_channels)` for any time dimension `T`. If the object includes variables with modified time periods, then this tensor must be provided at the geo and time granularity. |\n| `organic_media` | Optional tensor with dimensions `(n_geos, T, n_organic_media_channels)` for any time dimension `T`. |\n| `organic_reach` | Optional tensor with dimensions `(n_geos, T, n_organic_rf_channels)` for any time dimension `T`. |\n| `organic_frequency` | Optional tensor with dimensions `(n_geos, T, n_organic_rf_channels)` for any time dimension `T`. |\n| `non_media_treatments` | Optional tensor with dimensions `(n_geos, T, n_non_media_channels)` for any time dimension `T`. |\n| `controls` | Optional tensor with dimensions `(n_geos, n_times, n_controls)`. |\n| `revenue_per_kpi` | Optional tensor with dimensions `(n_geos, T)` for any time dimension `T`. |\n| `time` | Optional tensor of time coordinates in the \"YYYY-mm-dd\" string format for time dimension `T`. |\n\n\u003cbr /\u003e\n\nChild Classes\n\n[`class Spec`](../../../meridian/analysis/analyzer/DataTensors/Spec.md)\n\nMethods\n\n`filter_fields`\n\n[View source](https://github.com/google/meridian/blob/v1.2.0/meridian/analysis/analyzer.py#L237-L242) \n\n filter_fields(\n fields: Sequence[str]\n ) -\u003e Self\n\nReturns a new DataTensors object with only the specified fields.\n\n`get_modified_times`\n\n[View source](https://github.com/google/meridian/blob/v1.2.0/meridian/analysis/analyzer.py#L201-L235) \n\n get_modified_times(\n meridian: ../../../meridian/model/model/Meridian.md\n ) -\u003e (int | None)\n\nReturns `n_times` of any tensor where `n_times` has been modified.\n\nThis method compares the time dimensions of the attributes in the\n`DataTensors` object with the corresponding tensors in the [`meridian`](../../../meridian.md)\nobject. If any of the time dimensions are different, then this method\nreturns the modified number of time periods of the tensor in the\n`DataTensors` object. If all time dimensions are the same, returns `None`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|------------|-------------------------------------------------------------------------------|\n| `meridian` | A Meridian object to validate against and get the original data tensors from. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| The `n_times` of any tensor where `n_times` is different from the times of the corresponding tensor in the [`meridian`](../../../meridian.md) object. If all time dimensions are the same, returns `None`. ||\n\n\u003cbr /\u003e\n\n`total_spend`\n\n[View source](https://github.com/google/meridian/blob/v1.2.0/meridian/analysis/analyzer.py#L184-L199) \n\n total_spend() -\u003e (../../../meridian/backend/Tensor.md | None)\n\nReturns the total spend tensor.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| The `media_spend` tensor (if present) concatenated with the `rf_spend` tensor (if present), in this order. If both tensors are missing, returns `None`. ||\n\n\u003cbr /\u003e\n\n`validate_and_fill_missing_data`\n\n[View source](https://github.com/google/meridian/blob/v1.2.0/meridian/analysis/analyzer.py#L244-L281) \n\n validate_and_fill_missing_data(\n required_tensors_names: Sequence[str],\n meridian: ../../../meridian/model/model/Meridian.md,\n allow_modified_times: bool = True\n ) -\u003e Self\n\nFills missing data tensors with their original values from the model.\n\nThis method uses the collection of data tensors set in the DataTensor class\nand fills in the missing tensors with their original values from the\nMeridian object that is passed in. For example, if `required_tensors_names =\n[\"media\", \"reach\", \"frequency\"]` and only `media` is set in the DataTensors\nclass, then this method will output a new DataTensors object with the\n`media` value in this object plus the values of the `reach` and `frequency`\nfrom the [`meridian`](../../../meridian.md) object.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|--------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `required_tensors_names` | A sequence of data tensors names to validate and fill in with the original values from the [`meridian`](../../../meridian.md) object. |\n| `meridian` | The Meridian object to validate against and get the original data tensors from. |\n| `allow_modified_times` | A boolean flag indicating whether to allow modified time dimensions in the new data tensors. If False, an error will be raised if the time dimensions of any tensor is modified. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| A `DataTensors` container with the original values from the Meridian object filled in for the missing data tensors. ||\n\n\u003cbr /\u003e\n\n`__eq__` \n\n __eq__(\n other\n )\n\nReturn self==value.\n\n`__ne__` \n\n __ne__(\n other\n )\n\nReturn self!=value."]]