AliasTable_t Derived Type

type, public :: AliasTable_t

This class implements the Walker-Vose Alias Sampling method.

The initializing weights do not have to be normalized. The algorithm is described here

The class does not store the probabilities themselves. Look to AliasSampler_t for this additional feature.


Contents


Components

Type Visibility Attributes Name Initial
type(shared_array_real_t), private :: bias

this is the table of bias

type(shared_array_int32_t), private :: alias

this is the lookup table for the resulting random number


Type-Bound Procedures

procedure, public :: setup => setup_AliasTable_t

constructor

  • private subroutine setup_AliasTable_t(this, rank_with_info, arr)

    pseudo-constructor for alias tables

    Arguments

    Type IntentOptional Attributes Name
    class(AliasTable_t), intent(inout) :: this
    integer, intent(in) :: rank_with_info

    The intra-node rank that contains the weights to be used all other arr of all other ranks are ignored (and can be allocated with size 0).

    real(kind=dp), intent(in) :: arr(:)

    arr array containing the (not necessarily normalized) probabilities we want to use for sampling

procedure, private, :: init => init_AliasTable_t

only compute the data, without allocation

  • private subroutine init_AliasTable_t(this, rank_with_info, arr)

    Set the bias and alias values for each value in range @param[in] arr - array containing the (not necessarily normalized) probabilities we want to use for sampling

    Arguments

    Type IntentOptional Attributes Name
    class(AliasTable_t), intent(inout) :: this
    integer, intent(in) :: rank_with_info

    The intra-node rank that contains the weights to be used all other arr of all other ranks are ignored (and can be allocated with size 0).

    real(kind=dp), intent(in) :: arr(:)

procedure, public :: finalize => finalize_AliasTable_t

destructor - final would be suited better, but is not supported by all compilers

  • private subroutine finalize_AliasTable_t(this)

    clear the memory used by the alias table

    Arguments

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

procedure, public :: sample => sample_AliasTable_t

get a random value from the alias table

  • private function sample_AliasTable_t(this) result(ind)

    Draw a random number from an alias table created with the corresponding probabilities @return ind random number between 1 and the size of the array used to create the aliasTable object

    Arguments

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

    Return Value integer