-
Notifications
You must be signed in to change notification settings - Fork 0
Experimental weighting #2
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
Conversation
…impacts chi squared
Migrating some of the discussion here for future reference:
expt.linked_phases.add("phase1", scale=0.5)
expt.linked_phases.add("phase2", scale=1.3)
analysis.fit_mode = "joint"
analysis.joint_fit.add("expt1", weight=0.4) # Default weight could be 0.5
analysis.joint_fit.add("expt2", weight=0.6) # Default weight could be 0.5
analysis.joint_fit["expt1"].weight = 0.4
analysis.joint_fit["expt2"].weight = 0.6
|
By @elindgren
For reference, we decided that the sum of weights should sum up to the number of experiments. This ensures that one retrieves the same reduced chi_squared when fitting a dataset as when splitting the dataset in two parts and fitting the two parts together. |
|
||
# Compare fit quality | ||
assert_almost_equal(project.analysis.fit_results.reduced_chi_square, 21.1, decimal=1) | ||
assert_almost_equal(project.analysis.fit_results.reduced_chi_square, 14.4, decimal=1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that I had to adjust the expected chi_squared after changing the target sum of weights.
|
||
# Run the fitting process | ||
experiment_ids = list(experiments._items.keys()) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the line above should also reuse the new experiments.ids
property
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks!
Two comments for now:
|
@AndrewSazonov I've implemented the two points we discussed yesterday. |
It works as expected in terms of the resulting chi2 values. Thank you @elindgren for implementing this. One minor API detail. The correct way to update experiment weights should be:
instead of:
But, since I’m currently working on significant changes in the fix-output branch, I suggest we go ahead and merge this PR, and I’ll handle the adjustment there. |
ah okay, I missed that! Sounds good, I'll merge then |
Adds a weighting parameter "weight" to an Experiment.
The residuals are weighted by a weighting factor. Note that this means that the contribution to chi_squared is weighted by a factor of weight**2.
Skipping error handling for now, ideally the joint_fit object should be converted to a Python object that validates the weights etc. But let's not get ahead of ourselves.
Fixes #5