fitter
Master fitting and map making script.
You typically want to run the witcher command instead of this.
aic_refit(cfg, metamodel, start, nonpara=False)
Maximum likelihood under the initial noise model, for comparing models with the AIC.
The fit re-estimates the noise from each model's own residuals, so the chi-squared of
different models can't be compared. Here the noise is re-estimated from the data alone
(as at load time), the free parameters are refit with LM starting from the current
parameters (the MCMC medians, or the LM best fit without MCMC), and the result is saved
as aic.yaml and par_results_aic.dill in the output directory. The fit's own noise
is restored afterwards, nothing else is changed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
dict
|
The config, |
required |
metamodel
|
MetaModel
|
The fitted metamodel, its free parameters for the current round are refit. |
required |
start
|
str
|
Description of the starting parameters, saved in |
required |
nonpara
|
bool
|
If True the outputs get a |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
metamodel |
MetaModel
|
The input metamodel with its parameters and fit noise unchanged. |
Source code in witch/fitter.py
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 | |
deep_merge(a, b)
Based on https://gist.github.com/angstwad/bf22d1822c38a92ec0a9?permalink_comment_id=3517209
Source code in witch/fitter.py
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 | |
load_config(start_cfg, cfg_path)
We want to load a config and if it has the key "base", load that as well and merge them. We only want to take things from base that are not in the original config so we merge the original into the newly loaded one.
Source code in witch/fitter.py
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 | |
print_once(*args)
Helper function to print only once when running with MPI. Only the rank 0 process will print.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Unpack[tuple[Any, ...]]
|
Arguments to pass to print. |
()
|
Source code in witch/fitter.py
63 64 65 66 67 68 69 70 71 72 73 74 75 | |
process_maps(cfg, dataset, metamodel, sim_noise_kwargs=None)
Prepare the maps of a dataset: simulate them if requested and compute the noise model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
dict
|
The config. |
required |
dataset
|
DataSet
|
The map dataset. |
required |
metamodel
|
MetaModel
|
The model, only needed when simulating. |
required |
sim_noise_kwargs
|
dict
|
Overrides for the noise kwargs when drawing the simulated noise, so a sim can use a
different noise model than the fit (e.g. another CMB cosmology through |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
mapset |
SolutionSet
|
The maps with their noise models computed. |
Source code in witch/fitter.py
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 | |
resolve_noise_args(imap, args, kwargs)
Evaluate noise arguments that refer to the map, like compute_noise does.
Note
This is a temporary copy of the self... evaluation inside jitkasi's
WCSMap.compute_noise, needed because the sim calls a noise model's sample directly.
Once jitkasi exposes that evaluation as a public helper, import it from there and delete
this function (and its use in process_maps). Until then keep the two in step: a string
argument that starts with self is evaluated with self set to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
imap
|
WCSMap
|
The map that |
required |
args
|
tuple
|
Positional noise arguments, strings starting with |
required |
kwargs
|
dict
|
Keyword noise arguments, string values starting with |
required |
Returns:
| Name | Type | Description |
|---|---|---|
args |
list
|
The evaluated positional arguments. |
kwargs |
dict
|
The evaluated keyword arguments. |
Source code in witch/fitter.py
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 | |