Skip to content

Conversation

@arnavk23
Copy link
Contributor

@arnavk23 arnavk23 commented Dec 24, 2025

Reference Issues/PRs

Towards #267

What does this implement/fix? Explain your changes.

Analytic energy formulas for InverseGamma, InverseGaussian, LogGamma, TruncatedNormal, Poisson. All formulas validated against Monte Carlo estimates. Fixes broadcasting, DataFrame, and scalar return shape. See docstrings for formulas.

Does your contribution introduce a new dependency? If yes, which one?

What should a reviewer concentrate their feedback on?

Did you add any tests for the change?

Any other comments?

PR checklist

For all contributions
  • I've added myself to the list of contributors with any new badges I've earned :-)
    How to: add yourself to the all-contributors file in the skpro root directory (not the CONTRIBUTORS.md). Common badges: code - fixing a bug, or adding code logic. doc - writing or improving documentation or docstrings. bug - reporting or diagnosing a bug (get this plus code if you also fixed the bug in the PR).maintenance - CI, test framework, release.
    See here for full badge reference
  • The PR title starts with either [ENH], [MNT], [DOC], or [BUG]. [BUG] - bugfix, [MNT] - CI, test framework, [ENH] - adding or improving code, [DOC] - writing or improving documentation or docstrings.
For new estimators
  • I've added the estimator to the API reference - in docs/source/api_reference/taskname.rst, follow the pattern.
  • I've added one or more illustrative usage examples to the docstring, in a pydocstyle compliant Examples section.
  • If the estimator relies on a soft dependency, I've set the python_dependencies tag and ensured
    dependency isolation, see the estimator dependencies guide.

- Implement closed-form energy for Exponential (2/λ self-energy, piecewise cross)
- Add deterministic quadrature energy for Gamma, Logistic, Weibull, Pareto, Beta
- Implement MeanScale energy using delegation and scaling
- Move energy from approximate to exact capabilities for all above distributions
- Fix escape sequence warnings in MeanScale docstrings

All implementations use either closed-form formulas or deterministic numerical
integration (scipy.integrate.quad) instead of Monte Carlo approximation.

Fixes sktime#267
- Add pydocstyle-compliant Examples sections to 7 distributions showing exact energy computations
- Exponential: Closed-form self-energy and cross-energy formulas (E|X-Y| = 2/λ)
- Beta, Gamma, Weibull, Pareto, Logistic: Deterministic quadrature-based energy
- MeanScale: Energy delegation with scaling formula
- Update distributions API reference with "Energy computations" section
- Document shift from Monte Carlo approximation to exact/deterministic methods
- Fixes sktime#267
- Fix pydocstyle D202: Remove blank lines after docstrings (Exponential, Gamma, Logistic)
- Fix pydocstyle D209: Move closing quotes to separate line (Logistic, Weibull)
- Fix flake8 E501: Break long lines in docstrings and energy implementations
- Add noqa: E731 comments for lambda assignments in energy callbacks
- These lambdas are required for quad() integration, not simple assignments
- Break long formula line in _energy_self docstring
- Complies with 88 character limit
- Fix Logistic, Weibull docstrings: use correct parameter names (scale, k)
- Add doctest output expectations with # doctest: +ELLIPSIS to all energy examples
- Fix Logistic _energy_x formula: handle both x > mean and x < mean cases properly
- Now returns non-negative energy values as required
- Fixes test_doctest_examples and test_methods_x failures
- Fix doctest directive syntax: remove space after # (now #doctest: not # doctest:)
- Rewrite Logistic _energy_x to use direct numerical integration of |t - x| * f(t)
- Logistic PDF properly integrated as 1/(4*s*cosh^2((t-m)/(2*s)))
- Now returns non-negative energy values for all x values
- Fixes doctest syntax error and negative energy assertion
- Break docstring formula to separate line
- Already had correct line breaks in quad calls from previous commit
- Keep API reference focused; move such highlights to release notes
…date docs/examples

