Exemple #1
0
def birnbaum_importance(sg: SystemGraph, p, bdd_with_root=None, select=None):
    b_imps = {}

    if select is not None:
        for i in select:
            p[i] = 1.0
        risk_top = risk_by_bdd(sg, p, bdd_with_root)

        for i in select:
            p[i] = 0.0
        risk_bottom = risk_by_bdd(sg, p, bdd_with_root)

        b_imps["select"] = risk_top - risk_bottom
        return b_imps

    for i in sg.nodes:
        saved = p[i]
        p[i] = 1.0
        risk_top = risk_by_bdd(sg, p, bdd_with_root)
        p[i] = 0.0
        risk_bottom = risk_by_bdd(sg, p, bdd_with_root)
        b_imps[i] = risk_top - risk_bottom
        p[i] = saved  # restore to initial state

    del b_imps["indicator"]
    return b_imps
Exemple #2
0
def test_risk_by_bdd_minimal(minimal: SystemGraph):
    assert (risk_by_bdd(minimal, {
        "indicator": 0,
        "x1": 0,
        "x2": 0,
        "x3": 0
    }) == 0)
    assert (risk_by_bdd(minimal, {
        "indicator": 0,
        "x1": 0,
        "x2": 0,
        "x3": 1
    }) == 1)
    assert (risk_by_bdd(minimal, {
        "indicator": 0,
        "x1": 0,
        "x2": 1,
        "x3": 0
    }) == 0)
    assert (risk_by_bdd(minimal, {
        "indicator": 0,
        "x1": 1,
        "x2": 0,
        "x3": 0
    }) == 0)
    assert (risk_by_bdd(minimal, {
        "indicator": 0,
        "x1": 1,
        "x2": 1,
        "x3": 0
    }) == 1)
    assert (risk_by_bdd(minimal, {
        "indicator": 0,
        "x1": 1,
        "x2": 1,
        "x3": 1
    }) == 1)
    assert (risk_by_bdd(minimal, {
        "indicator": 0,
        "x1": 0,
        "x2": 0,
        "x3": 0
    }) == 0)
    assert (risk_by_bdd(minimal, {
        "indicator": 0,
        "x1": .5,
        "x2": .5,
        "x3": 0
    }) == .25)
    assert (risk_by_bdd(minimal, {
        "indicator": 0,
        "x1": 0,
        "x2": 0,
        "x3": .25
    }) == .25)
Exemple #3
0
def test_e2e_supplier_choice_solve_bad_supplier_risk(
        full_with_supplier_choices: SystemGraph,
        full_with_supplier_choices_data):
    bad = full_with_supplier_choices_data["edges"][0]
    bad["risk"] = 0.99
    before = risk_by_bdd(
        full_with_supplier_choices,
        provide_p_direct_from_data(full_with_supplier_choices,
                                   full_with_supplier_choices_data))
    prob = SupplierChoiceProblem(full_with_supplier_choices,
                                 full_with_supplier_choices_data)
    results = prob.solve({"alpha": 0.01, "budget": 500})
    updated = full_with_supplier_choices.with_suppliers(results[0])
    assert Edge(src=bad["src"], dst=bad["dst"]) not in updated.edges
    after = risk_by_bdd(
        updated,
        provide_p_direct_from_data(updated, full_with_supplier_choices_data))
    assert before > after
Exemple #4
0
def get_risk(sg: SystemGraph, data: Dict, prefs=None) -> Dict[str, float]:
    bdd_with_root = sg.get_bdd_with_root()
    validate_data(sg, data)
    p = provide_p_direct_from_data(sg, data)
    risk = risk_by_bdd(sg, p, bdd_with_root=bdd_with_root)
    return {"system": risk}
Exemple #5
0
def test_risk_by_bdd_diamond(diamond: SystemGraph):
    assert approx(
        risk_by_bdd(diamond, provide_p_unknown_data(diamond)) == 0.625)
Exemple #6
0
def test_risk_by_bdd_canonical(canonical: SystemGraph):
    assert approx(
        risk_by_bdd(canonical, provide_p_unknown_data(canonical)) ==
        0.9748495630919933)