vipr_reflectometry.flow_models.predict package¶
Submodules¶
vipr_reflectometry.flow_models.predict.flow_predictor module¶
- class vipr_reflectometry.flow_models.predict.flow_predictor.FlowPredictor(**kw: Any)¶
Bases:
PredictorHandlerPredictor handler for Flow Network models (CINN, NSF, MAF) using inverse sampling.
Performs probabilistic parameter prediction by sampling from the flow model’s latent space conditioned on experimental curves.
Supports all flow-based architectures: - CINNWithConvEmb - NSFWithConvEmb - MAFNetworkWithConvEmb - And other flow models with a sample() method
- class vipr_reflectometry.flow_models.predict.flow_predictor.FlowPredictorParams(*, num_samples: int = 100, seed: int | None = None, device: str = 'cpu', q_resolution: float | None = None, number_top_to_bottom: bool = True)¶
Bases:
BaseModelParameters for the flow predictor.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
vipr_reflectometry.flow_models.predict.physical_constraint_filter module¶
Physical constraint filter for flow model predictions.
This filter removes unphysical parameter samples (e.g., negative roughness or thickness values) that can be generated by flow-based models.
- class vipr_reflectometry.flow_models.predict.physical_constraint_filter.PhysicalConstraintFilter(app: VIPR)¶
Bases:
objectFilter class for enforcing physical constraints on flow model samples.
This class provides filtering methods to remove unphysical parameter samples generated by flow-based models.
- filter_unphysical_samples(prediction_data, **kwargs)¶
Filter out unphysical parameter samples from flow model predictions.
Flow models (CINN, NSF, MAF) can generate samples with negative values for physical parameters like roughness or thickness. This filter removes such unphysical samples to ensure only valid parameter combinations are passed to postprocessing steps.
The filter checks for: - Roughness < 0 - Thickness < 0 - Sigma < 0
Note: - SLD values are intentionally NOT filtered by sign because negative SLD
can be physically valid in neutron reflectometry.
Weight=-5 ensures this runs early, before other postprocessing filters.
- Parameters:
prediction_data – Dict containing: - ‘parameter_samples’: numpy array of shape (num_samples, num_params) - ‘param_names’: List of parameter names - ‘all_spectra_results’: (optional) List of per-spectrum results
**kwargs – Additional filter parameters
- Returns:
‘num_filtered’: Number of unphysical samples removed
- Return type:
prediction_data with only physical samples, augmented with
Example
If 2000 samples were generated and 150 had negative roughness: - Returns 1850 valid samples - Logs warning about filtered samples - Sets num_filtered=150
Module contents¶
Filters for flow model predictions.
- class vipr_reflectometry.flow_models.predict.PhysicalConstraintFilter(app: VIPR)¶
Bases:
objectFilter class for enforcing physical constraints on flow model samples.
This class provides filtering methods to remove unphysical parameter samples generated by flow-based models.
- filter_unphysical_samples(prediction_data, **kwargs)¶
Filter out unphysical parameter samples from flow model predictions.
Flow models (CINN, NSF, MAF) can generate samples with negative values for physical parameters like roughness or thickness. This filter removes such unphysical samples to ensure only valid parameter combinations are passed to postprocessing steps.
The filter checks for: - Roughness < 0 - Thickness < 0 - Sigma < 0
Note: - SLD values are intentionally NOT filtered by sign because negative SLD
can be physically valid in neutron reflectometry.
Weight=-5 ensures this runs early, before other postprocessing filters.
- Parameters:
prediction_data – Dict containing: - ‘parameter_samples’: numpy array of shape (num_samples, num_params) - ‘param_names’: List of parameter names - ‘all_spectra_results’: (optional) List of per-spectrum results
**kwargs – Additional filter parameters
- Returns:
‘num_filtered’: Number of unphysical samples removed
- Return type:
prediction_data with only physical samples, augmented with
Example
If 2000 samples were generated and 150 had negative roughness: - Returns 1850 valid samples - Logs warning about filtered samples - Sets num_filtered=150