reflectorch 1.3.0__py3-none-any.whl → 1.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of reflectorch might be problematic. Click here for more details.
- reflectorch/__init__.py +17 -17
- reflectorch/data_generation/__init__.py +128 -126
- reflectorch/data_generation/dataset.py +210 -210
- reflectorch/data_generation/likelihoods.py +80 -80
- reflectorch/data_generation/noise.py +470 -470
- reflectorch/data_generation/priors/__init__.py +60 -60
- reflectorch/data_generation/priors/base.py +55 -55
- reflectorch/data_generation/priors/exp_subprior_sampler.py +298 -298
- reflectorch/data_generation/priors/independent_priors.py +195 -195
- reflectorch/data_generation/priors/multilayer_models.py +311 -311
- reflectorch/data_generation/priors/multilayer_structures.py +104 -104
- reflectorch/data_generation/priors/no_constraints.py +206 -206
- reflectorch/data_generation/priors/parametric_models.py +841 -841
- reflectorch/data_generation/priors/parametric_subpriors.py +369 -369
- reflectorch/data_generation/priors/params.py +252 -252
- reflectorch/data_generation/priors/sampler_strategies.py +369 -369
- reflectorch/data_generation/priors/scaler_mixin.py +65 -65
- reflectorch/data_generation/priors/subprior_sampler.py +371 -371
- reflectorch/data_generation/priors/utils.py +118 -118
- reflectorch/data_generation/process_data.py +41 -41
- reflectorch/data_generation/q_generator.py +280 -246
- reflectorch/data_generation/reflectivity/__init__.py +102 -102
- reflectorch/data_generation/reflectivity/abeles.py +97 -97
- reflectorch/data_generation/reflectivity/kinematical.py +70 -70
- reflectorch/data_generation/reflectivity/memory_eff.py +105 -105
- reflectorch/data_generation/reflectivity/numpy_implementations.py +120 -120
- reflectorch/data_generation/reflectivity/smearing.py +138 -138
- reflectorch/data_generation/reflectivity/smearing_pointwise.py +109 -109
- reflectorch/data_generation/scale_curves.py +112 -112
- reflectorch/data_generation/smearing.py +98 -98
- reflectorch/data_generation/utils.py +223 -222
- reflectorch/extensions/jupyter/__init__.py +11 -6
- reflectorch/extensions/jupyter/api.py +85 -0
- reflectorch/extensions/jupyter/callbacks.py +34 -34
- reflectorch/extensions/jupyter/components.py +758 -0
- reflectorch/extensions/jupyter/custom_select.py +268 -0
- reflectorch/extensions/jupyter/log_widget.py +241 -0
- reflectorch/extensions/jupyter/model_selection.py +495 -0
- reflectorch/extensions/jupyter/plotly_plot_manager.py +329 -0
- reflectorch/extensions/jupyter/widget.py +625 -0
- reflectorch/extensions/matplotlib/__init__.py +5 -5
- reflectorch/extensions/matplotlib/losses.py +32 -32
- reflectorch/extensions/refnx/refnx_conversion.py +76 -76
- reflectorch/inference/__init__.py +28 -24
- reflectorch/inference/inference_model.py +847 -851
- reflectorch/inference/input_interface.py +239 -0
- reflectorch/inference/loading_data.py +37 -0
- reflectorch/inference/multilayer_fitter.py +171 -171
- reflectorch/inference/multilayer_inference_model.py +193 -193
- reflectorch/inference/plotting.py +524 -98
- reflectorch/inference/preprocess_exp/__init__.py +6 -6
- reflectorch/inference/preprocess_exp/attenuation.py +36 -36
- reflectorch/inference/preprocess_exp/cut_with_q_ratio.py +31 -31
- reflectorch/inference/preprocess_exp/footprint.py +81 -81
- reflectorch/inference/preprocess_exp/interpolation.py +19 -16
- reflectorch/inference/preprocess_exp/normalize.py +21 -21
- reflectorch/inference/preprocess_exp/preprocess.py +121 -121
- reflectorch/inference/query_matcher.py +81 -81
- reflectorch/inference/record_time.py +43 -43
- reflectorch/inference/sampler_solution.py +56 -56
- reflectorch/inference/scipy_fitter.py +272 -248
- reflectorch/inference/torch_fitter.py +87 -87
- reflectorch/ml/__init__.py +32 -32
- reflectorch/ml/basic_trainer.py +292 -292
- reflectorch/ml/callbacks.py +80 -80
- reflectorch/ml/dataloaders.py +26 -26
- reflectorch/ml/loggers.py +55 -55
- reflectorch/ml/schedulers.py +355 -355
- reflectorch/ml/trainers.py +200 -191
- reflectorch/ml/utils.py +2 -2
- reflectorch/models/__init__.py +15 -14
- reflectorch/models/activations.py +50 -50
- reflectorch/models/encoders/__init__.py +19 -17
- reflectorch/models/encoders/conv_encoder.py +218 -218
- reflectorch/models/encoders/conv_res_net.py +115 -115
- reflectorch/models/encoders/fno.py +133 -133
- reflectorch/models/encoders/integral_kernel_embedding.py +390 -0
- reflectorch/models/networks/__init__.py +14 -14
- reflectorch/models/networks/mlp_networks.py +434 -428
- reflectorch/models/networks/residual_net.py +156 -156
- reflectorch/paths.py +29 -27
- reflectorch/runs/__init__.py +31 -31
- reflectorch/runs/config.py +25 -25
- reflectorch/runs/slurm_utils.py +93 -93
- reflectorch/runs/train.py +78 -78
- reflectorch/runs/utils.py +404 -401
- reflectorch/test_config.py +4 -4
- reflectorch/train.py +4 -4
- reflectorch/train_on_cluster.py +4 -4
- reflectorch/utils.py +98 -68
- {reflectorch-1.3.0.dist-info → reflectorch-1.5.0.dist-info}/METADATA +129 -125
- reflectorch-1.5.0.dist-info/RECORD +96 -0
- {reflectorch-1.3.0.dist-info → reflectorch-1.5.0.dist-info}/WHEEL +1 -1
- {reflectorch-1.3.0.dist-info → reflectorch-1.5.0.dist-info}/licenses/LICENSE.txt +20 -20
- reflectorch-1.3.0.dist-info/RECORD +0 -86
- {reflectorch-1.3.0.dist-info → reflectorch-1.5.0.dist-info}/top_level.txt +0 -0
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
from typing import Tuple
|
|
2
|
-
|
|
3
|
-
import torch
|
|
4
|
-
from torch import Tensor
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class ScalerMixin:
|
|
8
|
-
"""Provides functionality to multiple inheritance classes for scaling the parameters to a specified range and restoring them to the original range."""
|
|
9
|
-
@staticmethod
|
|
10
|
-
def _get_delta_vector(min_vector: Tensor, max_vector: Tensor):
|
|
11
|
-
delta_vector = max_vector - min_vector
|
|
12
|
-
delta_vector[delta_vector == 0.] = 1.
|
|
13
|
-
return delta_vector
|
|
14
|
-
|
|
15
|
-
def _scale(self, params_t: Tensor, min_vector: Tensor, max_vector: Tensor):
|
|
16
|
-
"""scale the parameters to a specific range
|
|
17
|
-
Args:
|
|
18
|
-
params_t (Tensor): the values of the parameters
|
|
19
|
-
min_vector (Tensor): minimum possible values of each parameter
|
|
20
|
-
max_vector (Tensor): maximum possible values of each parameter
|
|
21
|
-
|
|
22
|
-
Returns:
|
|
23
|
-
Tensor: the scaled parameters
|
|
24
|
-
"""
|
|
25
|
-
if params_t.dim() == 2:
|
|
26
|
-
min_vector = torch.atleast_2d(min_vector)
|
|
27
|
-
max_vector = torch.atleast_2d(max_vector)
|
|
28
|
-
|
|
29
|
-
delta_vector = max_vector - min_vector
|
|
30
|
-
delta_vector[delta_vector == 0.] = 1.
|
|
31
|
-
scaled_params = (
|
|
32
|
-
params_t - min_vector
|
|
33
|
-
) / self._get_delta_vector(min_vector, max_vector) * self._length + self._bias
|
|
34
|
-
return scaled_params
|
|
35
|
-
|
|
36
|
-
def _restore(self, scaled_params: Tensor, min_vector: Tensor, max_vector: Tensor):
|
|
37
|
-
"""restores the parameters to their original range
|
|
38
|
-
Args:
|
|
39
|
-
scaled_params: (Tensor): the scaled parameters
|
|
40
|
-
min_vector (Tensor): minimum possible values of each parameter
|
|
41
|
-
max_vector (Tensor): maximum possible values of each parameter
|
|
42
|
-
|
|
43
|
-
Returns:
|
|
44
|
-
Tensor: the restored parameters
|
|
45
|
-
"""
|
|
46
|
-
if scaled_params.dim() == 2:
|
|
47
|
-
min_vector = torch.atleast_2d(min_vector)
|
|
48
|
-
max_vector = torch.atleast_2d(max_vector)
|
|
49
|
-
|
|
50
|
-
params_t = (
|
|
51
|
-
scaled_params - self._bias
|
|
52
|
-
) / self._length * self._get_delta_vector(min_vector, max_vector) + min_vector
|
|
53
|
-
return params_t
|
|
54
|
-
|
|
55
|
-
@property
|
|
56
|
-
def scaled_range(self) -> Tuple[float, float]:
|
|
57
|
-
return self._scaled_range
|
|
58
|
-
|
|
59
|
-
@scaled_range.setter
|
|
60
|
-
def scaled_range(self, scaled_range: Tuple[float, float]):
|
|
61
|
-
"""sets the range used for scaling the parameters"""
|
|
62
|
-
self._scaled_range = scaled_range
|
|
63
|
-
self._length = scaled_range[1] - scaled_range[0]
|
|
64
|
-
self._init_bias = (scaled_range[0] + scaled_range[1]) / 2
|
|
65
|
-
self._bias = (self._init_bias - 0.5 * self._length)
|
|
1
|
+
from typing import Tuple
|
|
2
|
+
|
|
3
|
+
import torch
|
|
4
|
+
from torch import Tensor
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ScalerMixin:
|
|
8
|
+
"""Provides functionality to multiple inheritance classes for scaling the parameters to a specified range and restoring them to the original range."""
|
|
9
|
+
@staticmethod
|
|
10
|
+
def _get_delta_vector(min_vector: Tensor, max_vector: Tensor):
|
|
11
|
+
delta_vector = max_vector - min_vector
|
|
12
|
+
delta_vector[delta_vector == 0.] = 1.
|
|
13
|
+
return delta_vector
|
|
14
|
+
|
|
15
|
+
def _scale(self, params_t: Tensor, min_vector: Tensor, max_vector: Tensor):
|
|
16
|
+
"""scale the parameters to a specific range
|
|
17
|
+
Args:
|
|
18
|
+
params_t (Tensor): the values of the parameters
|
|
19
|
+
min_vector (Tensor): minimum possible values of each parameter
|
|
20
|
+
max_vector (Tensor): maximum possible values of each parameter
|
|
21
|
+
|
|
22
|
+
Returns:
|
|
23
|
+
Tensor: the scaled parameters
|
|
24
|
+
"""
|
|
25
|
+
if params_t.dim() == 2:
|
|
26
|
+
min_vector = torch.atleast_2d(min_vector)
|
|
27
|
+
max_vector = torch.atleast_2d(max_vector)
|
|
28
|
+
|
|
29
|
+
delta_vector = max_vector - min_vector
|
|
30
|
+
delta_vector[delta_vector == 0.] = 1.
|
|
31
|
+
scaled_params = (
|
|
32
|
+
params_t - min_vector
|
|
33
|
+
) / self._get_delta_vector(min_vector, max_vector) * self._length + self._bias
|
|
34
|
+
return scaled_params
|
|
35
|
+
|
|
36
|
+
def _restore(self, scaled_params: Tensor, min_vector: Tensor, max_vector: Tensor):
|
|
37
|
+
"""restores the parameters to their original range
|
|
38
|
+
Args:
|
|
39
|
+
scaled_params: (Tensor): the scaled parameters
|
|
40
|
+
min_vector (Tensor): minimum possible values of each parameter
|
|
41
|
+
max_vector (Tensor): maximum possible values of each parameter
|
|
42
|
+
|
|
43
|
+
Returns:
|
|
44
|
+
Tensor: the restored parameters
|
|
45
|
+
"""
|
|
46
|
+
if scaled_params.dim() == 2:
|
|
47
|
+
min_vector = torch.atleast_2d(min_vector)
|
|
48
|
+
max_vector = torch.atleast_2d(max_vector)
|
|
49
|
+
|
|
50
|
+
params_t = (
|
|
51
|
+
scaled_params - self._bias
|
|
52
|
+
) / self._length * self._get_delta_vector(min_vector, max_vector) + min_vector
|
|
53
|
+
return params_t
|
|
54
|
+
|
|
55
|
+
@property
|
|
56
|
+
def scaled_range(self) -> Tuple[float, float]:
|
|
57
|
+
return self._scaled_range
|
|
58
|
+
|
|
59
|
+
@scaled_range.setter
|
|
60
|
+
def scaled_range(self, scaled_range: Tuple[float, float]):
|
|
61
|
+
"""sets the range used for scaling the parameters"""
|
|
62
|
+
self._scaled_range = scaled_range
|
|
63
|
+
self._length = scaled_range[1] - scaled_range[0]
|
|
64
|
+
self._init_bias = (scaled_range[0] + scaled_range[1]) / 2
|
|
65
|
+
self._bias = (self._init_bias - 0.5 * self._length)
|