Skip to main content

Softmax exploration functions for reinforcement learning

Project description

Softmax Exploration Package

A Python package for implementing softmax exploration strategies in reinforcement learning algorithms.

Installation

pip install softmax-exploration

Features

  • Softmax Action Selection: Convert Q-values to action probabilities using softmax function
  • Boltzmann Exploration: Temperature-controlled exploration strategy
  • Epsilon-Softmax: Hybrid approach combining epsilon-greedy with softmax
  • Adaptive Temperature: Dynamic temperature scheduling for exploration decay
  • Numerical Stability: Robust implementation with overflow protection

Usage

Basic Softmax Exploration

from softmax_exploration import softmax, softmax_action_selection

# Q-values for each action
q_values = [1.2, 0.8, 2.1, 0.5]

# Get action probabilities
probabilities = softmax(q_values, temperature=1.0)
print(probabilities)
# Output: [0.234, 0.156, 0.456, 0.154]

# Select action using softmax
action = softmax_action_selection(q_values, temperature=1.0)
print(f"Selected action: {action}")

Temperature Control

# High temperature = more exploration
probs_high_temp = softmax(q_values, temperature=2.0)
print("High temperature (more exploration):", probs_high_temp)

# Low temperature = more exploitation
probs_low_temp = softmax(q_values, temperature=0.5)
print("Low temperature (more exploitation):", probs_low_temp)

Epsilon-Softmax Hybrid

from softmax_exploration import epsilon_softmax

# Combine epsilon-greedy with softmax
action = epsilon_softmax(q_values, epsilon=0.1, temperature=1.0)
print(f"Epsilon-softmax action: {action}")

Adaptive Temperature Scheduling

from softmax_exploration import adaptive_temperature

# Temperature decreases over episodes
for episode in [0, 10, 50, 100]:
    temp = adaptive_temperature(episode)
    print(f"Episode {episode}: Temperature = {temp:.3f}")

Boltzmann Exploration

from softmax_exploration import boltzmann_exploration

# Boltzmann exploration (same as softmax)
action = boltzmann_exploration(q_values, temperature=1.0)
print(f"Boltzmann action: {action}")

API Reference

softmax(q_values, temperature=1.0)

Compute softmax probabilities for given Q-values.

Parameters:

  • q_values: List or numpy array of Q-values
  • temperature: Temperature parameter (higher = more exploration)

Returns: Probability distribution over actions

softmax_action_selection(q_values, temperature=1.0, random_state=None)

Select an action using softmax exploration.

Parameters:

  • q_values: List or numpy array of Q-values
  • temperature: Temperature parameter
  • random_state: Random state for reproducibility

Returns: Selected action index

epsilon_softmax(q_values, epsilon=0.1, temperature=1.0, random_state=None)

Hybrid exploration combining epsilon-greedy with softmax.

Parameters:

  • q_values: List or numpy array of Q-values
  • epsilon: Probability of random action selection
  • temperature: Temperature parameter for softmax
  • random_state: Random state for reproducibility

Returns: Selected action index

adaptive_temperature(episode, initial_temp=10.0, decay_rate=0.995, min_temp=0.1)

Compute adaptive temperature for exploration scheduling.

Parameters:

  • episode: Current episode number
  • initial_temp: Initial temperature value
  • decay_rate: Temperature decay rate
  • min_temp: Minimum temperature value

Returns: Adaptive temperature value

Requirements

  • Python 3.6+
  • NumPy

Installation from Source

git clone https://github.com/yourusername/softmax-exploration.git
cd softmax-exploration
pip install -e .

License

This project is open source and available under the MIT License.

Contributing

Feel free to contribute to this project by submitting issues or pull requests.

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

softmax_exploration-0.1.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

softmax_exploration-0.1-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file softmax_exploration-0.1.tar.gz.

File metadata

  • Download URL: softmax_exploration-0.1.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for softmax_exploration-0.1.tar.gz
Algorithm Hash digest
SHA256 9d07179adead69f957d01dcce2a48883a8115ceef47c3d23b3efdf61f37a028e
MD5 849b3bf26780baa3bc0c96b8f43f6620
BLAKE2b-256 70d6371111e81ce8eed585d44040bb5728e31579448250f08c2ff22270c7cad2

See more details on using hashes here.

File details

Details for the file softmax_exploration-0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for softmax_exploration-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 639eb58cd29590202800c0536d9365359a85c2822376571126dfc6743e29d6dd
MD5 ad6bf529adf5619112f97020b6c995a5
BLAKE2b-256 af0fe43914c1b779ba336614e65cd674ca0f7b35c2b2e36b73c1f304a242be0c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page