Skip to content

cbc2

cbc2_quadratic_terms(cbc2, x, u)

cbc2.mean(x) ≥ √(1-δ)/δ cbc2.k(x,x')

Source code in bayes_cbf/cbc2.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def cbc2_quadratic_terms(cbc2, x, u):
    """
    cbc2.mean(x) ≥ √(1-δ)/δ cbc2.k(x,x')
    """
    # TODO: Too complicated and opaque. Try to find a way to simplify
    mean = lambda up: cbc2(up).mean(x)
    k_func = lambda up: cbc2(up).knl(x, x)

    #assert mean(u) > 0, 'cbf2 should be at least satisfied in expectation'
    mean_A, mean_b = get_affine_terms(mean, u)
    assert not torch.isnan(mean_A).any()
    assert not torch.isnan(mean_b).any()
    k_Q, k_p, k_r = get_quadratic_terms(k_func, u)
    assert not torch.isnan(k_Q).any()
    assert not torch.isnan(k_p).any()
    assert not torch.isnan(k_r).any()
    return (mean_A, mean_b), (k_Q, k_p, k_r), mean(u), k_func(u)