NS-Gym Utils Module

ns_gym.utils.state_action_update(transitions, new_probs)[source]

Update the transitions associated with a single state action pair in the gridworld environments with new probs

Parameters:
  • transitions (list) – A list of tuples representing the transitions for a specific state-action pair.

  • new_probs (list) – A list of new probabilities to update the transitions with.

Returns:

The updated list of transitions with the new probabilities.

Return type:

list

Notes

The possible transitions from state s with action a are typically stored in a list of tuples. For example, the possible transitions for (s,a) in FrozenLake are store in table P at P[s][a], where:

P[s][a] = [(p0, newstate0, reward0, terminated),

(p1, newstate1, reward1, terminated), (p2, newstate2, reward2, terminated)]

The indended direction is stored in P[s][a][1].

ns_gym.utils.n_choose_k(n, k)[source]

Calculate the binomial coefficient ‘n choose k’ :type n: int :param n: Total number of items. :type n: int :type k: int :param k: Number of items to choose. :type k: int

Returns:

The binomial coefficient, i.e., the number of ways to choose k items

from a set of n items.

Return type:

int

ns_gym.utils.wasserstein_dual(u, v)[source]

_summary_

Parameters:
  • u (np.ndarray) – _description_

  • v (np.ndarray) – _description_

  • d (np.ndarray) – _description_

Returns:

_description_

Return type:

_type_

ns_gym.utils.categorical_sample(probs)[source]

Sample from a categorical distribution :type probs: list :param probs: A list of probabilities that sum to 1 :type probs: list

Returns:

The index of the sampled probability

Return type:

int

ns_gym.utils.type_mismatch_checker(observation=None, reward=None)[source]

A helper function to handle type mismatches between ns_gym and Gymnasium environments.

Parameters:
  • observation – The observation, which may be an dictionary.

  • reward – The reward object, which may be an instance of nsg.base.Reward.

Returns:

A tuple containing the processed observation and reward, with None if not provided.

ns_gym.utils.parse_config(file_path)[source]

Reads a YAML config file and updates its values with any command-line arguments. Also checks if necessary configs for experiments are present.

Parameters:

file_path (str or Path) – Path to the YAML configuration file.

Returns:

The combined configuration dictionary.

Return type:

dict

ns_gym.utils.neural_network_checker(agent_device, obs)[source]

Helper function to check if model and inputs are on the same device