mcmc_sampler Derived Type

type, public, extends(chain_builder) :: mcmc_sampler

An implementation of the Metropolis-Hastings algorithm for the generation of a Markov chain.


Type-Bound Procedures

procedure, public :: get_accepted_count => ms_get_num_accepted

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

    Gets the number of accepted steps.

    Arguments

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

    The mcmc_sampler object.

    Return Value integer(kind=int32)

    The number of accepted steps.

procedure, public :: get_chain => cb_get_chain

  • private function cb_get_chain(this, bin, err) result(rst)

    Gets a copy of the stored Markov chain.

    Arguments

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

    The chain_builder object.

    real(kind=real64), intent(in), optional :: bin

    An optional input allowing for a burn-in region. The parameter represents the amount (percentage-based) of the overall chain to disregard as "burn-in" values. The value shoud exist on [0, 1). The default value is 0 such that no values are disregarded.

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

    The error handling object.

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

    The resulting chain with each parameter represented by a column.

procedure, public :: get_chain_length => cb_get_chain_length

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

    Gets the length of the chain (number of stored state variables).

    Arguments

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

    The chain_builder object.

    Return Value integer(kind=int32)

    The chain length.

procedure, public :: get_state_variable_count => cb_get_nvars

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

    Gets the number of state variables.

    Arguments

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

    The chain_builder object.

    Return Value integer(kind=int32)

    The number of state variables.

procedure, public :: on_acceptance => ms_on_success

  • private subroutine ms_on_success(this, iter, alpha, xc, xp, err)

    Currently, this routine does nothing and is a placeholder for the user that inherits this class to provide functionallity upon acceptance of a proposed value.

    Arguments

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

    The mcmc_sampler object.

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

    The current iteration number.

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

    The proposal probabilty term used for acceptance criteria.

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

    An N-element array containing the current state variables.

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

    An N-element array containing the proposed state variables that were just accepted.

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

    An error handling object.

procedure, public :: on_rejection => ms_on_rejection

  • private subroutine ms_on_rejection(this, iter, alpha, xc, xp, err)

    Currently, this routine does nothing and is a placeholder for the user that inherits this class to provide functionallity upon rejection of a proposed value.

    Arguments

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

    The mcmc_sampler object.

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

    The current iteration number.

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

    The proposal probabilty term used for acceptance criteria.

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

    An N-element array containing the current state variables.

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

    An N-element array containing the proposed state variables that were just rejected.

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

    An error handling object.

procedure, public :: push_new_state => cb_push

  • private subroutine cb_push(this, x, err)

    Pushes a new set of state variables onto the buffer.

    Arguments

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

    The chain_builder object.

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

    The new N-element state array.

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

    The error handling object.

procedure, public :: reset => cb_clear_chain

  • private subroutine cb_clear_chain(this)

    Resets the object and clears out the buffer storing the chain values.

    Arguments

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

    The chain_builder object.

procedure, public :: sample => ms_sample

  • private subroutine ms_sample(this, xdata, ydata, prop, tgt, niter, err)

    Samples the distribution using the Metropolis-Hastings approach.

    Arguments

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

    The mcmc_sampler object.

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

    An M-element array containing the independent coordinate data points.

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

    An M-element array containing the dependent coordinate data points.

    class(mcmc_proposal), intent(inout) :: prop

    A proposal generation object.

    class(mcmc_target), intent(inout) :: tgt

    An mcmc_target-based object containing the model and allowing for evaluation of likelihoods.

    integer(kind=int32), intent(in), optional :: niter

    An optional input defining the number of iterations to take. The default is 10,000.

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

    The error handling object.