Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/nested #709

Merged
merged 9 commits into from
May 24, 2023
Prev Previous commit
Next Next commit
adding test
matthewghgriffiths committed May 10, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit d2cbf2232b024a8a14d6c3effe274b77311885f5
23 changes: 23 additions & 0 deletions test_autofit/graphical/functionality/test_factor_graph.py
Original file line number Diff line number Diff line change
@@ -77,6 +77,29 @@ def test_factor_jacobian():
assert np.allclose(ngrad, grad[z_])


def test_nested_factor():
def func(a, b):
a0 = a[0]
c = a[1]['c']
return a0 * c * b

a, b, c = graph.variables("a, b, c")

f = func((1, {'c': 2}), 3)
values = {a: 1, b: 3, c:2}

factor = graph.Factor(func, [a, {'c': c}], b)

assert factor(values) == pytest.approx(f)

fval, grad = factor.func_gradient(values)

assert fval == pytest.approx(f)
assert grad[a] == pytest.approx(6)
assert grad[b] == pytest.approx(2)
assert grad[c] == pytest.approx(3)


class TestFactorGraph:
def test_names(self, sigmoid, phi, compound):
assert sigmoid.name == "log_sigmoid"