def test_dfe_parameters(): dag = DAG.from_modelstring('[A]') dag.vs['levels'] = [["A", "B"] for v in dag.vs] data = pd.DataFrame({'A': [0, 0]}) dag.estimate_parameters(data, method="dfe", method_args={ "iterations": 1, "learning_rate": 0.1 }) assert np.array_equal(dag.vs[0]['CPD'].cumsum_array, np.array([0.55, 1]))
def test_bif_parser(): bif_path = (Path(__file__).parent.parent / 'baynet' / 'utils' / 'bif_library' / 'earthquake.bif').resolve() dag = dag_from_bif(bif_path) earthquake_dag = DAG.from_modelstring( "[Alarm|Burglary:Earthquake][Burglary][Earthquake][JohnCalls|Alarm][MaryCalls|Alarm]" ) assert dag.nodes == earthquake_dag.nodes assert dag.edges == earthquake_dag.edges dag.sample(10) with pytest.raises(ValueError): dag = dag_from_bif("foo") with pytest.raises(ValueError): dag = dag_from_bif(Path("foo"))
def partial_dag() -> DAG: return DAG.from_modelstring("[A][B|C:D][C][D]")
def reversed_dag() -> DAG: return DAG.from_modelstring(REVERSED_MODELSTRING)
def test_dag() -> DAG: return DAG.from_modelstring(TEST_MODELSTRING)