weighted_sampler_t Derived Type

type, public, extends(sampler_base_t) :: weighted_sampler_t

Derived type, extending from the base


Inherits

type~~weighted_sampler_t~5~~InheritsGraph type~weighted_sampler_t~5 weighted_sampler_t type~sampler_base_t sampler_base_t type~weighted_sampler_t~5->type~sampler_base_t type~weighted_sampler_t~3 weighted_sampler_t type~weighted_sampler_t~5->type~weighted_sampler_t~3 samplers type~weighted_sampler_t~3->type~sampler_base_t type~dynamical_list_t dynamical_list_t type~weighted_sampler_t~3->type~dynamical_list_t indices

Components

Type Visibility Attributes Name Initial
real(kind=dp), public, allocatable :: weights(:)
integer(kind=i4), public :: n = 0
type(weighted_sampler_t), public :: samplers(2)
real(kind=dp), public :: threshold = huge(dp)
integer(kind=i4), public, allocatable :: sampler_of_index(:)

Finalization Procedures

final :: sampler_finalize

  • private subroutine sampler_finalize(this)

    Finalize the sampler, deallocate resources

    Arguments

    Type IntentOptional Attributes Name
    type(weighted_sampler_t), intent(inout) :: this

Type-Bound Procedures

generic, public :: init => init_n, init_w, init_w2

  • private subroutine sampler_init(this, n)

    Initializes the structure with N weights Input: n - number of weights

    Arguments

    Type IntentOptional Attributes Name
    class(weighted_sampler_t), intent(inout) :: this
    integer(kind=i4), intent(in) :: n
  • private subroutine sampler_init_w(this, n, w)

    Initializes with size n and threshold w Input: n - number of weights w - threshold for the weights

    Arguments

    Type IntentOptional Attributes Name
    class(weighted_sampler_t), intent(inout) :: this
    integer(kind=i4), intent(in) :: n
    real(kind=dp), intent(in) :: w
  • private subroutine sampler_init_w2(this, n, w1, w2)

    Placeholder for 1D initialization (compat mode), maps to original init Input: n - number of weights w1 - any real number, not used w2 - any real number, not used

    Arguments

    Type IntentOptional Attributes Name
    class(weighted_sampler_t), intent(inout) :: this
    integer(kind=i4), intent(in) :: n
    real(kind=dp), intent(in) :: w1
    real(kind=dp), intent(in) :: w2

procedure, public :: init_n => sampler_init

  • private subroutine sampler_init(this, n)

    Initializes the structure with N weights Input: n - number of weights

    Arguments

    Type IntentOptional Attributes Name
    class(weighted_sampler_t), intent(inout) :: this
    integer(kind=i4), intent(in) :: n

procedure, public :: init_w => sampler_init_w

  • private subroutine sampler_init_w(this, n, w)

    Initializes with size n and threshold w Input: n - number of weights w - threshold for the weights

    Arguments

    Type IntentOptional Attributes Name
    class(weighted_sampler_t), intent(inout) :: this
    integer(kind=i4), intent(in) :: n
    real(kind=dp), intent(in) :: w

procedure, public :: init_w2 => sampler_init_w2

  • private subroutine sampler_init_w2(this, n, w1, w2)

    Placeholder for 1D initialization (compat mode), maps to original init Input: n - number of weights w1 - any real number, not used w2 - any real number, not used

    Arguments

    Type IntentOptional Attributes Name
    class(weighted_sampler_t), intent(inout) :: this
    integer(kind=i4), intent(in) :: n
    real(kind=dp), intent(in) :: w1
    real(kind=dp), intent(in) :: w2

procedure, public :: reset => sampler_reset

  • private subroutine sampler_reset(this)

    Resets the sampler: clears the list

    Arguments

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

procedure, public :: set_weight => sampler_set_weight

  • private subroutine sampler_set_weight(this, index, weight)

    Sets the weight for a given index Input: index - index of the element with a given weight weight - weight of the element

    Arguments

    Type IntentOptional Attributes Name
    class(weighted_sampler_t), intent(inout) :: this
    integer(kind=i4), intent(in) :: index
    real(kind=dp), intent(in) :: weight

procedure, public :: set_weight_array => sampler_set_weight_array

  • private subroutine sampler_set_weight_array(this, weights)

    Sets the weights from an array (full), using its indexes Weights should be larger than zero It assumes it was initialized before, and has the same size Input: weights - array with the weights

    Arguments

    Type IntentOptional Attributes Name
    class(weighted_sampler_t), intent(inout) :: this
    real(kind=dp), intent(in) :: weights(:)

procedure, public :: add_weight => sampler_add_weight

  • private subroutine sampler_add_weight(this, index, delta_weight)

    Adds a weight to the sampler at a given index Input: index - index of the element delta_weight - difference to add to its weight

    Arguments

    Type IntentOptional Attributes Name
    class(weighted_sampler_t), intent(inout) :: this
    integer(kind=i4), intent(in) :: index
    real(kind=dp), intent(in) :: delta_weight

procedure, public :: sample => sampler_sample

  • private function sampler_sample(this, gen) result(index)

    Samples an index from the sampler Input: gen - random number generator (rndgen-fortran module) Output: index - sampled index

    Arguments

    Type IntentOptional Attributes Name
    class(weighted_sampler_t), intent(in) :: this
    class(rndgen), intent(inout) :: gen

    Return Value integer(kind=i4)

procedure, public :: remove => sampler_remove

  • private subroutine sampler_remove(this, index)

    Remove an index from the sampler Important: the index is the original one, not the index used internally by the sampler Input: index - index of the element to be removed

    Arguments

    Type IntentOptional Attributes Name
    class(weighted_sampler_t), intent(inout) :: this
    integer(kind=i4), intent(in) :: index

procedure, public :: sum => sampler_sum

  • private function sampler_sum(this) result(total_weight)

    Get the sum of all weights Output: total - sum of all weights

    Arguments

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

    Return Value real(kind=dp)