def _initialise_node_cpd( node: str, node_states: Dict[str, List], sm: StructureModel, ) -> pd.DataFrame: """ Initialise the CPD of a specified node Args: node: Node name node_states: States of the node sm: Structure model Returns: CPD dataframe associated with the node Raises: ValueError: if node is not found in the network """ parents = list(sorted(sm.predecessors(node))) columns = [""] if len(parents) > 0: columns = pd.MultiIndex.from_product( [sorted(node_states[p]) for p in parents], names=parents, ) indices = pd.Index(data=sorted(node_states[node]), name=node) values = np.zeros(shape=(len(indices), len(columns))) return pd.DataFrame(index=indices, columns=columns, data=values)
def test_get_indices_empty_iterator(self, schema): graph = StructureModel() # add node without parents: graph.add_node(10) mapper = VariableFeatureMapper(schema) x = mapper.get_indices(graph.predecessors(10)) assert len(x) == 0 assert isinstance(x, list)