Skip to content

128 write a guide for the new prior and naming system#129

Open
kazewong wants to merge 33 commits intojim-devfrom
128-write-a-guide-for-the-new-prior-and-naming-system
Open

128 write a guide for the new prior and naming system#129
kazewong wants to merge 33 commits intojim-devfrom
128-write-a-guide-for-the-new-prior-and-naming-system

Conversation

@kazewong
Copy link
Owner

@kazewong kazewong commented Aug 6, 2024

Starting to construct the guide for the new prior system. @xuyuon @thomasckng Feel free to add sections to this branch

Summary by CodeRabbit

  • Documentation
    • Introduced a comprehensive guide that explains parameter transformation processes with practical examples and visual aids.
    • Enhanced documentation rendering with advanced mathematical typesetting capabilities.
  • New Features
    • Expanded support for flexible sampling workflows through enhanced parameter transformation options.
    • Added new prior classes: UniformPrior, SinePrior, CosinePrior, PowerLawPrior, CombinePrior, and GaussianPrior.
    • Introduced new transformation classes: SineTransform and CosineTransform.
  • Bug Fixes
    • Resolved issues in prior and transformation logic to improve accuracy and performance.
  • Tests
    • Enhanced test suite for prior distributions, incorporating JAX functionality for improved performance and stability.

@thomasckng thomasckng changed the base branch from 98-moving-naming-tracking-into-jim-class-from-prior-class to jim-dev September 3, 2024 00:39
Base automatically changed from jim-dev to main October 17, 2024 18:34
@thomasckng thomasckng added the documentation Improvements or additions to documentation label Mar 4, 2025
@kazewong kazewong linked an issue Mar 4, 2025 that may be closed by this pull request
@coderabbitai
Copy link

coderabbitai bot commented Mar 4, 2025

Walkthrough

The pull request introduces a comprehensive tutorial document that explains Jim’s parameter transformation system. The document details the relationships between the prior, sampler, and model parameterizations, including practical examples and visual aids. New classes for various priors and transformation processes have been added to the codebase, expanding the system’s functionality. Additionally, the documentation configuration has been updated to include JavaScript entries for MathJax support, enhancing the rendering of mathematical expressions.

Changes

File(s) Change Summary
docs/tutorials/prior_system.md Added a new tutorial guide detailing Jim’s parameter transform system with examples, diagrams, and explanations on parameterization and sampling.
src/jimgw/prior.py (UniformPrior, SinePrior, CosinePrior, PowerLawPrior, GaussianPrior) Introduced new prior classes and modified existing ones to enhance parameter transformation logic.
src/jimgw/transforms.py (SineTransform, CosineTransform) Renamed and added new transformation classes, updating transformation logic and removing the ParetoTransform.
src/jimgw/constants.py Added new physical constants and simplified calculations related to Mpc.
mkdocs.yml Updated the configuration to add local and external JavaScript files for MathJax, enabling advanced mathematical typesetting in the documentation.
src/jimgw/single_event/utils.py Updated the calculation of v0 to use MTSUN instead of Msun.
test/unit/test_prior.py Enhanced tests for various prior distributions, adding JAX functionality and restructuring tests for clarity and performance.

Suggested reviewers

  • tsunhopang
  • CharmaineWONG2

Poem

I'm a rabbit hopping with delight,
Through lines of code by day and night.
Priors and transforms dance in a neat array,
With each new change, I cheer and say,
"Carrots and code, what a wonderful sight!" 🥕

✨ Finishing Touches
  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (8)
docs/tutorials/prior_system.md (8)

1-1: Revise the document title for grammatical clarity.
The current title “# Jim's parameter transform system” uses “transform” as a noun, which may be unclear. Consider changing it to “# Jim's Parameter Transformation System” for clarity and consistency.

🧰 Tools
🪛 LanguageTool

[grammar] ~1-~1: There seems to be a noun/verb agreement error. Did you mean “transforms” or “transformed”?
Context: # Jim's parameter transform system !!! warning **Heavy develop...

(SINGULAR_NOUN_VERB_AGREEMENT)


8-8: Add missing punctuation for clarity.
In the sentence on line 8 describing the common prior, a comma after “minimum mass” would help clarify the point. For example:
"... with some maximum and minimum mass, one may want to define ..."

🧰 Tools
🪛 LanguageTool

[uncategorized] ~8-~8: Possible missing comma found.
Context: ...choice is uniform in the component mass space with some maximum and minimum mass. One...

(AI_HYDRA_LEO_MISSING_COMMA)


