fitting
NON_BUMPS_ERROR = "Inequality constraints (constraints_factory) require the BUMPS engine; the selected minimizer uses '{package}'."
module-attribute
_VALID_OBJECTIVES = ('legacy_mask', 'mighell', 'hybrid', 'auto')
module-attribute
_EPS = 1e-30
module-attribute
DataSet1D
Bases: SerializerComponent
Source code in src/easyreflectometry/data/data_store.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
model
property
writable
Model function.
is_experiment
property
Is experiment.
is_simulation
property
Is simulation.
__init__(name='Series', x=None, y=None, ye=None, xe=None, model=None, x_label='x', y_label='y', auto_background=True)
Init function.
Source code in src/easyreflectometry/data/data_store.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
data_points()
Data points.
Source code in src/easyreflectometry/data/data_store.py
85 86 87 | |
__repr__()
Repr function.
Source code in src/easyreflectometry/data/data_store.py
89 90 91 | |
PolarizedDataSet
A polarized experiment: one dataset per measured spin channel, one shared model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the experiment. By default, 'PolarizedSeries'. |
'PolarizedSeries'
|
channels
|
dict[PolarizationChannel | str, DataSet1D]
|
The measured channels; at least one. Keys are 'pp', 'pm', 'mp', 'mm' (or the corresponding enum members). Two-channel NSF-only experiments simply provide 'pp' and 'mm'. |
None
|
model
|
Model
|
The model shared by all channels. By default, None. |
None
|
Source code in src/easyreflectometry/data/polarized.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
model
property
writable
The model shared by all channels.
channels
property
The measured channels, in canonical order (pp, pm, mp, mm).
Read-only view: use :meth:set_channel / :meth:remove_channel to
modify the channel set, so validation and model propagation apply.
available_channels
property
The measured channels, in canonical order (pp, pm, mp, mm).
is_experiment
property
Is experiment.
is_simulation
property
Is simulation.
set_channel(channel, dataset)
Add or replace one channel dataset.
The dataset is validated, adopts the shared model, and the canonical channel order is preserved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channel
|
Union[PolarizationChannel, str]
|
One of 'pp', 'pm', 'mp', 'mm' (or the corresponding enum member). |
required |
dataset
|
DataSet1D
|
The channel data. |
required |
Source code in src/easyreflectometry/data/polarized.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
remove_channel(channel)
Remove one channel dataset; the last remaining channel cannot be removed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channel
|
Union[PolarizationChannel, str]
|
One of 'pp', 'pm', 'mp', 'mm' (or the corresponding enum member). |
required |
Source code in src/easyreflectometry/data/polarized.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
Model
Bases: BaseCore
Model is the class that represents the experiment.
It is used to store the information about the experiment and to perform the calculations.
Source code in src/easyreflectometry/model/model.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | |
total_thickness
property
Read-only parameter: the summed thickness of the film layers.
The superphase (first layer of the sample) and the subphase (last layer) are semi-infinite and excluded. The parameter is dependent: it tracks the layer thicknesses, never enters a fit and cannot be set; it can be referenced from constraint expressions and inequality constraints like any other parameter.
has_magnetism
property
Whether any layer in the sample carries magnetic properties.
is_default
property
writable
Whether this model was created as a default placeholder.
resolution_function
property
writable
Return the resolution function.
__init__(sample=None, scale=None, background=None, resolution_function=None, name='Model', color=COLORS[0], unique_name=None, interface=None)
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unique_name
|
Optional[str]
|
By default, None. |
None
|
color
|
str
|
By default, COLORS[0]. |
COLORS[0]
|
sample
|
Union[Sample, None]
|
The sample being modelled. By default, None. |
None
|
scale
|
Union[Parameter, Number, None]
|
Scaling factor of profile. By default, None. |
None
|
background
|
Union[Parameter, Number, None]
|
Linear background magnitude. By default, None. |
None
|
name
|
str
|
Name of the model. By default, 'Model'. |
'Model'
|
resolution_function
|
Union[ResolutionFunction, None]
|
Resolution function. By default, None. |
None
|
interface
|
Calculator interface. By default, None. |
None
|
Source code in src/easyreflectometry/model/model.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
interface(new_interface)
Set the interface; runs generate_bindings and then refreshes the
calculator's resolution function.
Source code in src/easyreflectometry/model/model.py
294 295 296 297 298 299 300 301 302 | |
refresh_derived()
Re-derive the model's computed parameters from the current layer structure.
Cheap (a few string operations) and idempotent: the dependency is
only rebuilt when the set of contributing layers changed. Called on
every access to :attr:total_thickness, so layers added or removed
through any path (Model.add_assemblies, assembly.layers.append,
...) are picked up without explicit notification.
Source code in src/easyreflectometry/model/model.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
add_assemblies(*assemblies)
Add assemblies to the model sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*assemblies
|
list[BaseAssembly]
|
Assemblies to add to model sample. |
()
|
Source code in src/easyreflectometry/model/model.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
duplicate_assembly(index)
Duplicate a given item or layer in a sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
|
required |
idx
|
Index of the item or layer to duplicate. |
required |
Source code in src/easyreflectometry/model/model.py
236 237 238 239 240 241 242 243 244 245 246 247 | |
remove_assembly(index)
Remove an assembly from the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
|
required |
idx
|
Index of the item to remove. |
required |
Source code in src/easyreflectometry/model/model.py
249 250 251 252 253 254 255 256 257 258 259 260 261 | |
to_dict(skip=None)
Serialize the model, encoding the resolution function and interface name.
Source code in src/easyreflectometry/model/model.py
327 328 329 330 331 332 333 334 335 336 337 338 339 340 | |
as_dict(skip=None)
Compatibility alias for :meth:to_dict.
Source code in src/easyreflectometry/model/model.py
342 343 344 | |
as_orso()
The sample as an ORSO simple-model (sample.model) dictionary.
Slab representation: lengths in angstrom, SLDs in 1/angstrom^2,
repeating multilayers via the inline N ( ... ) stack syntax.
Returns:
| Type | Description |
|---|---|
dict
|
The ORSO model-language dictionary (the content of an .ort file's
|
Source code in src/easyreflectometry/model/model.py
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
from_dict(passed_dict)
classmethod
Create a Model from a dictionary.
Source code in src/easyreflectometry/model/model.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | |
_ConstrainedEasyScienceMultiFitter
Bases: EasyScienceMultiFitter
EasyScience MultiFitter whose raw fit honours inequality constraints.
fit is a read-only property on the base class (it builds a fresh
callable per access), so the interception lives in an override rather
than a monkey-patch. An explicit constraints_factory keyword is
consumed here and enforced by this library — the core takes no such
argument and would swallow it through **kwargs. Without one, a call
running inside an active :meth:MultiFitter._constraints block passes
through untouched, leaving the outer factory in force.
Source code in src/easyreflectometry/fitting.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
MultiFitter
Source code in src/easyreflectometry/fitting.py
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 | |
sampler
property
The Sampler behind the most recent :meth:mcmc_sample call, or None.
Holds the live BUMPS chain state, so the sampling run can be continued
with fitter.sampler.extend(additional_samples=...) instead of
starting a fresh chain.
chi2
property
Total chi-squared across all fitted datasets, or None if no fit has been performed.
reduced_chi
property
Reduced chi-squared from the most recent fit, or None if no fit has been performed.
classical_chi2
property
Classical chi-squared using only points with positive variances.
classical_reduced_chi
property
Reduced classical chi-squared using only points with positive variances.
objective_chi2
property
Objective-space chi-squared returned by the minimizer.
objective_reduced_chi
property
Objective-space reduced chi-squared returned by the minimizer.
__init__(*args, objective='hybrid')
A convenience class for the class:
easyscience.Fitting.Fitting
which will populate the class:
sc.DataGroup appropriately
after the fitting is performed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Model
|
Reflectometry model(s). |
()
|
objective
|
str
|
Zero-variance handling strategy. One of
|
'hybrid'
|
Source code in src/easyreflectometry/fitting.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |
for_experiments(experiments, objective='hybrid', constraints_factory_provider=None)
classmethod
Build a fitter for a mixed list of unpolarized and polarized experiments.
Every experiment contributes one fit function per dataset: an ordinary
experiment one, a polarized experiment one per measured spin channel,
each evaluating that channel's spin cross-section against the single
model the channels share. Structural parameters are therefore common to
all channels and the magnetic ones are constrained by all of them at
once, exactly as in :meth:fit_polarized — but here several experiments
(and several models) can be fitted together, which is what an
application's "fit everything that is loaded" action needs.
The resulting fitter is not run: the caller supplies the data arrays
to easy_science_multi_fitter.fit(...) in the order given by
:attr:fit_datasets, which lets a GUI drive it from a worker thread.
That call resolves :attr:constraints_factory_provider at call time,
so inequality constraints are applied on this path too — pass
constraints_factory_provider (e.g.
project.build_constraints_factory) or set the attribute before
fitting; with none set, no inequality constraints are enforced.
Note
Built via cls(*models, objective=objective) and then overwrites
_fit_func / easy_science_multi_fitter with the per-channel
versions — the __init__-built pair is briefly constructed and
discarded. Unlike :meth:fit_polarized, the minimizer selection and
its tolerance / max_evaluations are not carried over: the
returned fitter starts from easy_science_multi_fitter's defaults,
so a caller that needs a specific minimizer must set it explicitly
before calling .fit(...).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
experiments
|
list[DataSet1D | PolarizedDataSet]
|
The loaded experiments, in the order they should be fitted. |
required |
objective
|
str
|
Zero-variance handling strategy, see :meth: |
'hybrid'
|
constraints_factory_provider
|
Callable[[], Callable | None] | None
|
Zero-argument callable returning the |
None
|
Returns:
| Type | Description |
|---|---|
MultiFitter
|
Fitter whose |
Source code in src/easyreflectometry/fitting.py
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 | |
fit(data, id=0, objective=None, constraints_factory=None)
Perform the fitting and populate the DataGroups with the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
sc.DataGroup
|
DataGroup to be fitted to and populated. |
required |
id
|
int
|
Unused parameter kept for backward compatibility. By default, 0. |
0
|
objective
|
str | None
|
Per-call override for the zero-variance objective.
If |
None
|
constraints_factory
|
Callable | None
|
Inequality constraints to enforce (BUMPS engines only); see
:mod: |
None
|
Returns:
| Type | Description |
|---|---|
sc.DataGroup
|
A new DataGroup with fitted model curves, SLD profiles, and fit statistics. |
Source code in src/easyreflectometry/fitting.py
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 | |
fit_single_data_set_1d(data, objective=None, constraints_factory=None)
Perform fitting on a single 1D dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataSet1D
|
The 1D dataset to fit. Note that |
required |
objective
|
str | None
|
Per-call override for the zero-variance objective.
If |
None
|
constraints_factory
|
Callable | None
|
Inequality constraints to enforce (BUMPS engines only). Defaults
to what :attr: |
None
|
Returns:
| Type | Description |
|---|---|
FitResults
|
Fit results from the minimizer. |
Source code in src/easyreflectometry/fitting.py
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 | |
fit_polarized(data, objective=None, constraints_factory=None)
Fit all measured spin channels of a polarized experiment simultaneously.
Each channel dataset gets its own fit function evaluating the
corresponding spin cross-section, while every channel shares the single
model — so structural parameters (thickness, roughness, nuclear SLD,
scale, background) are common, and the magnetic parameters
(rho_m/theta_m) are constrained by all channels at once. The refl1d
backend computes all four cross-sections in one kernel evaluation and
caches them per iteration, so fitting N channels costs about as much as
fitting one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
PolarizedDataSet
|
The polarized experiment (its model must be the model this fitter
was constructed with). Note that per-channel |
required |
objective
|
str | None
|
Per-call override for the zero-variance objective.
If |
None
|
constraints_factory
|
Callable | None
|
Inequality constraints to enforce (BUMPS engines only); see
:mod: |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, FitResults]
|
Fit results per channel, keyed 'pp', 'pm', 'mp', 'mm' (measured channels only, in that order). |
Note
Unlike :meth:for_experiments, this method does not populate
:attr:fit_datasets / :attr:fit_channels — those are set only by the
caller-driven, for_experiments-built flow.
Source code in src/easyreflectometry/fitting.py
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 | |
mcmc_sample(data, samples=10000, burn=2000, thin=10, population=None, objective=None, initializer=None, progress_callback=None, abort_test=None, constraints_factory=None)
Run Bayesian MCMC sampling on reflectometry data using the DREAM sampler.
Requires that the minimizer is a BUMPS instance (i.e. the minimizer was
switched to AvailableMinimizers.Bumps).
:param data: DataGroup with reflectivity data.
:param samples: Number of retained DREAM samples requested from BUMPS.
:param burn: Burn-in steps.
:param thin: Thinning interval.
:param population: BUMPS DREAM population count for advanced users.
:param objective: Zero-variance handling strategy.
:param initializer: DREAM population initializer. One of 'eps',
'cov', 'lhs', or 'random'. By default, None (BUMPS
uses 'eps').
:param progress_callback: Optional callback for progress updates during
sampling. Forwarded to the core MultiFitter.
:param abort_test: Optional callable returning True to abort sampling.
:param constraints_factory: Inequality constraints to enforce (see
:mod:easyreflectometry.inequality_constraints); the posterior is
penalised in the infeasible region. Defaults to what
:attr:constraints_factory_provider returns.
:return: Dictionary with keys 'draws', 'param_names', 'state',
and 'logp'.
:raises RuntimeError: If the current minimizer is not a BUMPS instance.
The underlying :class:~easyscience.fitting.Sampler is retained on
:attr:sampler, so the chain can be continued without re-running the
burn-in::
fitter.mcmc_sample(data, samples=2000, burn=500, thin=10)
extended = fitter.sampler.extend(additional_samples=8000, thin=10)
Source code in src/easyreflectometry/fitting.py
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 | |
record_fit_results(results)
Adopt fit results produced elsewhere, so this fitter reports on them.
An application that drives easy_science_multi_fitter.fit(...) itself
— to run it in a worker thread, for instance — leaves the MultiFitter
that owns the goodness-of-fit properties none the wiser. Handing the
results back here makes :attr:chi2 / :attr:reduced_chi describe that
fit instead of reporting "no fit performed".
Only the minimizer-reported metrics are restored: the classical ones
need the original data arrays, which are not part of FitResults, so
:attr:classical_chi2 and :attr:classical_reduced_chi stay None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
list[FitResults] | None
|
Results of the fit, one per fitted dataset. None clears them. |
required |
Source code in src/easyreflectometry/fitting.py
903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 | |
switch_minimizer(minimizer)
Switch the minimizer for the fitting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
minimizer
|
AvailableMinimizers
|
Minimizer to be switched to. |
required |
Source code in src/easyreflectometry/fitting.py
924 925 926 927 928 929 930 931 932 | |
_constraints_applied(factory)
Attach factory's constraints to problems built inside the block.
A no-op when factory is None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
factory
|
Optional[Callable]
|
Receives the |
required |
Source code in src/easyreflectometry/_bumps_constraints.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
_constraints_active()
Whether an :func:applied block is active in the current context.
Lets an inner wrapper (MultiFitter routes the raw
easy_science_multi_fitter.fit through the constraints machinery)
detect that an outer block already attached a factory — possibly an
explicit one that must not be overridden by re-resolving the provider.
Source code in src/easyreflectometry/_bumps_constraints.py
101 102 103 104 105 106 107 108 109 | |
_validate_objective(objective)
Validate and resolve the objective string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
objective
|
str
|
The objective mode string. |
required |
Raises:
| Type | Description |
|---|---|
ValueError :
|
If the objective is not one of the valid options. |
Returns:
| Type | Description |
|---|---|
str
|
Resolved objective string ('auto' becomes 'hybrid'). |
Source code in src/easyreflectometry/fitting.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
_prepare_fit_arrays(x_vals, y_vals, variances, objective)
Prepare x, y_eff, and weights arrays for fitting based on the objective mode.
For legacy_mask, zero-variance points are removed from all arrays.
For hybrid, valid-variance points use standard WLS while zero-variance
points use Mighell-transformed y and weights.
For mighell, all points use the Mighell transform.
Note: variances here means σ² (the scipp convention), not σ.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_vals
|
np.ndarray
|
Independent variable values. |
required |
y_vals
|
np.ndarray
|
Observed dependent variable values. |
required |
variances
|
np.ndarray
|
Variance (σ²) of each observed point. |
required |
objective
|
str
|
One of 'legacy_mask', 'hybrid', 'mighell'. |
required |
Returns:
| Type | Description |
|---|---|
tuple[np.ndarray, np.ndarray, np.ndarray, dict]
|
Tuple of (x_out, y_eff, weights, stats) where stats is a dict with keys 'valid', 'mighell_substituted', 'masked'. |
Source code in src/easyreflectometry/fitting.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
_compute_weighted_chi2(y_obs, y_calc, sigma)
Return weighted chi-square for finite, strictly positive uncertainties.
Source code in src/easyreflectometry/fitting.py
177 178 179 180 181 182 183 | |
_compute_reduced_chi2(chi2, n_points, n_params)
Return reduced chi-square or None when degrees of freedom are not positive.
Source code in src/easyreflectometry/fitting.py
186 187 188 189 190 191 | |
_fit_result_reduced_chi(result, n_points=None)
Return reduced chi-square from either supported FitResults attribute name.
Source code in src/easyreflectometry/fitting.py
194 195 196 197 198 199 200 201 202 203 204 | |
_bind_fit_func(func, unique_name)
Bind a model's fit function to its unique_name for EasyScienceMultiFitter.
EasyScienceMultiFitter calls each fit function positionally as
func(x, *extra_args); the model's interface.fit_func expects its
unique_name as that extra positional argument, so it has to be closed
over here rather than passed through the fitter's call signature.
Source code in src/easyreflectometry/fitting.py
207 208 209 210 211 212 213 214 215 216 217 218 219 | |
_emit_array_prep_warnings(stats, y_vals, label, *, action='fitting', extra='')
Warn about zero-variance handling applied by :func:_prepare_fit_arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stats
|
dict
|
The |
required |
y_vals
|
np.ndarray
|
The original (pre-transform) y values, used for the "all points" count. |
required |
label
|
str
|
Identifies what was fitted/sampled, e.g. |
required |
action
|
str
|
Verb describing the operation, e.g. |
'fitting'
|
extra
|
str
|
Extra sentence(s) appended to the Mighell-related warnings (e.g. a likelihood-validity caveat for MCMC). By default, ''. |
''
|
Source code in src/easyreflectometry/fitting.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
_classical_metrics_for(original, model_curve, result, n_points=None)
Assemble the classical (positive-variance-only) and objective-space fit metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original
|
dict
|
Dict with keys |
required |
model_curve
|
np.ndarray
|
Model evaluated at the original x values. |
required |
result
|
FitResults
|
The minimizer's result for this dataset/channel. |
required |
n_points
|
int | None
|
Number of points actually fitted, used as the |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Keys |
Source code in src/easyreflectometry/fitting.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |
_flatten_list(this_list)
Flatten nested lists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
this_list
|
list
|
List to be flattened. |
required |
Returns:
| Type | Description |
|---|---|
list
|
Flattened list. |
Source code in src/easyreflectometry/fitting.py
935 936 937 938 939 940 941 942 943 944 945 946 947 948 | |