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

Non-scalar ls in HSGP / HSGPPeriodic #1280

Open
wd60622 opened this issue Dec 14, 2024 · 5 comments
Open

Non-scalar ls in HSGP / HSGPPeriodic #1280

wd60622 opened this issue Dec 14, 2024 · 5 comments
Labels
enhancement New feature or request TVPs Related to time varying parameters

Comments

@wd60622
Copy link
Contributor

wd60622 commented Dec 14, 2024

I would like to be able to use vector (including hierarchical) ls for these two classes.

It would look like this:

from pymc_marketing.prior import Prior
from pymc_marketing.mmm import HSGP

ls = Prior("HalfNormal", dims="channel")
hsgp = HSGP(ls=ls, ..., dims=("date", "channel"))

The dims would have to be handled here:

cov_func = eta**2 * cov_funcs[self.cov_func.lower()](input_dim=1, ls=ls)
gp = pm.gp.HSGP(
m=[self.m],
L=[self.L],
cov_func=cov_func,
drop_first=self.drop_first,
)
phi, sqrt_psd = gp.prior_linearized(
self.X[:, None] - self.X_mid,
)

@wd60622 wd60622 changed the title Hierarchical ls in HSGP / HSGPPeriodic Non-scalar ls in HSGP / HSGPPeriodic Dec 14, 2024
@wd60622 wd60622 added enhancement New feature or request TVPs Related to time varying parameters and removed Needs Triage labels Dec 14, 2024
@wd60622
Copy link
Contributor Author

wd60622 commented Dec 14, 2024

Have you done this logic @bwengals ?
I tried and see that that the shapes out of prior_linearized need a bit of handling

@juanitorduz
Copy link
Collaborator

This would be great! I think we would need to make sure the spectral density expressions vecorize over ls?

Actually, it seems the spectral density functions do handle vector length scales:

https://github.com/pymc-devs/pymc/blob/5d51953df0168fce4029675575f7002db71e4347/pymc/gp/cov.py#L574-L587

@wd60622
Copy link
Contributor Author

wd60622 commented Dec 14, 2024

This would be great! I think we would need to make sure the spectral density expressions vecorize over ls?

Actually, it seems the spectral density functions do handle vector length scales:

https://github.com/pymc-devs/pymc/blob/5d51953df0168fce4029675575f7002db71e4347/pymc/gp/cov.py#L574-L587

Yes, think we just need the dims to broadcast correctly. But i tried out and there needs a little thought behind the following operations with psd, etc

@bwengals
Copy link

@juanitorduz they do handle vector lengthscales, but in terms of input dimension. For example, a spatial GP with a different lengthscale for the x and the y directions. It'd be really nice if they could handle both input dimension and the case below (vectorized, multi-dimensional inputs), but I had no idea how to do that.

There are examples here of using a vector of lengthscales for the case where you have multiple GPs each with a different lengthscale that you're implementing in a vectorized way. I'm purposefully saying they're multiple GP's because if the lengthscales are different then the kernels are different, and that's what differentiates one GP from another. I'd bet for most hierarchical GPs they'd share the same lengthscale parameter.

Which of these two cases are you trying to implement?

@juanitorduz
Copy link
Collaborator

Thanks @bwengals for the clarification. I think for MMMs you are right, all lengths scales would be similar. I think the main ingredients are in the HSGP advanced example you shared (which should be a similar strategy as in https://www.pymc-labs.com/blog-posts/modelling-changes-marketing-effectiveness-over-time/ I believe)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request TVPs Related to time varying parameters
Projects
None yet
Development

No branches or pull requests

3 participants