Processing math: 100%

mcmc_target Derived Type

type, public, abstract :: mcmc_target

Defines a model of the target distribution(s). This type is key to the MCMC regression process. The approach taken is to evaluate the model provided here and evaluating its likelihood. The likelihood is evaluated by computing the residual between the model and data, and making the assumption that the residual should be normally distributed.

L=ni=1lnN(yi|f(xi,θ),σ)

The logarithm of the results of the normal distribution are used as the scale of values can be quite extreme, especially if the model is far from the actual data; therefore, to avoid scaling induced overflow or underflow errors the logarithmic likelihood is utilized. The σ term results from the data_noise parameter and is a representation of just that, the noise in the data. The square of this parameter can also be referred to as the variance prior. The default utilized here within is to assume the variance prior is logarithmically distributed, and as such, is never negative-valued.


Contents


Components

Type Visibility Attributes Name Initial
real(kind=real64), public :: data_noise = 1.0d0

A parameter representing the noise in the data.


Type-Bound Procedures

procedure, public :: add_parameter => mt_add_param

  • private subroutine mt_add_param(this, x, err)

    Adds a new model parameter.

    Arguments

    Type IntentOptional Attributes Name
    class(mcmc_target), intent(inout) :: this

    The mcmc_target object.

    class(distribution), intent(in) :: x

    The parameter to add.

    class(errors), intent(inout), optional, target :: err

    The error handler object.

procedure, public :: evaluate_prior => mt_eval_prior

  • private function mt_eval_prior(this, x, err) result(rst)

    Evaluates the PDF's for each parameter and computes a probability.

    Arguments

    Type IntentOptional Attributes Name
    class(mcmc_target), intent(in) :: this

    The mcmc_target object.

    real(kind=real64), intent(in), dimension(:) :: x

    An N-element array containing the values at which to evaluate each of the N parameter PDF's.

    class(errors), intent(inout), optional, target :: err

    An error handling object.

    Return Value real(kind=real64)

    The resulting probability.

procedure, public :: evaluate_variance_prior => mt_eval_var_prior

  • private pure function mt_eval_var_prior(this, x) result(rst)

    Evalautes the model variance prior PDF.

    Arguments

    Type IntentOptional Attributes Name
    class(mcmc_target), intent(in) :: this

    The mcmc_target object.

    real(kind=real64), intent(in) :: x

    The value at which to evaluate the variance prior distribution PDF.

    Return Value real(kind=real64)

    The value of the variance prior distribution's PDF.

procedure, public :: get_parameter => mt_get_param

  • private function mt_get_param(this, i) result(rst)

    Gets a pointer to the stored parameter.

    Arguments

    Type IntentOptional Attributes Name
    class(mcmc_target), intent(in) :: this

    The mcmc_target object.

    integer(kind=int32), intent(in) :: i

    The index of the parameter to retrieve. If outside the bounds of the collection of parameters a null pointer is returned.

    Return Value class(distribution), pointer

    A pointer to the requested parameter distribution.

procedure, public :: get_parameter_count => mt_get_param_count

  • private pure function mt_get_param_count(this) result(rst)

    Gets the number of model parameters.

    Arguments

    Type IntentOptional Attributes Name
    class(mcmc_target), intent(in) :: this

    The mcmc_target object.

    Return Value integer(kind=int32)

    The parameter count.

procedure, public :: likelihood => mt_likelihood

  • private function mt_likelihood(this, xdata, ydata, xc, var, err) result(rst)

    Computes the target likelihood.

    Arguments

    Type IntentOptional Attributes Name
    class(mcmc_target), intent(inout) :: this

    The mcmc_target object.

    real(kind=real64), intent(in), dimension(:) :: xdata

    An M-element array containing the independent data points.

    real(kind=real64), intent(in), dimension(:) :: ydata

    An M-element array containing the dependent data points.

    real(kind=real64), intent(in), dimension(:) :: xc

    An N-element array containing the model parameters.

    real(kind=real64), intent(in) :: var

    An estimate of the model variance.

    class(errors), intent(inout), optional, target :: err

    An error handling object.

    Return Value real(kind=real64)

    The likelihood value.

procedure(evaluate_model), public, deferred :: model

  • subroutine evaluate_model(this, xdata, xc, y) Prototype

    Evaluates the model at the supplied values.

    Arguments

    Type IntentOptional Attributes Name
    class(mcmc_target), intent(in) :: this

    The mcmc_target object.

    real(kind=real64), intent(in), dimension(:) :: xdata

    An M-element array containing the values at which to evaluate the model.

    real(kind=real64), intent(in), dimension(:) :: xc

    An N-element array containing the model parameters.

    real(kind=real64), intent(out), dimension(:) :: y

    An M-element array where the resulting model values wil be written.

procedure, public :: sample_variance_prior => mt_sample_var_prior

  • private function mt_sample_var_prior(this, vc, n) result(rst)

    Samples the variance prior distribution for the requested number of samples.

    Arguments

    Type IntentOptional Attributes Name
    class(mcmc_target), intent(inout) :: this

    The mcmc_target object.

    real(kind=real64), intent(in) :: vc

    The prior variance term.

    integer(kind=int32), intent(in) :: n

    The number of samples.

    Return Value real(kind=real64), allocatable, dimension(:)

    The requested samples.