error_functions.residual_base.ResidualFunction

error_functions.residual_base.ResidualFunction(self, database, datasets, phase_models, symbols_to_fit=None, weight=None)

Protocol class for computing the error (residual) between data and a model prediction given a set of parameters.

Classes that implement this protocol typically will concerned with implementing a residual/likelihood function for a certain type of data. The protocol is intentitionally left to be simple to implement while enabling flexibility to implement additional methods and attributes for performance and debugging purposes.

Parameters

Name Type Description Default
database Database required
datasets PickleableTinyDB The candidate datasets for the a contribution. Usually the datasets are a superset (in components, phases, data types, etc.) of the actual data used to compute the residual for any particular contribution. required
phase_models PhaseModels Defines the active set of components that should be fit and any user-provided overrides to the PyCalphad Model class for each phase. required
symbols_to_fit Optional[List[SymbolName]] User-provided symbols to fit. By default, the symbols to fit should be set by espei.utils.database_symbols_to_fit. None
weight Optional[float] When computing the likelihood, this should be used to modify the probability distribution. Higher weights should correspond to narrower probability distributions, but it’s exact use will depend on the particular probability distribution. None

Attributes

Name Type Description
weight Optional[Union[float, Dict[str, float]]]

Methods

Name Description
get_likelihood Return log-likelihood for the set of parameters.
get_residuals Return the residual comparing the selected data to the set of parameters.

get_likelihood

error_functions.residual_base.ResidualFunction.get_likelihood(parameters)

Return log-likelihood for the set of parameters.

Parameters

Name Type Description Default
parameters ArrayLike 1D parameter vector. The size of the parameters array should match the number of fitting symbols used to build the models. This is not checked. required

Returns

Type Description
float Value of log-likelihood for the given set of parameters

get_residuals

error_functions.residual_base.ResidualFunction.get_residuals(parameters)

Return the residual comparing the selected data to the set of parameters.

The residual is zero if the database predictions under the given parameters agrees with the data exactly.

Parameters

Name Type Description Default
parameters ArrayLike 1D parameter vector. The size of the parameters array should match the number of fitting symbols used to build the models. This is not checked. required

Returns

Type Description
Tuple[List[float], List[float]] Tuple of (residuals, weights), which must obey len(residuals) == len(weights)
Back to top