# Check None cases
assert dbn_writer() is None
assert dbn_writer(exact=True) is None
# Check passthrough
= GraphvizFormatting()
writer
test_eq(dbn_writer(writer), writer)False)
test_eq(has_positions(writer),
# Check boxes, and that they don't stomp
= dbn_writer(boxes={1, 2})
writer 1, 2})
test_eq(writer.boxes, {= dbn_writer(writer, boxes={2, 3})
writer 1, 2, 3})
test_eq(writer.boxes, {False)
test_eq(has_positions(writer),
# Check hints, and that they don't stomp
= dbn_writer(hints={"A": 2})
writer "A": 2})
test_eq(writer.positionHints, {= dbn_writer(writer, hints={"A": 3})
writer "A": 2})
test_eq(writer.positionHints, {True)
test_eq(has_positions(writer),
# Check positions, and that they don't stomp
= 123
key = dbn_writer(positions={key: (2, 0)})
writer len(writer.variablePositions), 1)
test_eq(= dbn_writer(writer, positions={key: (3, 0)})
writer len(writer.variablePositions), 1)
test_eq(2, 0))
test_eq(writer.variablePositions[key], (True)
test_eq(has_positions(writer),
# Check factor positions, and that they don't stomp
= 0
i = dbn_writer(factor_positions={i: (2, 0)})
writer len(writer.factorPositions), 1)
test_eq(= dbn_writer(writer, factor_positions={i: (3, 0)})
writer len(writer.factorPositions), 1)
test_eq(2, 0))
test_eq(writer.factorPositions[i], (True) test_eq(has_positions(writer),
dbn
Support code for Dynamic Bayesian Networks (DBNs)
The only code defined here is intended for internal use in gtbook display
. If you have a need to use it, you can import it as follows:
from gtbook.dbn import dbn_writer, has_positions
Create or amend a DotWriter to be use in show:
has_positions
has_positions (writer)
Check if writer has positions for engine selection
dbn_writer
dbn_writer (writer=None, hints:dict=None, positions:dict=None, boxes:set=None, factor_positions:dict=None, binary_edges=False, **kwargs)
Create a DotWriter depending on input arguments: If writer is supplied, we will add but not overwrite hints or positions.