10-10: Ensure term consistency for describing parameter sets.
The document switches between “parametrization” and “parameterization.” It is recommended to choose one variant (e.g. “parameterization”) and use it consistently throughout the text.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~10-~10: Do not mix variants of the same word (‘parametrization’ and ‘parameterization’) within a single text.
Context: ...l setting, there could be three sets of parametrizations we can choose for our problem: a parame...

(EN_WORD_COHERENCY)


17-17: Simplify verbose phrasing in transformation explanation.
The phrase “transform the prior to the space z using a transform” is a bit wordy. Consider rephrasing it to something like “map the intuitive prior into the z space” to improve clarity and brevity.

🧰 Tools
🪛 LanguageTool

[style] ~17-~17: ‘prior to’ might be wordy. Consider a shorter alternative.
Context: ...t is more intuitive, then transform the prior to the space z using a transform. By c...

(EN_WORDINESS_PREMIUM_PRIOR_TO)


19-19: Streamline expression regarding bijective transforms.
Consider rephrasing “in order to make the prior-to-sample transform work in practice” to a more concise version such as “to ensure the transform works in practice.”

🧰 Tools
🪛 LanguageTool

[style] ~19-~19: Consider a shorter alternative to avoid wordiness.
Context: ...le space z to the prior space $x$. So in order to make the prior-to-sample transform work...

(IN_ORDER_TO_PREMIUM)


44-45: Standardize compound adjective spelling.
The section header “## Multi-dimensional Priors” appears to use a hyphenated form, yet style guides generally prefer “Multidimensional Priors” as a single compound word. Consider updating for consistency.

🧰 Tools
🪛 LanguageTool

[misspelling] ~44-~44: This word is normally spelled as one.
Context: ...documentation (not available yet). ### Multi-dimensional Priors When working with multi-dimensio...

(EN_COMPOUNDS_MULTI_DIMENSIONAL)


[misspelling] ~45-~45: This word is normally spelled as one.
Context: ...ti-dimensional Priors When working with multi-dimensional parameter space, we will usually want t...

(EN_COMPOUNDS_MULTI_DIMENSIONAL)


68-68: Ensure consistency in naming parameter sets.
The bullet point beginning “In general, there could be three sets of parametrizations…” again mixes “parametrizations” with “parameterizations.” Please pick one term (preferably “parameterizations”) and apply it uniformly throughout the document.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~68-~68: Do not mix variants of the same word (‘parametrization’ and ‘parameterization’) within a single text.
Context: ...n general, there could be three sets of parametrizations we need to work with in our problem: 1...

(EN_WORD_COHERENCY)


31-127: Specify language identifiers for fenced code blocks.
Several fenced code blocks (e.g., around lines 31, 47, 55, 91, 104, and 122) are missing language specifiers. Adding the appropriate language (such as python or bash) improves syntax highlighting and complies with markdownlint standards.

Example for a Python code block:

-```
+```python
🧰 Tools
🪛 LanguageTool

[misspelling] ~44-~44: This word is normally spelled as one.
Context: ...documentation (not available yet). ### Multi-dimensional Priors When working with multi-dimensio...

(EN_COMPOUNDS_MULTI_DIMENSIONAL)


[misspelling] ~45-~45: This word is normally spelled as one.
Context: ...ti-dimensional Priors When working with multi-dimensional parameter space, we will usually want t...

(EN_COMPOUNDS_MULTI_DIMENSIONAL)


[uncategorized] ~68-~68: Do not mix variants of the same word (‘parametrization’ and ‘parameterization’) within a single text.
Context: ...n general, there could be three sets of parametrizations we need to work with in our problem: 1...

(EN_WORD_COHERENCY)

🪛 markdownlint-cli2 (0.17.2)

31-31: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


47-47: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


55-55: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


91-91: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


104-104: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


122-122: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 54f2db5 and f5b9630.

⛔ Files ignored due to path filters (4)
  • docs/tutorials/likelihood_transform.png is excluded by !**/*.png
  • docs/tutorials/prior_system.jpg is excluded by !**/*.jpg
  • docs/tutorials/prior_system_diagram.png is excluded by !**/*.png
  • docs/tutorials/sample_transform.png is excluded by !**/*.png
