gflownet.envs.choices ===================== .. py:module:: gflownet.envs.choices .. autoapi-nested-parse:: An environment to sample a selection of elements from a given set of options. The configuration of the environment must determine not only the set of options, but the maximum number of elements to be sampled, whether fewer than the maximum can be sampled and whether the selection must proceed with or without replacement. If the selection is with replacement, then the environment operates as a SetFlex (without constraints). If the selection is without replacement, then the environment operates as a SetFix with constraints, such that options that have been already selected are made unavailable in the remaining environments. Classes ------- .. autoapisummary:: gflownet.envs.choices.ChoicesBase gflownet.envs.choices.ChoicesSetFix gflownet.envs.choices.ChoicesSetFlex Functions --------- .. autoapisummary:: gflownet.envs.choices.Choices Module Contents --------------- .. py:function:: Choices(options = None, n_options = 3, max_selection = 2, can_select_fewer_than_max = False, with_replacement = True, source_readable = '', **kwargs) Factory method to instantiate a Choices environment. :param options: The descrption of the options. If None, the options are simply described by their indices. In this case, ``n_options`` must be not None. :type options: iterable (optional) :param n_options: The number of options, if ``options`` is None. Ignored otherwise. :type n_options: int :param max_selection: The maximum number of options that may be selected. :type max_selection: int :param can_select_fewer_than_max: Whether fewer options than the maximum can be selected. :type can_select_fewer_than_max: bool :param with_replacement: Whether the selection proceeds with replacement (True, the same option can be selected more than once) or without replacement (False, each option can be selected only once). :type with_replacement: bool :param source_readable: The string to be used to represent the source state as a human-readable string. By default: :type source_readable: str .. py:class:: ChoicesBase(options = None, n_options = 3, max_selection = 2, can_select_fewer_than_max = False, with_replacement = True, source_readable = '', **kwargs) Initializes a Choices environment. :param options: The descrption of the options. If None, the options are simply described by their indices. In this case, ``n_options`` must be not None. :type options: iterable (optional) :param n_options: The number of options, if ``options`` is None. Ignored otherwise. :type n_options: int :param max_selection: The maximum number of options that may be selected. :type max_selection: int :param can_select_fewer_than_max: Whether fewer options than the maximum can be selected. :type can_select_fewer_than_max: bool :param with_replacement: Whether the selection proceeds with replacement (True, the same option can be selected more than once) or without replacement (False, each option can be selected only once). :type with_replacement: bool :param source_readable: The string to be used to represent the source state as a human-readable string. By default: :type source_readable: str .. py:attribute:: max_selection :value: 2 .. py:attribute:: can_select_fewer_than_max :value: False .. py:attribute:: with_replacement :value: True .. py:attribute:: options .. py:attribute:: n_options .. py:attribute:: source_readable .. py:property:: choice_env :type: gflownet.envs.choice.Choice Returns the unique Choice environment. :returns: *Choice* -- The Choice environment that serves as unique environment of the Set. .. py:method:: get_options(state = None) Returns all the options that have already been chosen from the state. :param state: A state of the global set environment. :type state: dict :returns: *The set of options, as a tuple of integers.* .. py:method:: states2policy(states) Prepares a batch of states in environment format for the policy model. The policy representation is the concatenation of the following elements: - A flag indicating whether no environment is active (-1), an environment is active and not done (0), or an environment is active but done (1). - A vector of length ``self.n_options`` with the count of each selected option. :param states: A batch of states in environment format. :type states: list :returns: *A tensor containing all the states in the batch.* .. py:class:: ChoicesSetFix(*args, **kwargs) Bases: :py:obj:`ChoicesBase`, :py:obj:`gflownet.envs.composite.setfix.SetFix` Initializes a ChoicesSetFix environment inheriting from the SetFix. .. py:class:: ChoicesSetFlex(*args, **kwargs) Bases: :py:obj:`ChoicesBase`, :py:obj:`gflownet.envs.composite.setflex.SetFlex` Initializes a ChoicesSetFlex environment inheriting from the SetFlex.