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

Custom optimizer constraints #1358

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

Conversation

cetagostini
Copy link
Contributor

@cetagostini cetagostini commented Jan 8, 2025

Description

Allowing optimizer to use custom constraints around any intermediate variable (e.g: Response, Specific channel contributions or budgets).

Build on top of #1357 by @ricardoV94

Related Issue

Checklist

Modules affected

  • MMM
  • CLV
  • Customer Choice

Type of change

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

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

Copy link
Contributor

Choose a reason for hiding this comment

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

How about defining the types a bit more

class Constraint: 
    key: str
    constraint_type: Literal["eq", ...]
    sym_fun: Callable[[], pt.TensorVariable]
    sym_jac: Callable[[], pt.TensorVariable]
    
# Then can use like
constraints: list[Constraint] = [...]

Otherwise, functions like compile_constraints_for_scipy are quite hard to read

Copy link
Contributor

Choose a reason for hiding this comment

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

sym_jac won't stay if it's still there btw

Copy link

codecov bot commented Jan 8, 2025

Codecov Report

Attention: Patch coverage is 19.72789% with 118 lines in your changes missing coverage. Please review.

Project coverage is 54.96%. Comparing base (7dfa955) to head (17c86f1).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
pymc_marketing/mmm/budget_optimizer.py 18.09% 86 Missing ⚠️
pymc_marketing/mmm/constraints.py 25.80% 23 Missing ⚠️
pymc_marketing/mmm/mmm.py 18.18% 9 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (7dfa955) and HEAD (17c86f1). Click for more details.

HEAD has 6 uploads less than BASE
Flag BASE (7dfa955) HEAD (17c86f1)
11 5
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1358       +/-   ##
===========================================
- Coverage   95.31%   54.96%   -40.36%     
===========================================
  Files          47       48        +1     
  Lines        4912     5007       +95     
===========================================
- Hits         4682     2752     -1930     
- Misses        230     2255     +2025     

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

@wd60622 wd60622 changed the title Custom constraints Custom optimizer constraints Jan 8, 2025
@wd60622
Copy link
Contributor

wd60622 commented Jan 8, 2025

Where there any closing issues for this?

@ricardoV94 ricardoV94 force-pushed the custom_constraints_refactor branch from 5e5c73a to 02ce740 Compare January 9, 2025 19:27
@ricardoV94 ricardoV94 force-pushed the custom_constraints_refactor branch from aeeb060 to 17c86f1 Compare January 13, 2025 17:10
@ricardoV94
Copy link
Contributor

The changes are so big that we probably will just skip #1357 to keep our sanity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Making optimizer pymc model agnostic
3 participants