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 |
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.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=dp), | intent(in) | :: | w(:) |
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.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=dp), | intent(in) | :: | w(:) | |||
real(kind=dp), | intent(in) | :: | total |
Return randomly a value val
and its probability p
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(CDF_Sampler_t), | intent(in) | :: | this | |||
integer, | intent(out) | :: | val | |||
real(kind=dp), | intent(out) | :: | p |
Get the probability of a given value val
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(CDF_Sampler_t), | intent(in) | :: | this | |||
integer, | intent(in) | :: | val |
Return if all probabilities are zero, or the set of probabilities is empty.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(CDF_Sampler_t), | intent(in) | :: | this |
Return the number of probabilites.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(CDF_Sampler_t), | intent(in) | :: | this |