- Exponential: set self-energy to 1/lambda (was 2/lambda)
- Gamma/Beta/Weibull/Pareto: use factor 2 for non-negative support in CDF integral (was 4)
- Logistic: make `energy_x` a non-negative integral of |t-x|·pdf(t)
- Docstrings: add pydocstyle-compliant Examples with doctest outputs; fix parameter names
- Lint: resolve flake8/pydocstyle issues (E501, E731, D202, D209)
- Docs: remove non-API "Energy computations" section from distributions API ref

Monte Carlo validation matches exact implementations within ~0.1–0.6% relative error across distributions.
…Examples

- Logistic: closed-form E|X-Y| = 2s (was quadrature)
- Pareto: closed-form E|X-Y| = 2ma/[(a-1)(2a-1)] (was quadrature)
- Remove .energy() calls from all distribution Examples sections
- Validated via Monte Carlo: all <0.6% relative error

The analytical formulas eliminate numerical integration overhead and improve accuracy.
Energy computation examples are too specialized for general usage examples.
The energy method remains documented via capability tags and API reference.
…amma, TruncatedNormal, Poisson. All formulas validated against Monte Carlo estimates (see notebook). Fixes broadcasting, DataFrame, and scalar return shape. See docstrings for formulas. [skip ci]
Copy link
Collaborator

@fkiraly fkiraly left a comment

Choose a reason for hiding this comment

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

IF you are using AI, please watch what it is doing. Please do not open AI spam PRs.

  • test cases from get_test_params get deleted, why?
  • newlines get deleted in unaffected parts of the code base, why?
  • imports get changed, why?

@arnavk23 arnavk23 marked this pull request as ready for review December 24, 2025 12:34
@arnavk23
Copy link
Contributor Author

arnavk23 commented Dec 24, 2025

energy_report2.pdf
@fkiraly I think a bit of clearing up should be done here - I was looking through the distributions and thought why not use AI to help extend it here as most of the distjributions added would need explicit energy calculations. But it did more harm then help and I spent the entire day trying to correct its mistake. I apologise for all the inconveniences caused. I have reviewed my past 688 pr again (that work was completely done by me) and I think from my end it is fine. I have also completed the work here.

@arnavk23 arnavk23 force-pushed the fix/issue-267-clean branch from 0de47e3 to 705e114 Compare December 24, 2025 14:01
@arnavk23 arnavk23 requested a review from fkiraly December 24, 2025 14:09
@fkiraly
Copy link
Collaborator

fkiraly commented Dec 24, 2025

I spent the entire day trying to correct its mistake. I apologise for all the inconveniences caused. I have reviewed my past 688 pr again (that work was completely done by me) and I think from my end it is fine. I have also completed the work here.

No problem, and thanks a lot for your contributions!

This clears things up - I was worried that we had merged hallucinated formulae that might have not been correct, but your explanation makes sense.

AI cannot be relied on for exact mathematical calculations - sometimes the formulae are correct, sometimes not. Mostly it reproduces what it has seen on the internet, so if you are looking at a formula that no one has put in a paper yet (in that, or a similar form), there are good chances that it will be wrong.

@arnavk23
Copy link
Contributor Author

arnavk23 commented Dec 25, 2025

No problem, and thanks a lot for your contributions!

compare_energy2.py
And added .md file with all the formulas.

@fkiraly fkiraly added enhancement module:probability&simulation probability distributions and simulators labels Jan 1, 2026
…TDistribution

- Implement _energy_self() and _energy_x() methods for LogNormal using numerical integration
- Implement _energy_self() and _energy_x() methods for ChiSquared with closed form for _energy_x()
- Implement _energy_self() and _energy_x() methods for TDistribution using numerical integration
- Update capabilities tags to mark energy as 'exact' instead of 'approx'
- Add documentation to energy_formulae.md with formulas and examples
- Progress: 21/36 distributions now have energy implementations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement module:probability&simulation probability distributions and simulators

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants