hierarchical_flow_tools.likelihood¶
Flow likelihood class definition and helper functions.
Module Contents¶
Classes¶
Class for streamlining log_likelihood calls with normalising flows, handling vectorisation and data rescaling. |
- class hierarchical_flow_tools.likelihood.FlowLikelihood(flow: glasflow.flows.base.Flow, device: str, conditional_rescaling_function=None, data=None, batch_size=None)¶
Class for streamlining log_likelihood calls with normalising flows, handling vectorisation and data rescaling.
- Parameters:
- flowFlow
A trained normalising flow that will perform the log_likelihood calculation.
- devicestr
The pytorch device on which to perform all operations
- conditional_rescaling_functionfunction, optional
A function for remapping input conditionals to , by default None
- dataTensor, optional
The data (rescaled if necessary) to be input to the flow for all log_likelihood evaluations, by default None (data to be provided on log_likelihood call)
- batch_sizeint, optional
Size of each batch to feed into the flow, by default None (in which case, all data is fed through the flow at once - may lead to memory errors for large datasets)
- log_likelihood(conditional, data=None)¶
Get the log_likelihood of the data given a set of M conditional parameters. This method supports vectorised evaluation of N sets of conditionals (of shape (N, M)). If no data is provided, the method falls back to the data given on instantiation of the parent class.
- Parameters:
- conditionalTensor
The conditional values to evaluate the log_likelihood for. If vectorised, should take the shape (N_points, N_conditional_params)
- dataTensor, optional
Data to provide to the flow for the log_likelihood evaluation, by default None (falls back to data supplied on instantiation of this class)
- Returns:
- Tensor
The combined log_likelihoods for the supplied conditional values over all of the data.
- Raises:
- RuntimeError
Raises if no data has been provided at any stage for the log_likelihood evaluations.