constrained_getProb Function

private pure function constrained_getProb(this, contain, renorm, tgt) result(prob)

Returns the probability to draw tgt from this sampler @param[in] tgt the number for which we request the probability of sampling @param[in] constraint pick only elements from constraint (has to be a set, i.e. unique and ordered) @param[out] prob the probability of picking tgt from constraint the probability of drawing anything from an empty sampler is 0

Type Bound

AliasSampler_t

Arguments

Type IntentOptional Attributes Name
class(AliasSampler_t), intent(in) :: this
integer, intent(in) :: contain(:)
real(kind=dp), intent(in) :: renorm
integer, intent(in) :: tgt

Return Value real(kind=dp)

This loosened threshhold might be a good idea if the renormalization was calculated via the complement, i.e. \Sum{ p_i } {i \in D_i} = 1 - \Sum{ p_i } {i \notin D_i}


Contents

Source Code


Source Code

    pure function constrained_getProb(this, contain, renorm, tgt) result(prob)
        class(AliasSampler_t), intent(in) :: this
        integer, intent(in) :: contain(:)
        real(dp), intent(in) :: renorm
        integer, intent(in) :: tgt
        character(*), parameter :: this_routine = 'constrained_getProb'
        real(dp) :: prob

        ASSERT(is_set(contain))
        ASSERT(1 <= contain(1) .and. contain(size(contain)) <= size(this%probs%ptr))
        ASSERT(isclose(renorm, sum(this%get_prob(contain)), atol=1e-10_dp))
            !! This loosened threshhold might be a good idea if the renormalization
            !! was calculated via the complement, i.e.
            !! \Sum{ p_i } {i \in D_i} = 1 - \Sum{ p_i } {i \notin D_i}

        if (near_zero(renorm)) then
            !! the probability of drawing anything from an empty sampler is 0
            prob = 0.0
        else
            prob = this%probs%ptr(tgt) / renorm
        end if
    end function constrained_getProb