-
Notifications
You must be signed in to change notification settings - Fork 168
Implementing and Testing Jacobian Functions in Stingray in models.py
#898
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
kashish2210
wants to merge
6
commits into
StingraySoftware:main
Choose a base branch
from
kashish2210:jacobian
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for further testing with some complications:testing code:# Define test values
x = np.logspace(-2, 2, 100)
# Parameters for GeneralizedLorentz1D
x_0 = 1.0
fwhm = 1.0
value = 1.0
power_coeff = 2.0
# Parameters for SmoothBrokenPowerLaw
norm = 1.0
gamma_low = 1.0
gamma_high = 2.0
break_freq = 1.0
# Compute Jacobians using provided functions
jac_lorentz = GeneralizedLorentz1DJacobian(x, x_0, fwhm, value, power_coeff)
jac_smooth_bkn_po = SmoothBrokenPowerLawJacobian(x, norm, gamma_low, gamma_high, break_freq)
# Plot Jacobians
fig, ax = plt.subplots(figsize=(10, 5))
ax.loglog(x, np.abs(jac_lorentz[:, 0]), label='d/dx_0 (Lorentz)', linestyle='dashed')
ax.loglog(x, np.abs(jac_lorentz[:, 1]), label='d/dFWHM (Lorentz)', linestyle='dotted')
ax.loglog(x, np.abs(jac_lorentz[:, 2]), label='d/dValue (Lorentz)', linestyle='dashdot')
ax.loglog(x, np.abs(jac_lorentz[:, 3]), label='d/dPowerCoeff (Lorentz)', linestyle='solid')
ax.loglog(x, np.abs(jac_smooth_bkn_po[:, 0]), label='d/dNorm (Smooth BPL)', linestyle='dashed', color='red')
ax.loglog(x, np.abs(jac_smooth_bkn_po[:, 1]), label='d/dGammaLow (Smooth BPL)', linestyle='dotted', color='green')
ax.loglog(x, np.abs(jac_smooth_bkn_po[:, 2]), label='d/dGammaHigh (Smooth BPL)', linestyle='dashdot', color='purple')
ax.loglog(x, np.abs(jac_smooth_bkn_po[:, 3]), label='d/dBreakFreq (Smooth BPL)', linestyle='solid', color='brown')
ax.set_xlabel('Frequency (x)')
ax.set_ylabel('Jacobian Values (Absolute)')
ax.legend()
ax.set_title('Jacobian Values for Generalized Lorentzian and Smooth Broken Power Law')
ax.grid(True, which='both', linestyle='--', linewidth=0.5)
plt.show()
# Print Jacobian values for verification
print("Jacobian for Generalized Lorentzian (first few values):\n", jac_lorentz[:5])
print("Jacobian for Smooth Broken Power Law (first few values):\n", jac_smooth_bkn_po[:5])
output:
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #898 +/- ##
==========================================
- Coverage 96.03% 94.09% -1.95%
==========================================
Files 48 48
Lines 9770 9788 +18
==========================================
- Hits 9383 9210 -173
- Misses 387 578 +191 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Contribution: Implementing and Testing Jacobian Functions in Stingray
Overview
This contribution implements and tests the Jacobian functions for
GeneralizedLorentzianJacobian
andSmoothBrokenPowerLawJacobian
instingray/simulator/models.py
. These were listed as TODO and have now been completed and verified with test plots.Implemented Functions
The following Jacobian functions were added:
[file_change]
Testing and Verification
The functions were tested using the following code to ensure correctness and visualize the Jacobian components.
Results
Helper_Notes:
@custom_model
fromastropy.modeling.Model
and found an errorWhy Not Use
@custom_model
?This contribution addresses @matteobachetti's
# TODO: Add Jacobian
instingray/simulator/models.py
by implementing and testing the required Jacobian functions. The code has been validated with test plots demonstrating correct behavior.guide me for my workflow: