def create(self, network_factory): network = network_factory.create() cluster = builder.try_get_node(network, "Cluster") if cluster is None: cluster = builder.create_cluster_variable( network, self._latent_states, variable_name=self._latent_variable_name) if not dk.empty(self._continuous): for c_name in self._continuous.columns: self._logger.info("Pre-processing {} column".format(c_name)) c = builder.create_continuous_variable(network, c_name) try: builder.create_link(network, cluster, c) except ValueError as e: self._logger.warn(e) if not dk.empty(self._discrete): for d_name in self._discrete.columns: if d_name in self._discrete_states: states = self._discrete_states[str(d_name)] else: states = dk.compute(self._discrete[str( d_name)].dropna().unique()).tolist() try: c = builder.create_discrete_variable( network, self._discrete, str(d_name), states) builder.create_link(network, cluster, c) except BaseException as e: self._logger.warn(e) return network
def create(self, network_factory): network = network_factory.create() if not dk.empty(self._continuous): for c_name in self._continuous.columns: c = builder.create_continuous_variable(network, c_name) if dk.empty(self._discrete): for d_name in self._discrete.columns: if d_name in self._discrete_states: states = self._discrete_states[d_name] else: states = dk.compute( self._discrete[d_name].dropna().unique()).tolist() try: c = builder.create_discrete_variable( network, self._discrete, d_name, states) except BaseException as e: self._logger.warn(e) parent_node = builder.try_get_node(network, self._parent_node) if parent_node is None: raise ValueError("Parent node: {} not recognised".format( self._parent_node)) for node in network.getNodes(): if node == parent_node: continue builder.create_link(network, parent_node, node) return network