https://github.com/DanielAvdar/prob-spaces
https://github.com/DanielAvdar/prob-spaces
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/DanielAvdar/prob-spaces
- Owner: DanielAvdar
- License: mit
- Created: 2025-03-16T19:06:45.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-04-20T19:58:23.000Z (6 months ago)
- Last Synced: 2025-04-22T19:47:55.951Z (6 months ago)
- Language: Python
- Size: 5.81 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- awesome-opensource-israel - prob-spaces - Probability Distributions from Gymnasium Spaces. (Projects by main language / python)
README
# prob-spaces: Probability Distributions from Gymnasium Spaces
[](https://pypi.org/project/prob-spaces/)
[](https://img.shields.io/pypi/v/prob-spaces)
[](https://opensource.org/licenses/MIT)



[](https://github.com/DanielAvdar/prob-spaces/actions/workflows/ci.yml)
[](https://github.com/DanielAvdar/prob-spaces/actions/workflows/code-checks.yml)
[](https://codecov.io/gh/DanielAvdar/prob-spaces)
[](https://github.com/astral-sh/ruff)

**prob-spaces** is a Python package that allows you to create probability distributions from Gymnasium spaces.
It provides a simple and intuitive interface for working with various probability spaces in reinforcement learning
environments.Key Features:
* Create probability distributions directly from Gymnasium spaces
* Support for common space types: Discrete, MultiDiscrete, Box, and Dict
* Seamless integration with PyTorch for sampling and computing log probabilities
* Support for masking operations to constrain valid actions## Installation
### From PyPI
To install prob-spaces from PyPI:
```bash
pip install prob-spaces
```### GPU Support
prob-spaces uses PyTorch, which can be installed with CUDA support for GPU acceleration.
The package configuration includes a PyTorch CUDA 12.4 index. To use a different CUDA version,
you may need to modify the PyTorch installation separately.## Example Usage
Here's a simple example of how to use prob-spaces:
```python
import gymnasium as gym
import torch as th
from prob_spaces.converter import convert_to_prob_space# Create a Gymnasium space
action_space = gym.spaces.Discrete(5)# Convert to a probability space
prob_space = convert_to_prob_space(action_space)# Create a probability distribution
probs = th.ones(5) # Uniform distribution
dist = prob_space(probs)# Sample from the distribution
action = dist.sample()# Compute log probability
log_prob = dist.log_prob(action)
```## Documentation
[Documentation](https://prob-spaces.readthedocs.io/en/latest/) is available online and provides detailed information on how to use the package, including examples and API references.