Skip to content

Add Bass Diffusion Model #1328

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

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft

Add Bass Diffusion Model #1328

wants to merge 15 commits into from

Conversation

williambdean
Copy link
Contributor

@williambdean williambdean commented Jan 3, 2025

Description

Adding Bass Diffusion Model

Related Issue

Checklist

Modules affected

  • MMM
  • CLV
  • Customer Choice
  • Product Development

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

📚 Documentation preview 📚: https://pymc-marketing--1328.org.readthedocs.build/en/1328/

@github-actions github-actions bot added the enhancement New feature or request label Jan 3, 2025
@williambdean
Copy link
Contributor Author

Here is a crude implementation of the Bass model. Feel free to take over @juanitorduz

I forget why I didn't wrap it in the ModelBuilder. Maybe I was just trying it out and familiarizing myself with the model. Maybe it will be straight forward but I remember having some concern.

As for the magnitude of m compared to the other parameters and NUTS, maybe a scaling constant can be used in the model. You might have some more ideas.

model = Bass(m_scaling=5000)

# Under the hood
m = m_scaling * Prior.create_variable(...)

Copy link

codecov bot commented Jan 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.55%. Comparing base (a87f1fa) to head (2a4dd03).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1328      +/-   ##
==========================================
+ Coverage   93.53%   93.55%   +0.02%     
==========================================
  Files          55       56       +1     
  Lines        6357     6381      +24     
==========================================
+ Hits         5946     5970      +24     
  Misses        411      411              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@juanitorduz
Copy link
Collaborator

Thanks @wd60622 ! I will familiarize myself with the model and push it forward 🙌

@williambdean
Copy link
Contributor Author

williambdean commented Jan 3, 2025

Sounds good! Thanks

I had the idea we could parameterize it as days/weeks/months from product launch making pooling across dims / products easier. I feel like that would be an interesting insight.

@juanitorduz juanitorduz self-assigned this Jan 3, 2025
@williambdean
Copy link
Contributor Author

Visual produced from the main block:

bass

@juanitorduz
Copy link
Collaborator

I will pick up this one so that we can merge the base model and iterate

@williambdean
Copy link
Contributor Author

williambdean commented Apr 2, 2025

The magnitude of m might benefit from VariableFactory protocol allows for:

import pymc as pm
from pymc_marketing.prior import Prior

class Scaled: 
    def __init__(self, dist: Prior, factor: str): 
        self.dist = dist
        self.factor = factor 

    @property 
    def dims(self): 
        return self.dist.dims

    def create_variable(self, name: str): 
        var = self.dist.create_variable(f"{name}_unscaled")
        return pm.Deterministic(name, var * self.factor, dims=self.dims)

This would keep the model itself free from this scaling logic but still allow if needed.

from pymc_marketing.prior import sample_prior

m = Scaled(Prior("HalfNormal", sigma=1), 5000)
prior = sample_prior(m)

scaled

@github-actions github-actions bot added the tests label Apr 8, 2025
@github-actions github-actions bot added the docs Improvements or additions to documentation label Apr 8, 2025
@juanitorduz juanitorduz marked this pull request as draft April 8, 2025 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to documentation enhancement New feature or request tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Bass Diffusion Model
2 participants