pylawr.transform.inference#

pylawr.transform.inference.KernelVariogram(kernel)

The kernel variogram is an observation operator, which transforms a set of parameters into a pre-defined kernel.

pylawr.transform.inference.SIRParticleFilter(...)

This sequential importance resampling (SIR) particle filter can be used to infer unknown parameters and states with known observations and models.

pylawr.transform.inference.random_walk(params)

Given parameters are disturbed by truncated Gaussian noise with given relative standard deviation.

pylawr.transform.inference.gaussian_pdf(...)

This likelihood corresponds to a Gaussian probability distribution function.

pylawr.transform.inference.laplace_pdf(...)

This likelihood corresponds to a Laplace probability distribution function.

pylawr.transform.inference.KernelVariogram#

class pylawr.transform.inference.KernelVariogram(kernel)[source]#

Bases: object

The kernel variogram is an observation operator, which transforms a set of parameters into a pre-defined kernel. The variogram of this kernel is then evaluated based on given observation distances. The order of the parameters should be the same between kernel and given parameters.

Parameters

kernel (child of BaseKernel) – This kernel is used as basis kernel for the observation operator. The given parameters are set as parameters of this kernel.

pylawr.transform.inference.SIRParticleFilter#

class pylawr.transform.inference.SIRParticleFilter(obs_op_func, predict_func, prob_func, params_fg, ens_size=100, ens_threshold=10)[source]#

Bases: MemoryMixin

This sequential importance resampling (SIR) particle filter can be used to infer unknown parameters and states with known observations and models.

The particle filter needs an observation operator obs_op_func, which maps from state space into observation space. An additional dynamical model predict_func is needed to propagate the state from one time step to the other. The probability function prob_func specifies the probability distribution of the observation space. The first guess parameters params_fg are used as first forecast of the parameters.

Parameters
  • obs_op_func (function) – This func takes the state space parameters and transfers these into observation space. There are some prepared observation operators specified in this submodule.

  • predict_func (function) – This prediction function is used as dynamical model to propagate the state space parameters from one time to another. This prediction function takes state space parameters and returns the predicted new state space parameters. There are some prepared prediction function specified in this submodule.

  • prob_func (function) – This probability function specifies the probability density function of the observations. This probability takes observations generated with given observation operator and compares them to real observations. There are some commonly used probability density functions specified within this submodule.

  • params_fg (iterable) – This parameters are used as first guess. The number of different parameters have to be equal the number of ensemble members. This is normally a numpy.ndarray, where the first dimension is the ensemble size and the second dimension is the i-th parameter.

  • ens_size (int, optional) – This number of ensemble members (default=100) is used to infer the parameters.

  • ens_threshold (int, optional) – If the effective number of ensemble members is smaller than this threshold (default=10), the ensemble is resampled.

_abc_impl = <_abc._abc_data object>#
_propagate(**kwargs)[source]#
_resample(params, weights, rnd=None, **kwargs)[source]#
_update_weights(params, obs, **kwargs)[source]#
property ens_size#

The ensemble size of this particle filter.

Returns

ens_size – The ensemble size of this particle filter.

Return type

int

fit(obs, time=None, **kwargs)[source]#

This method iterates the particle filter with given observations. If the number of effective particles is below a set threshold, the ensemble members are resampled.

Parameters
  • obs (numpy.ndarray) – The conditional probability of the parameters with respect to these observations are used to update the particle weights.

  • time (pandas.DateTime or None, optional) – This time is used as timestamp within the weight and parameter history. If no time is given (default), an empty time step is used.

  • **kwargs (dict(str, any)) – These additional keyword arguments are passed to the observation operator and the prediction function.

property fitted#

If this particle filter is fitted.

Returns

fitted – If there was at least one iteration with this particle filter.

Return type

bool

property param_hist#

The history of the parameters.

Returns

param_hist – This is the parameter history, where the first axis is given as number of iterations. Normally, this array has as shape n x k x p with n the number of historic iterations, k the number of ensemble members and p as number of parameters.

Return type

numpy.ndarray

to_xarray()[source]#

Serialize this filter’s parameters to an xarray.Dataset

Returns

the filter’s parameters as dataset

Return type

xarray.Dataset

property weight_hist#

The history of the estimated ensemble weights.

Returns

weight_hist – This is the weight history with n x k as shape, n the number of historic iterations and k the number of ensemble members. At every iteration the weights are normalized to unity.

Return type

numpy.ndarray

pylawr.transform.inference.random_walk#

pylawr.transform.inference.random_walk(params, noise=0.1, **kwargs)[source]#

Given parameters are disturbed by truncated Gaussian noise with given relative standard deviation. Truncation leads to unbiased and positive parameter values. Random walk is a stochastic process, where only the ensemble uncertainty is increased with time, while the expected value remains the same.

Parameters
  • params (numpy.ndarray) – This array of parameters is propagated in time by random walk.

  • noise (float, optional) – This noise level (default = 0.1) is the standard deviation of the truncated Gaussian noise, relative to the parameter values. This noise level has to be between 0 and 1.

  • kwargs (dict) – These additional keyword arguments are not used for this propagation model.

Returns

new_params – These new parameters are given parameters added to the random walk with specified noise level.

Return type

numpy.ndarray

pylawr.transform.inference.gaussian_pdf#

This likelihood corresponds to a Gaussian probability distribution function. Given variance is directly used for the Gaussian PDF.

param y_hat

The predicted observations with the same shape as given observations.

type y_hat

numpy.ndarray

param y_obs

The actual observations, which are used as reference for the predicted observations.

type y_obs

numpy.ndarray

param var

This is the variance for the Gaussian PDF. If this is a float (default=1), the variance is the same for all observations. To specify different uncertainties for different observations, one needs to give an array. This array should have the same size as given observations.

type var

float or numpy.ndarray, optional

param kwargs

Additional keyword arguments which are not used in this function.

type kwargs

dict

returns

likeli – This is the Gaussian negative log likelihood of the predicted observations for given actual observations, normed by the observational variance.

rtype

float

pylawr.transform.inference.laplace_pdf#

This likelihood corresponds to a Laplace probability distribution function. Given variance is automatically converted to the laplacian scaling coefficient.

param y_hat

The predicted observations with the same shape as given observations.

type y_hat

numpy.ndarray

param y_obs

The actual observations, which are used as reference for the predicted observations.

type y_obs

numpy.ndarray

param var

This is the variance for the Laplace PDF. If this is a float (default=1), the variance is the same for all observations. To specify different uncertainties for different observations, one needs to give an array. This array should have the same size as given observations. This variance is automatically converted to the laplacian scaling coefficient.

type var

float or numpy.ndarray, optional

param kwargs

Additional keyword arguments which are not used in this function.

type kwargs

dict

returns

likeli – This is the Laplace negative log likelihood of the predicted observations for given actual observations, normed by the observational laplacian scaling.

rtype

float