# MCMC (Delayed Rejection Adaptive Metropolis Algorithm)

This is an implementation of the *Delayed Rejection Adaptive Metropolis* algorithm,
as published in Haario2006.
This solver can also be configured to run the standard *Metropolis Hastings* method.

## Usage

`e["Solver"]["Type"] = "Sampler/MCMC"`

## Results

These are the results produced by this solver:

- Sample Database
**Usage**: e[“Results”][“Sample Database”] = List of Lists of*real number***Description**: Collection of samples describing the probability distribution.

## Variable-Specific Settings

These are settings required by this module that are added to each of the experiment’s variables when this module is selected.

- Initial Mean
**Usage**: e[“Variables”][*index*][“Initial Mean”] =*real number***Description**: Specifies the Initial Mean of the proposal distribution.

- Initial Standard Deviation
**Usage**: e[“Variables”][*index*][“Initial Standard Deviation”] =*real number***Description**: Specifies the Standard Deviation for each variable. The proposal distribution is defined through a covariance matrix with the variance of the variables in its diagonal.

- Lower Bound
**Usage**: e[“Variables”][*index*][“Lower Bound”] =*real number***Description**: Specifies the lower bound for the variable’s value.

- Upper Bound
**Usage**: e[“Variables”][*index*][“Upper Bound”] =*real number***Description**: Specifies the upper bound for the variable’s value.

- Initial Value
**Usage**: e[“Variables”][*index*][“Initial Value”] =*real number***Description**: Defines the initial value at or around which the algorithm shall start looking for an optimum.

## Configuration

These are settings required by this module.

- Burn In
**Usage**: e[“Solver”][“Burn In”] =*unsigned integer***Description**: Specifies the number of preliminary MCMC steps before samples are being drawn. This may reduce effects from improper initialization.

- Leap
**Usage**: e[“Solver”][“Leap”] =*unsigned integer***Description**: Generates a Markov Chain containing samples from every ‘Leap’-th step. This will increase the overall Chain Length by a factor of ‘Leap’.

- Rejection Levels
**Usage**: e[“Solver”][“Rejection Levels”] =*unsigned integer***Description**: Controls the number of accept-reject stages per MCMC step (by default, this value is set 1, for values greater 1 the delajed rejection algorithm is active.

- Use Adaptive Sampling
**Usage**: e[“Solver”][“Use Adaptive Sampling”] =*True/False***Description**: Specifies if covariance matrix of the proposal distribution is calculated from the samples.

- Non Adaption Period
**Usage**: e[“Solver”][“Non Adaption Period”] =*unsigned integer***Description**: Number of steps (after Burn In steps) during which the initial covariance is used instead of the Chain Covariance. If 0 (default) is specified, this value is calibrated as $5%$ of the Max Chain Length (only relevant for Adaptive Sampling).

- Chain Covariance Scaling
**Usage**: e[“Solver”][“Chain Covariance Scaling”] =*real number***Description**: Learning rate of the Chain Covariance (only relevant for Adaptive Sampling).

## Termination Criteria

These are the customizable criteria that indicates whether the solver should continue or finish execution. Korali will stop when at least one of these conditions are met. The criteria is expressed in C++ since it is compiled and evaluated as seen here in the engine.

- Max Samples
**Usage**: e[“Solver”][“Max Samples”] =*unsigned integer***Description**: Number of Samples to Generate.**Criteria**:`_sampleDatabase.size() >= _maxSamples`

- Max Model Evaluations
**Usage**: e[“Solver”][“Max Model Evaluations”] =*unsigned integer***Description**: Specifies the maximum allowed evaluations of the computational model.**Criteria**:`_maxModelEvaluations <= _modelEvaluationCount`

- Max Generations
**Usage**: e[“Solver”][“Max Generations”] =*unsigned integer***Description**: Determines how many solver generations to run before stopping execution. Execution can be resumed at a later moment.**Criteria**:`_k->_currentGeneration > _maxGenerations`

## Default Configuration

These following configuration will be assigned by default. Any settings defined by the user will override the given settings specified in these defaults.

{ "Burn In": 0, "Chain Covariance Scaling": 1.0, "Leap": 1, "Model Evaluation Count": 0, "Non Adaption Period": 0, "Normal Generator": { "Mean": 0.0, "Standard Deviation": 1.0, "Type": "Univariate/Normal" }, "Rejection Levels": 1, "Termination Criteria": { "Max Generations": 10000000000, "Max Model Evaluations": 1000000000, "Max Samples": 5000 }, "Uniform Generator": { "Maximum": 1.0, "Minimum": 0.0, "Type": "Univariate/Uniform" }, "Use Adaptive Sampling": false, "Variable Count": 0 }

## Variable Defaults

These following configuration will be assigned to each of the experiment variables by default. Any settings defined by the user will override the given settings specified in these defaults.

{ "Initial Value": -Infinity, "Lower Bound": -Infinity, "Upper Bound": Infinity }