📒 Files selected for processing (2)
  • docs/tutorials/prior_system.md (1 hunks)
  • mkdocs.yml (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/tutorials/prior_system.md

[grammar] ~1-~1: There seems to be a noun/verb agreement error. Did you mean “transforms” or “transformed”?
Context: # Jim's parameter transform system !!! warning **Heavy develop...

(SINGULAR_NOUN_VERB_AGREEMENT)


[uncategorized] ~8-~8: Possible missing comma found.
Context: ...choice is uniform in the component mass space with some maximum and minimum mass. One...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~10-~10: Do not mix variants of the same word (‘parametrization’ and ‘parameterization’) within a single text.
Context: ...l setting, there could be three sets of parametrizations we can choose for our problem: a parame...

(EN_WORD_COHERENCY)


[style] ~17-~17: ‘prior to’ might be wordy. Consider a shorter alternative.
Context: ...t is more intuitive, then transform the prior to the space z using a transform. By c...

(EN_WORDINESS_PREMIUM_PRIOR_TO)


[style] ~19-~19: Consider a shorter alternative to avoid wordiness.
Context: ...le space z to the prior space $x$. So in order to make the prior-to-sample transform work...

(IN_ORDER_TO_PREMIUM)


[typographical] ~21-~21: Two consecutive dots
Context: ... there is no limitation on the transform.. So the transform for the likelihood is ...

(DOUBLE_PUNCTUATION)


[misspelling] ~21-~21: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...ot need to be bijective, it can even by a N-to-M transform. # Prior ## Primativ...

(EN_A_VS_AN)


[misspelling] ~44-~44: This word is normally spelled as one.
Context: ...documentation (not available yet). ### Multi-dimensional Priors When working with multi-dimensio...

(EN_COMPOUNDS_MULTI_DIMENSIONAL)


[misspelling] ~45-~45: This word is normally spelled as one.
Context: ...ti-dimensional Priors When working with multi-dimensional parameter space, we will usually want t...

(EN_COMPOUNDS_MULTI_DIMENSIONAL)


[uncategorized] ~68-~68: Do not mix variants of the same word (‘parametrization’ and ‘parameterization’) within a single text.
Context: ...n general, there could be three sets of parametrizations we need to work with in our problem: 1...

(EN_WORD_COHERENCY)

🪛 markdownlint-cli2 (0.17.2)
docs/tutorials/prior_system.md

31-31: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


47-47: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


55-55: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


91-91: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


104-104: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


122-122: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

🪛 YAMLlint (1.35.1)
mkdocs.yml

[warning] 46-46: wrong indentation: expected 4 but found 2

(indentation)

Comment on lines +45 to +48
extra_javascript:
- javascripts/mathjax.js
- https://unpkg.com/mathjax@3/es5/tex-mml-chtml.js

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix YAML indentation for extra_javascript entries.
The static analysis indicates that list items under extra_javascript should be indented 4 spaces rather than 2. This will ensure proper YAML formatting and prevent linting issues.

Proposed diff:

-extra_javascript:
-  - javascripts/mathjax.js
-  - https://unpkg.com/mathjax@3/es5/tex-mml-chtml.js
+extra_javascript:
+    - javascripts/mathjax.js
+    - https://unpkg.com/mathjax@3/es5/tex-mml-chtml.js
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
extra_javascript:
- javascripts/mathjax.js
- https://unpkg.com/mathjax@3/es5/tex-mml-chtml.js
extra_javascript:
- javascripts/mathjax.js
- https://unpkg.com/mathjax@3/es5/tex-mml-chtml.js
🧰 Tools
🪛 YAMLlint (1.35.1)

[warning] 46-46: wrong indentation: expected 4 but found 2

(indentation)


By carrying the Jacobian of the transform, we can define the prior in the space `z` by transforming the prior in the intuitive space, $p_Z(z) = p_X(x) \left| \frac{dx}{dz} \right|$, where $x = t_2(z)$. The tricky bit here is the user often wants to start from the prior $x$ and define the transform **to** the sample space `z`, but here the transform is defined **from** the sample space `z` to the prior space $x$. So in order to make the prior-to-sample transform work in practice, the transform has to be **bijective**, which implies they are invertible and have a well-defined determinant of the Jacobian.

On the other hand, the likelihood is often related to a model instead of coming from a distribution, meaning as long as one can transform the parameters to feed into the model, there is no limitation on the transform.. So the transform for the likelihood is strictly from the sample space `z` to the model space $y = t_1(z)$. For this reason, the transform for the likelihood does not need to be bijective, it can even by a N-to-M transform.
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Correct punctuation and article usage.
There is an extra period after “transform” and a minor article error. Update the sentence to remove the double dot and change “a N-to-M transform” to “an N-to-M transform.”

Proposed diff:

-... there is no limitation on the transform.. So the transform for the likelihood does not need to be bijective, it can even by a N-to-M transform.
+... there is no limitation on the transform. So the transform for the likelihood does not need to be bijective, it can even be an N-to-M transform.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
On the other hand, the likelihood is often related to a model instead of coming from a distribution, meaning as long as one can transform the parameters to feed into the model, there is no limitation on the transform.. So the transform for the likelihood is strictly from the sample space `z` to the model space $y = t_1(z)$. For this reason, the transform for the likelihood does not need to be bijective, it can even by a N-to-M transform.
On the other hand, the likelihood is often related to a model instead of coming from a distribution, meaning as long as one can transform the parameters to feed into the model, there is no limitation on the transform. So the transform for the likelihood is strictly from the sample space `z` to the model space $y = t_1(z)$. For this reason, the transform for the likelihood does not need to be bijective, it can even be an N-to-M transform.
🧰 Tools
🪛 LanguageTool

[typographical] ~21-~21: Two consecutive dots
Context: ... there is no limitation on the transform.. So the transform for the likelihood is ...

(DOUBLE_PUNCTUATION)


[misspelling] ~21-~21: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...ot need to be bijective, it can even by a N-to-M transform. # Prior ## Primativ...

(EN_A_VS_AN)

@thomasckng thomasckng changed the base branch from main to jim-dev March 4, 2025 15:22
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
mkdocs.yml (1)

45-47: ⚠️ Potential issue

Fix YAML indentation for extra_javascript entries.

According to YAML linting rules, list items should be indented with 4 spaces rather than 2. This will ensure proper YAML formatting and prevent linting issues.

Apply this diff to correct the indentation:

extra_javascript:
-  - javascripts/mathjax.js
-  - https://unpkg.com/mathjax@3/es5/tex-mml-chtml.js
+    - javascripts/mathjax.js
+    - https://unpkg.com/mathjax@3/es5/tex-mml-chtml.js
🧰 Tools
🪛 YAMLlint (1.35.1)

[warning] 46-46: wrong indentation: expected 4 but found 2

(indentation)

🧹 Nitpick comments (1)
src/jimgw/prior.py (1)

278-321: Add unit tests and minor docstring improvements.
The GaussianPrior class implementation looks correct. However, it lacks direct test coverage. Also, the docstring's phrase “which scale and translate” can be improved grammatically to “which scales and translates.”

Would you like help writing a unit test to confirm that it samples from the correct mean and standard deviation?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f5b9630 and 8099db3.

📒 Files selected for processing (7)
  • mkdocs.yml (1 hunks)
  • src/jimgw/constants.py (1 hunks)
  • src/jimgw/prior.py (4 hunks)
  • src/jimgw/single_event/likelihood.py (1 hunks)
  • src/jimgw/single_event/utils.py (2 hunks)
  • src/jimgw/transforms.py (5 hunks)
  • test/unit/test_prior.py (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/jimgw/single_event/likelihood.py
🧰 Additional context used
🪛 YAMLlint (1.35.1)
mkdocs.yml

[warning] 46-46: wrong indentation: expected 4 but found 2

(indentation)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build (3.11)
  • GitHub Check: build (3.10)
  • GitHub Check: build (3.12)
  • GitHub Check: build (3.11)
🔇 Additional comments (21)
mkdocs.yml (1)

45-47: Good addition of MathJax support for mathematical expressions.

The addition of MathJax scripts will enable proper rendering of mathematical notation in the documentation, which is essential for a gravitational-wave inference toolkit. This aligns well with the new prior system tutorial being added in this PR.

🧰 Tools
🪛 YAMLlint (1.35.1)

[warning] 46-46: wrong indentation: expected 4 but found 2

(indentation)

src/jimgw/single_event/utils.py (2)

5-5: Consistent update to use the new constant naming convention.

The import has been updated to use MTSUN instead of Msun, aligning with the changes in the constants module. This is a good practice for maintaining consistency across the codebase.


502-502:

Details

✅ Verification successful

Proper migration to the new constant in physical calculation.

The calculation of v0 has been correctly updated to use MTSUN instead of Msun, maintaining the physical meaning while following the new constant naming convention.


🏁 Script executed:

#!/bin/bash
# Verify that all usages of Msun have been replaced with MTSUN in the codebase

# Check if there are any remaining references to the old Msun constant
echo "Checking for remaining references to Msun..."
rg "Msun" --no-filename | grep -v "MTSUN" || echo "No remaining references to Msun found."

# Check for all references to MTSUN to ensure consistency
echo "Checking for all references to MTSUN..."
rg "MTSUN" --no-filename

Length of output: 574


Migration to the new constant confirmed

The update to the calculation of v0 in src/jimgw/single_event/utils.py correctly uses MTSUN instead of Msun, preserving the intended physical meaning. The only remaining reference to a similar name appears in commented-out code (i.e., MsunInkg), which does not affect functionality.

src/jimgw/constants.py (3)

1-1: Simplified import statement.

The import has been correctly updated to only include pc from astropy.constants, removing the unused c import. This is a good practice for keeping imports clean and minimal.


4-14: Well-documented physical constants with precise values.

The addition of these four fundamental physical constants with clear docstrings improves code readability and maintainability. The precise values with high decimal precision ensure accurate calculations in gravitational wave physics.

The constants follow a consistent naming convention with clear units specified in the docstrings:

  • C_SI: Speed of light in m/s
  • MSUN: Nominal solar mass in kg
  • MTSUN: Geometrised nominal solar mass in seconds
  • MRSUN: Geometrised nominal solar mass in meters

17-17: Simplified calculation of Mpc.

The calculation of Mpc has been simplified by removing the division by c.value, which is consistent with the removal of the c import. The new calculation directly multiplies pc.value by 1e6 to convert from parsecs to megaparsecs.

test/unit/test_prior.py (7)

1-3: Added JAX dependency for enhanced testing capabilities.

The addition of JAX and its numpy module enables better testing of the prior distributions, particularly for checking jittability which is crucial for performance in a JAX-based toolkit.


4-13: Comprehensive import of all prior classes for testing.

The import statement has been updated to include all the prior distribution classes, including the newly added GaussianPrior. This ensures complete test coverage for all available prior distributions.


18-18: Enable 64-bit precision for numerical stability.

Setting jax_enable_x64 to True ensures that JAX operations are performed with 64-bit precision, which is crucial for numerical stability in scientific computations, especially those involving probability distributions.


36-40: Added jittability checks for LogisticDistribution.

Testing that the log_prob method can be JIT-compiled is an excellent addition. This ensures that the distribution will work efficiently with JAX's just-in-time compilation, which is crucial for performance in sampling applications.


56-60: Consistent JIT compilation tests across all distributions.

All prior distributions now have consistent tests for JIT compilation of their log_prob methods. This ensures that all distributions will work efficiently with JAX's acceleration capabilities and maintain numerical stability under compilation.

Also applies to: 79-83, 103-107, 126-130, 184-188, 210-214


146-182: Improved PowerLawPrior testing with comprehensive edge cases.

The tests for PowerLawPrior have been significantly enhanced to cover various alpha values, including the special case of alpha = -1.0. The test now directly verifies the log probability calculations against the expected analytical formulas for different ranges of alpha, which provides much stronger validation of correctness.


190-214: Complete test coverage for the new GaussianPrior class.

The addition of tests for the GaussianPrior class ensures that the new functionality is properly validated. The tests verify that samples and log probabilities are finite, that the log probability values match those from scipy.stats.norm, and that the log_prob method can be JIT-compiled.

src/jimgw/prior.py (3)

14-16: Imports look good.
The newly introduced imports for SineTransform and reverse_bijective_transform align with their usage in CosinePrior.


366-373: Validate domain assumptions.
Using reverse_bijective_transform(SineTransform(...)) effectively redefines the transform for CosinePrior. Ensure that the domain for the underlying sine transform ([-π/2, π/2]) is enforced or clearly documented, so invalid inputs don’t cause numerical issues.


433-441: PowerLawTransform usage looks correct.
Replacing conditional transforms with PowerLawTransform is coherent. Ensure that edge cases (e.g., alpha very close to -1.0) are properly tested, given the specialized handling in the transform’s logic.

src/jimgw/transforms.py (5)

90-92: Check for potential singularities.
Taking the log of the determinant here is fine, but ensure that transform_func is guaranteed to be invertible in all scenarios. Singular transforms can lead to infinities or NaNs.


129-131: Same determinant caution.
The inverse transform also computes the log determinant in the same manner. Validate numeric stability and handle singular transforms gracefully.


306-332: SineTransform implementation is precise.
The forward and inverse functions correctly use sine and arcsine. The domain [-π/2, π/2] is well-documented.


335-360: CosineTransform logic is consistent.
Using cosine and arccos elegantly covers the transformation in [0, π]. This matches the docstring stipulations.


503-541: Conditional logic for alpha = -1.0 appears correct.
The exponent-based transform is an appropriate special case. For alpha near -1.0 but not exact, consider whether small floating-point deviations could cause numerical instabilities.

@thomasckng thomasckng removed their assignment Oct 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Write a guide for the new prior and naming system

4 participants