CDF_Sampler_t Derived Type

type, public :: CDF_Sampler_t


Contents


Components

Type Visibility Attributes Name Initial
real(kind=dp), private, allocatable :: p(:)

The probabilities.

real(kind=dp), private, allocatable :: cum_p(:)

The cumulated probabilities.

integer, private :: my_size

We store the size in an additional integer, because p and cum_p are allocated empty, if all probabilities are zero.


Constructor

public interface CDF_Sampler_t

  • private pure function construct_CDF_sampler_t(w) result(res)

    Construct a CDF sampler from given weights.

    The weights do not have to be normalized. If all weights are zero, or the array is empty, the sampler will return the (non-existent) index 0 with probability 1.

    Arguments

    Type IntentOptional Attributes Name
    real(kind=dp), intent(in) :: w(:)

    Return Value type(CDF_Sampler_t)

  • private pure function construct_CDF_sampler_with_total_t(w, total) result(res)

    Construct a CDF sampler from given weights.

    The weights do not have to be normalized. If all weights are zero, or the array is empty, the sampler will return the (non-existent) index 0 with probability 1.

    Arguments

    Type IntentOptional Attributes Name
    real(kind=dp), intent(in) :: w(:)
    real(kind=dp), intent(in) :: total

    Return Value type(CDF_Sampler_t)


Type-Bound Procedures

procedure, public :: sample

  • private subroutine sample(this, val, p)

    Return randomly a value val and its probability p.

    Arguments

    Type IntentOptional Attributes Name
    class(CDF_Sampler_t), intent(in) :: this
    integer, intent(out) :: val
    real(kind=dp), intent(out) :: p

procedure, public :: get_prob

  • private elemental function get_prob(this, val)

    Get the probability of a given value val.

    Arguments

    Type IntentOptional Attributes Name
    class(CDF_Sampler_t), intent(in) :: this
    integer, intent(in) :: val

    Return Value real(kind=dp)

procedure, public :: all_zero

  • private elemental function all_zero(this)

    Return if all probabilities are zero, or the set of probabilities is empty.

    Arguments

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

    Return Value logical

procedure, public :: size => get_size

  • private elemental function get_size(this)

    Return the number of probabilites.

    Arguments

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

    Return Value integer