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

Add jitter_scale parameter for initial point generation #7643

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

aphc14
Copy link

@aphc14 aphc14 commented Jan 13, 2025

Description

Add jitter_scale parameter to control the bounds of uniform jitter in initial points. This allows users to adjust the width of random initialisation, which is useful for the Multi-path Pathfinder algorithm to explore posteriors in a larger parameter space or where the posterior mean is much further away from the prior mean.

Changes:

  • Add jitter_scale parameter (default=1.0) to initial point functions
  • Update jitter bounds from U(-1,1) to U(-jitter_scale, jitter_scale)
  • Add test_jitter_scale to verify scaling behaviour
  • Update docstrings to reflect new parameter

Related Issue

Checklist

Type of change

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

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

Copy link

welcome bot commented Jan 13, 2025

Thank You Banner]
💖 Thanks for opening this pull request! 💖 The PyMC community really appreciates your time and effort to contribute to the project. Please make sure you have read our Contributing Guidelines and filled in our pull request template to the best of your ability.

@@ -66,6 +66,7 @@ def make_initial_point_fns_per_chain(
model,
overrides: StartDict | Sequence[StartDict | None] | None,
jitter_rvs: set[TensorVariable] | None = None,
jitter_scale: float = 1.0,
Copy link
Member

Choose a reason for hiding this comment

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

Need to update the docstrings of the function that now accept jitter_scale

@@ -152,6 +152,34 @@ def test_adds_jitter(self):
assert fn(0) == fn(0)
assert fn(0) != fn(1)

def test_jitter_scale(self):
Copy link
Member

Choose a reason for hiding this comment

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

Can you simplify this test? If you test the default 1.0 jitter and a very large amount like 1000.0 a single draw should be enough to test the change.

Copy link
Author

Choose a reason for hiding this comment

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

Would I need to test if the large jitters are close to +- 1000? If so, what if the single draw for the large jitter is +/- 80? I'm not sure how to test if the jitter_scale is correct without making many draws.

Copy link
Member

@ricardoV94 ricardoV94 Jan 13, 2025

Choose a reason for hiding this comment

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

The large jitter should be >> 10 in magnitude, with p=1-(10/1000)=0.99, whereas with default jitter should be smaller than 1, with p=1


assert np.all((-0.05 < init_standardised) & (init_standardised < 0.05))
assert fn_large(0)["A_log__"] > fn_default(0)["A_log__"]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assert fn_large(0)["A_log__"] > fn_default(0)["A_log__"]
assert fn_large(0)["A_log__"] > 10
assert fn_default(0)["A_log__"] < 1

Copy link
Member

Choose a reason for hiding this comment

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

Or if 10 is too large, something smaller

@ricardoV94 ricardoV94 changed the title ENH: Add jitter_scale parameter for initial point generation (#7555) Add jitter_scale parameter for initial point generation Jan 15, 2025
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.

ENH: Option to adjust the uniform distribution bounds for jitter/initialisation
2 participants