google-meridian 1.1.0__py3-none-any.whl → 1.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {google_meridian-1.1.0.dist-info → google_meridian-1.1.2.dist-info}/METADATA +6 -2
- google_meridian-1.1.2.dist-info/RECORD +46 -0
- {google_meridian-1.1.0.dist-info → google_meridian-1.1.2.dist-info}/WHEEL +1 -1
- meridian/__init__.py +2 -2
- meridian/analysis/__init__.py +1 -1
- meridian/analysis/analyzer.py +29 -22
- meridian/analysis/formatter.py +1 -1
- meridian/analysis/optimizer.py +70 -44
- meridian/analysis/summarizer.py +1 -1
- meridian/analysis/summary_text.py +1 -1
- meridian/analysis/test_utils.py +1 -1
- meridian/analysis/visualizer.py +17 -8
- meridian/constants.py +3 -3
- meridian/data/__init__.py +4 -1
- meridian/data/arg_builder.py +1 -1
- meridian/data/data_frame_input_data_builder.py +614 -0
- meridian/data/input_data.py +12 -8
- meridian/data/input_data_builder.py +817 -0
- meridian/data/load.py +121 -428
- meridian/data/nd_array_input_data_builder.py +509 -0
- meridian/data/test_utils.py +60 -43
- meridian/data/time_coordinates.py +1 -1
- meridian/mlflow/__init__.py +17 -0
- meridian/mlflow/autolog.py +54 -0
- meridian/model/__init__.py +1 -1
- meridian/model/adstock_hill.py +1 -1
- meridian/model/knots.py +1 -1
- meridian/model/media.py +1 -1
- meridian/model/model.py +65 -37
- meridian/model/model_test_data.py +75 -1
- meridian/model/posterior_sampler.py +19 -15
- meridian/model/prior_distribution.py +1 -1
- meridian/model/prior_sampler.py +32 -26
- meridian/model/spec.py +18 -8
- meridian/model/transformers.py +1 -1
- google_meridian-1.1.0.dist-info/RECORD +0 -41
- {google_meridian-1.1.0.dist-info → google_meridian-1.1.2.dist-info}/licenses/LICENSE +0 -0
- {google_meridian-1.1.0.dist-info → google_meridian-1.1.2.dist-info}/top_level.txt +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright
|
|
1
|
+
# Copyright 2025 The Meridian Authors.
|
|
2
2
|
#
|
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
# you may not use this file except in compliance with the License.
|
|
@@ -120,8 +120,6 @@ class PosteriorMCMCSampler:
|
|
|
120
120
|
def joint_dist_unpinned():
|
|
121
121
|
# Sample directly from prior.
|
|
122
122
|
knot_values = yield prior_broadcast.knot_values
|
|
123
|
-
gamma_c = yield prior_broadcast.gamma_c
|
|
124
|
-
xi_c = yield prior_broadcast.xi_c
|
|
125
123
|
sigma = yield prior_broadcast.sigma
|
|
126
124
|
|
|
127
125
|
tau_g_excl_baseline = yield tfp.distributions.Sample(
|
|
@@ -377,19 +375,25 @@ class PosteriorMCMCSampler:
|
|
|
377
375
|
combined_beta = tf.concat([combined_beta, beta_gorf], axis=-1)
|
|
378
376
|
|
|
379
377
|
sigma_gt = tf.transpose(tf.broadcast_to(sigma, [n_times, n_geos]))
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
[n_geos, n_controls],
|
|
383
|
-
name=constants.GAMMA_GC_DEV,
|
|
384
|
-
)
|
|
385
|
-
gamma_gc = yield tfp.distributions.Deterministic(
|
|
386
|
-
gamma_c + xi_c * gamma_gc_dev, name=constants.GAMMA_GC
|
|
387
|
-
)
|
|
388
|
-
y_pred_combined_media = (
|
|
389
|
-
tau_gt
|
|
390
|
-
+ tf.einsum("gtm,gm->gt", combined_media_transformed, combined_beta)
|
|
391
|
-
+ tf.einsum("gtc,gc->gt", controls_scaled, gamma_gc)
|
|
378
|
+
y_pred_combined_media = tau_gt + tf.einsum(
|
|
379
|
+
"gtm,gm->gt", combined_media_transformed, combined_beta
|
|
392
380
|
)
|
|
381
|
+
# Omit gamma_c, xi_c, and gamma_gc from joint distribution output if
|
|
382
|
+
# there are no control variables in the model.
|
|
383
|
+
if n_controls:
|
|
384
|
+
gamma_c = yield prior_broadcast.gamma_c
|
|
385
|
+
xi_c = yield prior_broadcast.xi_c
|
|
386
|
+
gamma_gc_dev = yield tfp.distributions.Sample(
|
|
387
|
+
tfp.distributions.Normal(0, 1),
|
|
388
|
+
[n_geos, n_controls],
|
|
389
|
+
name=constants.GAMMA_GC_DEV,
|
|
390
|
+
)
|
|
391
|
+
gamma_gc = yield tfp.distributions.Deterministic(
|
|
392
|
+
gamma_c + xi_c * gamma_gc_dev, name=constants.GAMMA_GC
|
|
393
|
+
)
|
|
394
|
+
y_pred_combined_media += tf.einsum(
|
|
395
|
+
"gtc,gc->gt", controls_scaled, gamma_gc
|
|
396
|
+
)
|
|
393
397
|
|
|
394
398
|
if mmm.non_media_treatments is not None:
|
|
395
399
|
xi_n = yield prior_broadcast.xi_n
|
meridian/model/prior_sampler.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright
|
|
1
|
+
# Copyright 2025 The Meridian Authors.
|
|
2
2
|
#
|
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
# you may not use this file except in compliance with the License.
|
|
@@ -175,8 +175,9 @@ class PriorDistributionSampler:
|
|
|
175
175
|
(https://github.com/tensorflow/probability/blob/main/PRNGS.md).
|
|
176
176
|
|
|
177
177
|
Returns:
|
|
178
|
-
A mapping of RF parameter names to a tensor of shape
|
|
179
|
-
n_rf_channels]` or `[n_draws, n_rf_channels]`
|
|
178
|
+
A mapping of RF parameter names to a tensor of shape
|
|
179
|
+
`[n_draws, n_geos, n_rf_channels]` or `[n_draws, n_rf_channels]`
|
|
180
|
+
containing the samples.
|
|
180
181
|
"""
|
|
181
182
|
mmm = self._meridian
|
|
182
183
|
|
|
@@ -269,9 +270,9 @@ class PriorDistributionSampler:
|
|
|
269
270
|
(https://github.com/tensorflow/probability/blob/main/PRNGS.md).
|
|
270
271
|
|
|
271
272
|
Returns:
|
|
272
|
-
A mapping of organic media parameter names to a tensor of shape
|
|
273
|
-
n_geos, n_organic_media_channels] or
|
|
274
|
-
containing the samples.
|
|
273
|
+
A mapping of organic media parameter names to a tensor of shape
|
|
274
|
+
`[n_draws, n_geos, n_organic_media_channels]` or
|
|
275
|
+
`[n_draws, n_organic_media_channels]` containing the samples.
|
|
275
276
|
"""
|
|
276
277
|
mmm = self._meridian
|
|
277
278
|
|
|
@@ -352,9 +353,9 @@ class PriorDistributionSampler:
|
|
|
352
353
|
(https://github.com/tensorflow/probability/blob/main/PRNGS.md).
|
|
353
354
|
|
|
354
355
|
Returns:
|
|
355
|
-
A mapping of organic RF parameter names to a tensor of shape
|
|
356
|
-
n_geos, n_organic_rf_channels] or
|
|
357
|
-
containing the samples.
|
|
356
|
+
A mapping of organic RF parameter names to a tensor of shape
|
|
357
|
+
`[n_draws, n_geos, n_organic_rf_channels]` or
|
|
358
|
+
`[n_draws, n_organic_rf_channels]` containing the samples.
|
|
358
359
|
"""
|
|
359
360
|
mmm = self._meridian
|
|
360
361
|
|
|
@@ -436,9 +437,8 @@ class PriorDistributionSampler:
|
|
|
436
437
|
|
|
437
438
|
Returns:
|
|
438
439
|
A mapping of non-media treatment parameter names to a tensor of shape
|
|
439
|
-
[n_draws,
|
|
440
|
-
|
|
441
|
-
containing the samples.
|
|
440
|
+
`[n_draws, n_geos, n_non_media_channels]` or
|
|
441
|
+
`[n_draws, n_non_media_channels]` containing the samples.
|
|
442
442
|
"""
|
|
443
443
|
mmm = self._meridian
|
|
444
444
|
|
|
@@ -470,8 +470,7 @@ class PriorDistributionSampler:
|
|
|
470
470
|
mmm.compute_non_media_treatments_baseline()
|
|
471
471
|
)
|
|
472
472
|
linear_predictor_counterfactual_difference = (
|
|
473
|
-
mmm.non_media_treatments_normalized
|
|
474
|
-
- baseline_scaled
|
|
473
|
+
mmm.non_media_treatments_normalized - baseline_scaled
|
|
475
474
|
)
|
|
476
475
|
gamma_n_value = mmm.calculate_beta_x(
|
|
477
476
|
is_non_media=True,
|
|
@@ -517,8 +516,6 @@ class PriorDistributionSampler:
|
|
|
517
516
|
tau_g_excl_baseline = prior.tau_g_excl_baseline.sample(**sample_kwargs)
|
|
518
517
|
base_vars = {
|
|
519
518
|
constants.KNOT_VALUES: prior.knot_values.sample(**sample_kwargs),
|
|
520
|
-
constants.GAMMA_C: prior.gamma_c.sample(**sample_kwargs),
|
|
521
|
-
constants.XI_C: prior.xi_c.sample(**sample_kwargs),
|
|
522
519
|
constants.SIGMA: prior.sigma.sample(**sample_kwargs),
|
|
523
520
|
constants.TAU_G: (
|
|
524
521
|
_get_tau_g(
|
|
@@ -527,6 +524,7 @@ class PriorDistributionSampler:
|
|
|
527
524
|
).sample()
|
|
528
525
|
),
|
|
529
526
|
}
|
|
527
|
+
|
|
530
528
|
base_vars[constants.MU_T] = tfp.distributions.Deterministic(
|
|
531
529
|
tf.einsum(
|
|
532
530
|
"...k,kt->...t",
|
|
@@ -536,16 +534,24 @@ class PriorDistributionSampler:
|
|
|
536
534
|
name=constants.MU_T,
|
|
537
535
|
).sample()
|
|
538
536
|
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
537
|
+
# Omit gamma_c, xi_c, and gamma_gc parameters from sampled distributions if
|
|
538
|
+
# there are no control variables in the model.
|
|
539
|
+
if mmm.n_controls:
|
|
540
|
+
base_vars |= {
|
|
541
|
+
constants.GAMMA_C: prior.gamma_c.sample(**sample_kwargs),
|
|
542
|
+
constants.XI_C: prior.xi_c.sample(**sample_kwargs),
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
gamma_gc_dev = tfp.distributions.Sample(
|
|
546
|
+
tfp.distributions.Normal(0, 1),
|
|
547
|
+
[mmm.n_geos, mmm.n_controls],
|
|
548
|
+
name=constants.GAMMA_GC_DEV,
|
|
549
|
+
).sample(**sample_kwargs)
|
|
550
|
+
base_vars[constants.GAMMA_GC] = tfp.distributions.Deterministic(
|
|
551
|
+
base_vars[constants.GAMMA_C][..., tf.newaxis, :]
|
|
552
|
+
+ base_vars[constants.XI_C][..., tf.newaxis, :] * gamma_gc_dev,
|
|
553
|
+
name=constants.GAMMA_GC,
|
|
554
|
+
).sample()
|
|
549
555
|
|
|
550
556
|
media_vars = (
|
|
551
557
|
self._sample_media_priors(n_draws, seed)
|
meridian/model/spec.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright
|
|
1
|
+
# Copyright 2025 The Meridian Authors.
|
|
2
2
|
#
|
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
# you may not use this file except in compliance with the License.
|
|
@@ -109,17 +109,27 @@ class ModelSpec:
|
|
|
109
109
|
roi_calibration_period: An optional boolean array of shape `(n_media_times,
|
|
110
110
|
n_media_channels)` indicating the subset of `time` that the ROI value of
|
|
111
111
|
the `roi_m` prior applies to. The ROI numerator is the incremental outcome
|
|
112
|
-
generated
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
generated by media executed during the calibration period. More precisely,
|
|
113
|
+
it is the difference in expected outcome between the counterfactual where
|
|
114
|
+
media is set to historical values versus the counterfactual where media is
|
|
115
|
+
set to zero during the calibration period and set to historical values for
|
|
116
|
+
all other time periods. The denominator is the channel spend during
|
|
117
|
+
calibration period (excluding any calibration time periods prior to the
|
|
118
|
+
first KPI time period). Spend data by time period is required. If `None`,
|
|
119
|
+
all times are used. Only used if `media_prior_type` is `'roi'`.
|
|
115
120
|
Default: `None`.
|
|
116
121
|
rf_roi_calibration_period: An optional boolean array of shape
|
|
117
122
|
`(n_media_times, n_rf_channels)` indicating the subset of `time` that the
|
|
118
123
|
ROI value of the `roi_rf` prior applies to. The ROI numerator is the
|
|
119
|
-
incremental outcome generated
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
124
|
+
incremental outcome generated by media executed during the calibration
|
|
125
|
+
period. More precisely, it is the difference in expected outcome between
|
|
126
|
+
the counterfactual where reach and frequency is set to historical values
|
|
127
|
+
versus the counterfactual where reach is set to zero during the
|
|
128
|
+
calibration period and set to historical values for all other time
|
|
129
|
+
periods. The denominator is the channel spend during calibration period
|
|
130
|
+
(excluding any calibration time periods prior to the first KPI time
|
|
131
|
+
period). Spend data by time period is required. If `None`, all times are
|
|
132
|
+
used. Only used if `rf_prior_type` is `'roi'`. Default: `None`.
|
|
123
133
|
organic_media_prior_type: A string to specify the prior type for the organic
|
|
124
134
|
media coefficients. Allowed values: `'contribution'`, `'coefficient'`.
|
|
125
135
|
`PriorDistribution` contains `contribution_om` and `beta_om`, but only one
|
meridian/model/transformers.py
CHANGED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
google_meridian-1.1.0.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
|
|
2
|
-
meridian/__init__.py,sha256=Z2HBhx0G1hdGh8Q3k-4Bt6WrPHpHyAxUpeKaT0QXXQg,714
|
|
3
|
-
meridian/constants.py,sha256=C0Af-w-q4fL-GW08Z9jrRRCet-dAdXpz7LsX1SA8uf0,17157
|
|
4
|
-
meridian/analysis/__init__.py,sha256=-FooDZ5OzePpyTVkvRoWQx_xBaRR_hjVLny9H8-kkyQ,836
|
|
5
|
-
meridian/analysis/analyzer.py,sha256=qVv8654KLyz8kFVn06oHfkKfwXQHwS4RwdckTRbFpgE,203995
|
|
6
|
-
meridian/analysis/formatter.py,sha256=F8OYxD2bH13zV10JY63j2ugCOj-DpTXhyJr43n5ukr8,7270
|
|
7
|
-
meridian/analysis/optimizer.py,sha256=tYOqgj-neqgOGdjs6F4GbQVAmMQ9JyEUXpqUScanhnk,106122
|
|
8
|
-
meridian/analysis/summarizer.py,sha256=VVtMsNct5PrnWHdVnDzo_dyiTM9labUD55G1FXdxxOM,18855
|
|
9
|
-
meridian/analysis/summary_text.py,sha256=n6a-DTZxtS3WvdI_pDEK7lvO3MRUX3h83GzuVnG6sQ4,12438
|
|
10
|
-
meridian/analysis/test_utils.py,sha256=uNJuBsRaHz8Cnaqq5DhOc271mQKYk8h-fIG5du0kCBw,77699
|
|
11
|
-
meridian/analysis/visualizer.py,sha256=6iyNOtjds4CwPaTmEoh_2XuYx4kFxUl8W7t2fmL4vSk,93736
|
|
12
|
-
meridian/analysis/templates/card.html.jinja,sha256=pv4MVbQ25CcvtZY-LH7bFW0OSeHobkeEkAleB1sfQ14,1284
|
|
13
|
-
meridian/analysis/templates/chart.html.jinja,sha256=87i0xnXHRBoLLxBpKv2i960TLToWq4r1aVQZqaXIeMQ,1086
|
|
14
|
-
meridian/analysis/templates/chips.html.jinja,sha256=Az0tQwF_-b03JDLyOzpeH-8fb-6jgJgbNfnUUSm-q6E,645
|
|
15
|
-
meridian/analysis/templates/insights.html.jinja,sha256=6hEWipbOMiMzs9QGZ6dcB_73tNkj0ZtNiC8E89a98zg,606
|
|
16
|
-
meridian/analysis/templates/stats.html.jinja,sha256=9hQOG02FX1IHVIvdWS_-LI2bbSaqdyHEtCZkiArwAg0,772
|
|
17
|
-
meridian/analysis/templates/style.css,sha256=RODTWc2pXcG9zW3q9SEJpVXgeD-WwQgzLpmFcbXPhLg,5492
|
|
18
|
-
meridian/analysis/templates/style.scss,sha256=nSrZOpcIrVyiL4eC9jLUlxIZtAKZ0Rt8pwfk4H1nMrs,5076
|
|
19
|
-
meridian/analysis/templates/summary.html.jinja,sha256=LuENVDHYIpNo4pzloYaCR2K9XN1Ow6_9oQOcOwD9nGg,1707
|
|
20
|
-
meridian/analysis/templates/table.html.jinja,sha256=mvLMZx92RcD2JAS2w2eZtfYG-6WdfwYVo7pM8TbHp4g,1176
|
|
21
|
-
meridian/data/__init__.py,sha256=ixOYHDQExjnPTLLnZ758pRQscZP7c8QJqtc8P4hK-mE,774
|
|
22
|
-
meridian/data/arg_builder.py,sha256=f7LEysYmixAagwygZOEiJkRnWggRhTeXj5AXthBpkQ8,3741
|
|
23
|
-
meridian/data/input_data.py,sha256=GJcf3wqMrF1jFZ3hBk1mlqUMV8_-gEo8ZagiB5siJ58,39610
|
|
24
|
-
meridian/data/load.py,sha256=MKCnRoR8ZIfhEAcm5ZUQsjfoEzi1c9SDOgf6BR8Akr0,54642
|
|
25
|
-
meridian/data/test_utils.py,sha256=4c2WIPfu-vYudyVM9WLUWrJ4Op14L-zk34N09_6Za8E,55015
|
|
26
|
-
meridian/data/time_coordinates.py,sha256=wTr-JKWNkMOkiZQ8B16qy0bUUuMkdh9sI2-IP4HRUTw,9874
|
|
27
|
-
meridian/model/__init__.py,sha256=bvx8vvXolktsCTDKViU9U1v85pgNWF3haDowTKy11d4,982
|
|
28
|
-
meridian/model/adstock_hill.py,sha256=b_YYhqci6ndgi602FFXmx2f12ceC4N0tp338nMMtm54,9283
|
|
29
|
-
meridian/model/knots.py,sha256=r7PPaJM96d5pkoOeV9crIOgkM0-rh24mWMvypMiV4aQ,8054
|
|
30
|
-
meridian/model/media.py,sha256=Tb8tOK_ay1kGjq1a6xsjW8XdMOWAuYCgE7-YYSyJCho,13819
|
|
31
|
-
meridian/model/model.py,sha256=Vg0HZg8X5BiKLRgrM65xO4P6uO7S46BfTaP3qmjtUCI,60398
|
|
32
|
-
meridian/model/model_test_data.py,sha256=t6W-xRuQlrCuMOpdjy4zIzMdBCFuFbHB7_ELKqOI8L8,12917
|
|
33
|
-
meridian/model/posterior_sampler.py,sha256=S0ZbWFghiUV51yKt2tr4_aBr2JrqR5Z6wEXn8P8VmbI,27527
|
|
34
|
-
meridian/model/prior_distribution.py,sha256=vkvmZ0lIc150Fgejo7YVDzjWJxgs-tOPBlMneX5I1oo,42417
|
|
35
|
-
meridian/model/prior_sampler.py,sha256=xJ-X_Q1gFp6amANre78Cq70T1qS6UKO_iXmePNokX8g,23001
|
|
36
|
-
meridian/model/spec.py,sha256=lUGgSIAQdpBQIBNBPBTW5f9Dbk7PaxeLZVFuWQ1VZ00,17239
|
|
37
|
-
meridian/model/transformers.py,sha256=j6yHvLpdDGOXcJHddDP7pZalxMs25eGUx1vu2ppfriQ,7763
|
|
38
|
-
google_meridian-1.1.0.dist-info/METADATA,sha256=S4ADeuHKzmdSwL2GxVhwgeyr0DPpqJsM2m5xoi-R8XU,22055
|
|
39
|
-
google_meridian-1.1.0.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
|
|
40
|
-
google_meridian-1.1.0.dist-info/top_level.txt,sha256=nwaCebZvvU34EopTKZsjK0OMTFjVnkf4FfnBN_TAc0g,9
|
|
41
|
-
google_meridian-1.1.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|