fitting
_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
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 | |
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
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 | |
data_points()
Data points.
Source code in src/easyreflectometry/data/data_store.py
155 156 157 | |
__repr__()
Repr function.
Source code in src/easyreflectometry/data/data_store.py
159 160 161 | |
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 | |
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 | |
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
225 226 227 228 229 230 231 232 233 | |
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
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
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
172 173 174 175 176 177 178 179 180 181 182 183 | |
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
185 186 187 188 189 190 191 192 193 194 195 196 197 | |
to_dict(skip=None)
Serialize the model, encoding the resolution function and interface name.
Source code in src/easyreflectometry/model/model.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
as_dict(skip=None)
Compatibility alias for :meth:to_dict.
Source code in src/easyreflectometry/model/model.py
273 274 275 | |
as_orso()
Convert the model to a dictionary suitable for ORSO.
Source code in src/easyreflectometry/model/model.py
277 278 279 | |
from_dict(passed_dict)
classmethod
Create a Model from a dictionary.
Source code in src/easyreflectometry/model/model.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |
MultiFitter
Source code in src/easyreflectometry/fitting.py
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 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 | |
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
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 | |
fit(data, id=0, objective=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
|
Returns:
| Type | Description |
|---|---|
sc.DataGroup
|
A new DataGroup with fitted model curves, SLD profiles, and fit statistics. |
Source code in src/easyreflectometry/fitting.py
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 | |
fit_single_data_set_1d(data, objective=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
|
Returns:
| Type | Description |
|---|---|
FitResults
|
Fit results from the minimizer. |
Source code in src/easyreflectometry/fitting.py
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 | |
mcmc_sample(data, samples=10000, burn=2000, thin=10, population=None, objective=None, initializer=None, progress_callback=None, abort_test=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.
: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
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 | |
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
545 546 547 548 549 550 551 552 553 | |
_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
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
_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
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 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 | |
_compute_weighted_chi2(y_obs, y_calc, sigma)
Return weighted chi-square for finite, strictly positive uncertainties.
Source code in src/easyreflectometry/fitting.py
134 135 136 137 138 139 140 | |
_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
143 144 145 146 147 148 | |
_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
151 152 153 154 155 156 157 158 159 160 161 | |
_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
556 557 558 559 560 561 562 563 564 565 566 567 568 569 | |