def _convert_pes_to_pos(hazard_curve, imls):
    """
        For each IML (Intensity Measure Level) given compute the
        PoOs (Probability of Occurence) from the PoEs
        (Probability of Exceendance) defined in the given hazard curve.
    """
    return collect(loop(_compute_pes_from_imls(hazard_curve, imls),
        lambda x, y: subtract(array(x), array(y))))
def _generate_curve(losses, probs_of_exceedance):
    """Generate a loss ratio (or loss) curve, given a set of losses
    and corresponding PoEs (Probabilities of Exceedance).

    This function is intended to be used internally.
    """

    mean_losses = collect(loop(losses, lambda x, y: mean([x, y])))
    return shapes.Curve(zip(mean_losses, probs_of_exceedance))
Exemple #3
0
def _convert_pes_to_pos(hazard_curve, imls):
    """
        For each IML (Intensity Measure Level) given compute the
        PoOs (Probability of Occurence) from the PoEs
        (Probability of Exceendance) defined in the given hazard curve.
    """
    return collect(
        loop(_compute_pes_from_imls(hazard_curve, imls),
             lambda x, y: subtract(array(x), array(y))))
def _compute_imls(vuln_function):
    """
        Computes Intensity Measure Levels considering
        the highest/lowest values a special case
    """

    imls = vuln_function.imls

    # "special" cases for lowest part and highest part of the curve
    lowest_curve_value = imls[0] - ((imls[1] - imls[0]) / 2)
    highest_curve_value = imls[-1] + ((imls[-1] - imls[-2]) / 2)

    between_curve_values = collect(loop(imls, lambda x, y: mean([x, y])))
    
    return [lowest_curve_value] + between_curve_values + [highest_curve_value]
def _split_loss_ratios(loss_ratios, steps=None):
    """Split the loss ratios, producing a new set of loss ratios.

    Keyword arguments:
    steps -- the number of steps we make to go from one loss
    ratio to the next. For example, if we have [1.0, 2.0]:

        steps = 1 produces [1.0, 2.0]
        steps = 2 produces [1.0, 1.5, 2.0]
        steps = 3 produces [1.0, 1.33, 1.66, 2.0]
    """

    if steps is None:
        steps = STEPS_PER_INTERVAL

    splitted_ratios = set()

    for interval in loop(array(loss_ratios), linspace, steps + 1):
        splitted_ratios.update(interval)

    return array(sorted(splitted_ratios))
def _compute_imls(vuln_function):
    """
        Compute the mean IMLs (Intensity Measure Level)
        for the given vulnerability function.
    """

    imls = vuln_function.imls

    # "special" cases for lowest part and highest part of the curve
    lowest_curve_value = imls[0] - ((imls[1] - imls[0]) / 2)

    # if the calculated lowest_curve_value goes < 0 we have to force the 0
    # IMLs have to be >= 0
    if lowest_curve_value < 0:
        lowest_curve_value = 0

    highest_curve_value = imls[-1] + ((imls[-1] - imls[-2]) / 2)

    between_curve_values = collect(loop(imls, lambda x, y: mean([x, y])))

    return [lowest_curve_value] + between_curve_values + [highest_curve_value]
Exemple #7
0
def _compute_imls(vuln_function):
    """
        Compute the mean IMLs (Intensity Measure Level)
        for the given vulnerability function.
    """

    imls = vuln_function.imls

    # "special" cases for lowest part and highest part of the curve
    lowest_curve_value = imls[0] - ((imls[1] - imls[0]) / 2)

    # if the calculated lowest_curve_value goes < 0 we have to force the 0
    # IMLs have to be >= 0
    if lowest_curve_value < 0:
        lowest_curve_value = 0

    highest_curve_value = imls[-1] + ((imls[-1] - imls[-2]) / 2)

    between_curve_values = collect(loop(imls, lambda x, y: mean([x, y])))

    return [lowest_curve_value] + between_curve_values + [highest_curve_value]
Exemple #8
0
def _split_loss_ratios(loss_ratios, steps=None):
    """Split the loss ratios, producing a new set of loss ratios.

    Keyword arguments:
    steps -- the number of steps we make to go from one loss
    ratio to the next. For example, if we have [1.0, 2.0]:

        steps = 1 produces [1.0, 2.0]
        steps = 2 produces [1.0, 1.5, 2.0]
        steps = 3 produces [1.0, 1.33, 1.66, 2.0]
    """

    if steps is None:
        steps = STEPS_PER_INTERVAL

    splitted_ratios = set()

    for interval in loop(array(loss_ratios), linspace, steps + 1):
        splitted_ratios.update(interval)

    return array(sorted(splitted_ratios))
def _convert_pes_to_pos(hazard_curve, imls):
    """
        Computes the probability occurences from the probability exceedances
    """
    return collect(loop(_compute_pes_from_imls(hazard_curve, imls), 
        lambda x, y: subtract(array(x), array(y))))