Ejemplo n.º 1
0
def test_cyclic_assignment():
    chi = And(GE(x, Real(0)), LE(x, Real(1)), Equals(x, y), Equals(y, x))
    wmi = WMI(chi)
    
    with pytest.raises(WMIParsingException) as ex:
        result, _ = wmi.computeMI(phi)
    assert ex.value.code == WMIParsingException.CYCLIC_ASSIGNMENT_IN_ALIASES
Ejemplo n.º 2
0
def test_invalid_mode():
    chi = Bool(True)
    wmi = WMI(chi)
    
    with pytest.raises(WMIRuntimeException) as ex:
        result_allsmt, _ = wmi.computeMI(phi, mode="mode")
    assert ex.value.code == WMIRuntimeException.INVALID_MODE
Ejemplo n.º 3
0
def test_conversion_pysmt_to_sympy():
    chi = LE(Min(Real(5), Real(2)), x)
    wmi = WMI(chi)
    
    with pytest.raises(WMIParsingException) as ex:
        result, _ = wmi.computeMI(phi)
    assert ex.value.code == WMIParsingException.CANNOT_CONVERT_PYSMT_FORMULA_TO_SYMPY
Ejemplo n.º 4
0
def test_not_correct_alias():
    chi = And(GE(x, Real(0)), LE(x, Real(1)), Equals(Plus(x, Real(3)), Plus(y, Real(2))))
    wmi = WMI(chi)
    
    with pytest.raises(WMIParsingException) as ex:
        result, _ = wmi.computeMI(phi)
    assert ex.value.code == WMIParsingException.MALFORMED_ALIAS_EXPRESSION
Ejemplo n.º 5
0
def test_double_assignments_same_variable():
    chi = And(GE(x, Real(0)), LE(x, Real(1)), GE(y, Real(0)), LE(y, Real(1)), Equals(z, Plus(x, Real(3))), Equals(z, Plus(y, Real(2))))
    wmi = WMI(chi)
    
    with pytest.raises(WMIParsingException) as ex:
        result_allsmt, _ = wmi.computeMI(phi, mode=WMI.MODE_ALLSMT)
    assert ex.value.code == WMIParsingException.MULTIPLE_ASSIGNMENT_SAME_ALIAS
Ejemplo n.º 6
0
def test_wrong_domX():
    chi = And(GE(x, Real(0)), LE(x, Real(1)), a)
    wmi = WMI(chi)
    domX = set()
    
    with pytest.raises(WMIRuntimeException) as ex:
        result_allsmt, _ = wmi.computeMI(phi, domX=domX)
    assert ex.value.code == WMIRuntimeException.DOMAIN_OF_INTEGRATION_MISMATCH
Ejemplo n.º 7
0
def test_invalid_weight_function():
    chi = And(GE(x, Real(0)), LE(x, Real(1)))
    w = GE(x, Real(2))
    
    with pytest.raises(WMIParsingException) as ex:
        wmi = WMI(chi, w)
    assert ex.value.code == WMIParsingException.INVALID_WEIGHT_FUNCTION
Ejemplo n.º 8
0
def run_pa(density, n_bins, log_path):
    formula = density.support
    weight = density.weight
    CACHE = False

    #log_path = join(output_folder, f"{name}-gt-PA.json")
    if not isfile(log_path):
        print("Running WMI-PA")

        wmipa = WMI(density.support, density.weight)
        Z_pa, _ = wmipa.computeWMI(Bool(True), mode=WMI.MODE_PA, cache=CACHE)

        gt_marginals = {}
        for xvar in density.domain.get_real_symbols():
            x = xvar.symbol_name()
            gt_marginals[x] = []
            low, up = density.domain.var_domains[x]
            slices = [(i / n_bins) * (up - low) + low
                      for i in range(0, n_bins + 1)]
            for i in range(len(slices) - 1):
                l, u = slices[i], slices[i + 1]
                gt_q = And(LE(Real(l), xvar), LE(xvar, Real(u)))
                gt_vol, _ = wmipa.computeWMI(gt_q,
                                             mode=WMI.MODE_PA,
                                             cache=CACHE)
                gt_marginals[x].append((l, u, gt_vol / Z_pa))

        with open(log_path, 'w') as log_file:
            json.dump(gt_marginals, log_file, indent=2)

    else:
        print(f"Found {log_path}")
        with open(log_path, 'r') as log_file:
            gt_marginals = json.load(log_file)

    return gt_marginals