Skip to main content

Agent Toolbox

Overview

The agent toolbox generates tensors from the observation and action space. These tensors or vectors can be used directly to Tensorflow or PyTorch.

Setup

pip install cogment_agent_toolbox

Use TensorGenerator class in your agent

  • Create a generator
from agent_toolbox.tensor_generator import TensorGenerator
generator = TensorGenerator()
  • Get the action size and observation size of the environment. These functions are uselfull to create the neural net with the right sizes.
generator = TensorGenerator()
state_size = generator.get_state_size()
action_size = generator.get_action_size()
  • Compute state tensor from the environment observation or compute action tensor from an environment action
state = generator.compute_tensor(obs)
  • Compute action from a tensor, useful function when the type of action is continuous
action_from_tensor = generator.compute_action_from_tensor(action_tensor)

Discrete Actions utils

  • Consult all possible actions generated for a classification problem
generator.get_possible_actions()
  • Returns the number of actions generated for a classification problem
classification_size = generator.get_classification_size()

equivalent to

len(generator.get_possible_actions())
  • Compute a choice for a classification problem, from an action tensor. The returned value is an index in the possible action list. generator.get_possible_actions()
choice = generator.compute_choice_from_action(action_tensor)
  • Convert the selected action index in action required by the environment. The parameter choice is an index from 0 to n, n being generator.get_classification_size().
generator.convert_choice_in_action(choice)

Examples

  • Using action tensor directly, useful for continuous action type.
from agent_toolbox.tensor_generator import TensorGenerator

...

    def decide(self, observation: cog_settings.actor_classes._otsa.observation_space):

        # Create generator
        generator = TensorGenerator()

        # Transform the observation space in tensor
        obs_tensor = generator.compute_tensor(observation)
        print("Observation tensor: ", obs_tensor)

        # Pick an action from a tensor
        action_size = generator.get_action_size()
        action_tensor = [random.random() for i in range(action_size)]

        # Transform the tensor in action
        action_from_tensor = generator.compute_action_from_tensor(action_tensor)

        print("Action from tensor : ", action_from_tensor)
  • Solving classification problem by using a list generated actions, useful for discrete action type.
    def decide(self, observation: cog_settings.actor_classes._otsa.observation_space):

        # Create generator
        generator = TensorGenerator()

        # Transform the observation space in tensor
        obs_tensor = generator.compute_tensor(observation)
        print("Observation tensor: ", obs_tensor)

        # Pick an action from a classification problem
        classification_size = generator.get_classification_size()
        action_choice = random.randrange(classification_size)

        # Transform the choice in action
        action_from_choice = generator.convert_choice_in_action(
            action_choice)

        print("Action from choice : ", action_from_choice)

Metadata

Release files for cogment-agent-toolbox 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cogment-agent-toolbox 0.0.4
File Size Uploaded Provenance Actions
cogment_agent_toolbox-0.0.4.tar.gz 6.0 kB Without provenance Details for cogment_agent_toolbox-0.0.4.tar.gz

Release files / cogment_agent_toolbox-0.0.4.tar.gz

Download URL cogment_agent_toolbox-0.0.4.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1740c0ae1334caa018be5082e11ac3418fb8cfebaa28dc6c8b66431e17c849da
BLAKE2b-256 checksum
How to use checksums
a417ab6c0cedcdea3b028b5b2b81dcba217fd23e5ab3cfcfa450f5a7de8eed24
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.9

Security for cogment-agent-toolbox 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page