Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mock MMM posterior with prior #582

Closed
wants to merge 30 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d5b5176
mock the posterior with prior
wd60622 Mar 10, 2024
c4f3884
rename and mock in test_plotting
wd60622 Mar 10, 2024
f085838
remove tests that wont work with prior as posterior
wd60622 Mar 14, 2024
b30f9d3
Remove scale_preserving_logistic_saturation function (#585)
ulfaslak Mar 11, 2024
6e7b701
Bump minimum Python version in environment.yml
ricardoV94 Mar 14, 2024
29fde57
Remove useless fixtures in test_gamma_gamma
ricardoV94 Mar 4, 2024
ce80f57
Make test_save_load lighter
ricardoV94 Mar 14, 2024
6993997
Run slow tests in CI
ricardoV94 Feb 29, 2024
277c7d1
Make GammaGamma.test_model_convergence more stable
ricardoV94 Mar 14, 2024
e7e3ecb
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Mar 12, 2024
49398fe
Add test util for setting fake data in CLV models
ricardoV94 Mar 1, 2024
b9e61d2
Implement ParetoNBD with covariates
ricardoV94 Mar 1, 2024
13e6e9b
Update version.txt
ricardoV94 Mar 15, 2024
4f33440
Make data optional in all ParetoNBD methods
ricardoV94 Mar 15, 2024
97b9807
Assign coords in ParetoNBDModel
ricardoV94 Mar 15, 2024
a6b6b94
Update version.txt
ricardoV94 Mar 15, 2024
5c70875
add test setup
wd60622 Mar 16, 2024
7d0dd9c
store commit
wd60622 Mar 17, 2024
267cef2
store commit
wd60622 Mar 18, 2024
824914a
implement slow but actual fit tests
wd60622 Mar 21, 2024
4823d39
correct after failing
wd60622 Mar 21, 2024
d8c49ce
Merge branch 'main' into mock-mmm-fit
wd60622 Apr 1, 2024
873436a
Merge branch 'main' into mock-mmm-fit
wd60622 Apr 8, 2024
8513e46
add variables that make up 500
wd60622 Apr 8, 2024
34a79c8
add an expected fail
wd60622 Apr 8, 2024
0d36fd1
Merge branch 'pymc-labs:main' into mock-mmm-fit
wd60622 Apr 11, 2024
ed279c0
add additional difference between changes by masking
wd60622 Apr 11, 2024
de5d5d2
Merge branch 'main' into mock-mmm-fit
wd60622 May 2, 2024
1c86f78
Merge branch 'main' into mock-mmm-fit
wd60622 May 21, 2024
90ff335
Merge branch 'main' into mock-mmm-fit
wd60622 Jun 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions tests/mmm/test_delayed_saturated_mmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -872,27 +872,39 @@ def test_plot_new_spend_contributions_prior_select_channels(
@pytest.fixture(scope="module")
def fixed_model_parameters() -> dict[str, Union[float, list[float]]]:
return {
"intercept": 2.5,
"beta_channel": [0.5, 0.5],
"intercept": 5.0,
"beta_channel": [0.15, 0.5],
"alpha": [0.5, 0.5],
"lam": [0.5, 0.5],
"likelihood_sigma": 0.25,
"gamma_control": [0.5, 0.5],
"gamma_control": [0.0001, 0.005],
wd60622 marked this conversation as resolved.
Show resolved Hide resolved
}


def random_mask(df: pd.DataFrame, mask_value: float = 0.0) -> pd.DataFrame:
shape = df.shape

mask = rng.choice([0, 1], size=shape, p=[0.75, 0.25])
return df.mul(mask)


@pytest.fixture(scope="module")
def masked_toy_X(toy_X) -> pd.DataFrame:
return toy_X.set_index("date").pipe(random_mask).reset_index()
Comment on lines +982 to +991
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rational here is that since all of the toy_X columns are pretty much white noise, the generated y is also pretty much a white noise and the model doesn't fit well

Here there are some clear stops in toy_X making the y notably depend on the covariates



@pytest.fixture(scope="module")
def model_generated_y(mmm, toy_X, fixed_model_parameters) -> np.ndarray:
fake_y = np.ones(len(toy_X))
mmm.build_model(toy_X, fake_y)
def model_generated_y(mmm, masked_toy_X, fixed_model_parameters) -> np.ndarray:
fake_y = np.ones(len(masked_toy_X))
mmm.build_model(masked_toy_X, fake_y)

fixed_model = pm.do(mmm.model, fixed_model_parameters)
return pm.draw(fixed_model["y"], random_seed=rng)


@pytest.fixture(scope="module")
def actually_fit_mmm(mmm, toy_X, model_generated_y) -> DelayedSaturatedMMM:
mmm.fit(toy_X, model_generated_y, random_seed=rng)
def actually_fit_mmm(mmm, masked_toy_X, model_generated_y) -> DelayedSaturatedMMM:
mmm.fit(masked_toy_X, model_generated_y, random_seed=rng)
return mmm


Expand Down
Loading