gfn.gym.bayesian_structure ========================== .. py:module:: gfn.gym.bayesian_structure Classes ------- .. autoapisummary:: gfn.gym.bayesian_structure.BayesianStructure Module Contents --------------- .. py:class:: BayesianStructure(n_nodes, state_evaluator, device = 'cpu', debug = False) Bases: :py:obj:`gfn.gym.graph_building.GraphBuilding` Environment for incrementally building a directed acyclic graph (DAG) for Bayesian structure learning (Deleu et al., 2022). The environment allows the following actions: - Adding edges between existing nodes with features - Terminating construction (EXIT) :param n_nodes: Number of nodes in the graph. :param state_evaluator: Callable that computes rewards for final states. If None, uses default GCNConvEvaluator :param device_str: Device to run computations on ('cpu' or 'cuda') .. py:method:: backward_step(states, actions) Performs a backward step in the environment. :param states: The current states. :param actions: The actions to undo. :returns: The previous states. .. py:method:: is_action_valid(states, actions, backward = False) Check if actions are valid for the given states. :param states: Current graph states. :param actions: Actions to validate. :param backward: Whether this is a backward step. :returns: True if all actions are valid, False otherwise. .. py:method:: log_reward(final_states) The environment's reward given a state. This or log_reward must be implemented. :param final_states: A batch of final states. :returns: Tensor of shape "batch_shape" containing the rewards. :rtype: torch.Tensor .. py:method:: make_actions_class() Returns the GraphActions class for this environment. :returns: A type of a subclass of GraphActions with environment-specific functionalities. .. py:method:: make_random_states_tensor(batch_shape, conditions = None, device = None) Makes a batch of random DAG states with fixed number of nodes. :param batch_shape: Shape of the batch dimensions. :param conditions: Optional tensor of shape (*batch_shape, condition_dim) containing condition vectors for conditional GFlowNets. :param device: The device to create the graph states on. :returns: A PyG Batch object containing random DAG states. .. py:method:: make_states_class() Creates a `GraphStates` class for this environment. .. py:attribute:: n_actions .. py:attribute:: n_nodes .. py:method:: reward(final_states) :abstractmethod: The environment's reward given a state. :param final_states: A batch of final states. :returns: A tensor of shape `(batch_size,)` containing the rewards. .. py:method:: step(states, actions) Performs a step in the environment. :param states: The current states. :param actions: The actions to take. :returns: The next states.