Skip to content

Added GeneralizedLorentz1D and SmoothBrokenPowerLaw classes to stingray.simulator.models. #889

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

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

Conversation

ankitkhushwaha
Copy link
Contributor

@ankitkhushwaha ankitkhushwaha commented Feb 24, 2025

TODO:

  • added the GeneralizedLorentz1D and SmoothBrokenPowerLaw, to stingray.simulator.models.
  • added test for new classes
  • added changelog

i have confirmed that jacobian for function with respect to each parameter is correct using sympy

@matteobachetti

@ankitkhushwaha ankitkhushwaha marked this pull request as draft February 24, 2025 12:24
@ankitkhushwaha ankitkhushwaha force-pushed the jacob branch 3 times, most recently from 85f0175 to 8026b67 Compare February 25, 2025 12:25
@ankitkhushwaha ankitkhushwaha marked this pull request as ready for review February 25, 2025 12:27
@ankitkhushwaha
Copy link
Contributor Author

ankitkhushwaha commented Feb 25, 2025

I think changes are ready for review.
@matteobachetti

@matteobachetti
Copy link
Member

@ankitkhushwaha thanks for your PR. However, I haven't noticed any tests failing, there are no issues open about it as far as I can tell. Could you be clearer about what is failing, and what your changes do?

@ankitkhushwaha
Copy link
Contributor Author

ankitkhushwaha commented Feb 25, 2025

@matteobachetti
in the first commit. Function GeneralizedLorentz1D, SmoothBrokenPowerLaw was returning the jacobian and function output as tuple. that's why some test are falling.

these test are fixed now.

TODO:
I have added the Jacobian functionality for GeneralizedLorentz1D, SmoothBrokenPowerLaw which will compute the derivative of their function with respective to each parameter.

Copy link

codecov bot commented Mar 4, 2025

Codecov Report

Attention: Patch coverage is 92.22222% with 7 lines in your changes missing coverage. Please review.

Project coverage is 82.70%. Comparing base (c432bd2) to head (a1715ea).

Files with missing lines Patch % Lines
stingray/simulator/models.py 92.22% 7 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (c432bd2) and HEAD (a1715ea). Click for more details.

HEAD has 10 uploads less than BASE
Flag BASE (c432bd2) HEAD (a1715ea)
16 6
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #889       +/-   ##
===========================================
- Coverage   96.04%   82.70%   -13.34%     
===========================================
  Files          48       48               
  Lines        9789     9871       +82     
===========================================
- Hits         9402     8164     -1238     
- Misses        387     1707     +1320     

☔ 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.

@ankitkhushwaha
Copy link
Contributor Author

Hey @matteobachetti, mostly this pr is ready to be reviewed, could you review this.
more tests needs to added that i will add in upcoming commits.

@ankitkhushwaha
Copy link
Contributor Author

Hey @matteobachetti , all TODO are completed.
you can take a look at it.
Thanks!

@ankitkhushwaha ankitkhushwaha changed the title Add Jacobian to GeneralizedLorentz1D, SmoothBrokenPowerLaw in stingray.simulator.models Added GeneralizedLorentz1D and SmoothBrokenPowerLaw classes to stingray.simulator.models. Apr 12, 2025
@matteobachetti
Copy link
Member

@ankitkhushwaha just to clarify: have you suppressed the use of the derivative in all model fits? A lot of lines seem not to be covered by tests


data = model_with_deriv(x) + n
fitter_with_deriv = fitting.LevMarLSQFitter()
new_model_with_deriv = fitter_with_deriv(model_with_deriv, x, data)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

under the hood this tests exeutes the fit_deriv method see
https://docs.astropy.org/en/stable/api/astropy.modeling.fitting.LevMarLSQFitter.html -> estimate_jacobian

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i have seen these types of tests in astropy codebase
so i implemented this

Copy link
Member

Choose a reason for hiding this comment

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

What I mean is that codecov is showing a lot of code not being executed during tests, including, e.g., the fit_deriv and bounding_box methods of GeneralizedLorentz1D (and even fewer methods of the broken power law model). I don't know why, it might be a bug of codecov, but I suggest to verify that all code is actually executed

@pytest.mark.parametrize(
"model, x_lim",
[
(models.SmoothBrokenPowerLaw(1, -2, 2, 10), [0.01, 70]),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

also if the boundaries are too much large ex [0.01, 100]
the fitter in its internal calculaltion produces infinity. and fitting fails

so i changed boundaries to [0.01, 70]

----------
factor : float
The multiple of FWHM used to define the limits.
Default is chosen to include most (99%) of the
Copy link
Member

Choose a reason for hiding this comment

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

25 times the fwhm seems a lot more than 99%?


data = model_with_deriv(x) + n
fitter_with_deriv = fitting.LevMarLSQFitter()
new_model_with_deriv = fitter_with_deriv(model_with_deriv, x, data)
Copy link
Member

Choose a reason for hiding this comment

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

What I mean is that codecov is showing a lot of code not being executed during tests, including, e.g., the fit_deriv and bounding_box methods of GeneralizedLorentz1D (and even fewer methods of the broken power law model). I don't know why, it might be a bug of codecov, but I suggest to verify that all code is actually executed

@ankitkhushwaha
Copy link
Contributor Author

will surely check it if lines are being tested or not.

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

Successfully merging this pull request may close these issues.

2 participants