Derived type, extending from the base
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(:) |
Finalize the sampler, deallocate resources
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(weighted_sampler_t), | intent(inout) | :: | this |
Initializes the structure with N weights Input: n - number of weights
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(weighted_sampler_t), | intent(inout) | :: | this | |||
integer(kind=i4), | intent(in) | :: | n |
Initializes with size n and threshold w Input: n - number of weights w - threshold for the weights
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(weighted_sampler_t), | intent(inout) | :: | this | |||
integer(kind=i4), | intent(in) | :: | n | |||
real(kind=dp), | intent(in) | :: | w |
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
Type | Intent | Optional | 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 |
Initializes the structure with N weights Input: n - number of weights
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(weighted_sampler_t), | intent(inout) | :: | this | |||
integer(kind=i4), | intent(in) | :: | n |
Initializes with size n and threshold w Input: n - number of weights w - threshold for the weights
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(weighted_sampler_t), | intent(inout) | :: | this | |||
integer(kind=i4), | intent(in) | :: | n | |||
real(kind=dp), | intent(in) | :: | w |
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
Type | Intent | Optional | 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 |
Resets the sampler: clears the list
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(weighted_sampler_t), | intent(inout) | :: | this |
Sets the weight for a given index Input: index - index of the element with a given weight weight - weight of the element
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(weighted_sampler_t), | intent(inout) | :: | this | |||
integer(kind=i4), | intent(in) | :: | index | |||
real(kind=dp), | intent(in) | :: | weight |
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
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(weighted_sampler_t), | intent(inout) | :: | this | |||
real(kind=dp), | intent(in) | :: | weights(:) |
Adds a weight to the sampler at a given index Input: index - index of the element delta_weight - difference to add to its weight
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(weighted_sampler_t), | intent(inout) | :: | this | |||
integer(kind=i4), | intent(in) | :: | index | |||
real(kind=dp), | intent(in) | :: | delta_weight |
Samples an index from the sampler Input: gen - random number generator (rndgen-fortran module) Output: index - sampled index
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(weighted_sampler_t), | intent(in) | :: | this | |||
class(rndgen), | intent(inout) | :: | gen |
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
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(weighted_sampler_t), | intent(inout) | :: | this | |||
integer(kind=i4), | intent(in) | :: | index |
Get the sum of all weights Output: total - sum of all weights
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(weighted_sampler_t), | intent(in) | :: | this |