This is a template repository for Python projects that use uv for their dependency management.
Project description
Samsara RL
A vectorized NumPy implementation of foundational reinforcement learning algorithms, following David Silver's RL lecture series. Built for clarity and learning — each algorithm maps directly to the equations in the lectures.
Applications of RL include robotic manipulation, LLM fine-tuning, financial portfolio management, and adaptive control systems.
Table of Contents
Installation
pip install samsara-rl
Quick Start
from samsara_rl.mdp.grid_world.grid_world_mdp import GridWorldMDP
from samsara_rl.planning.policy_iteration import PolicyIteration
mdp = GridWorldMDP()
pi = PolicyIteration(mdp)
policy = pi.find_optimal_policy()
Planning
Planning algorithms assume full knowledge of environment dynamics (transition probabilities and reward function). While not "true RL" — agents never have access to dynamics in practice — planning provides the theoretical foundation all RL algorithms build on.
MDP Structure
MDPs are represented as NumPy arrays. The included GridWorldMDP implements the 4x4 grid world from David Silver's Lecture 3.
| Attribute | Shape | Description |
|---|---|---|
state_action_transition_matrix |
(S, A, S') |
T(s, a, s') — transition probabilities |
reward_matrix |
(S, A, S') |
R(s, a, s') — reward for each transition |
Policy Iteration
Alternates between evaluating the current policy using the Bellman expectation equation and improving it greedily until the policy stops changing.
PolicyIteration(mdp, bellman_tolerance)
| Argument | Type | Default | Description |
|---|---|---|---|
mdp |
MDP | MDP instance to solve | |
bellman_tolerance |
float |
0.01 |
Convergence threshold for policy evaluation |
find_optimal_policy(max_iter)
| Argument | Type | Default | Description |
|---|---|---|---|
max_iter |
int |
99 |
Maximum number of policy iteration steps |
Value Iteration
Applies the Bellman optimality equation directly each iteration. Equivalent to policy iteration with k=1 evaluation steps per improvement. Policy is extracted once at convergence.
ValueIteration(mdp, bellman_tolerance)
| Argument | Type | Default | Description |
|---|---|---|---|
mdp |
MDP | MDP instance to solve | |
bellman_tolerance |
float |
0.01 |
Convergence threshold for value iteration |
Examples
from samsara_rl.mdp.grid_world.grid_world_mdp import GridWorldMDP
from samsara_rl.planning.policy_iteration import PolicyIteration
from samsara_rl.planning.value_iteration import ValueIteration
mdp = GridWorldMDP()
policy = PolicyIteration(mdp, bellman_tolerance=0.001).find_optimal_policy(max_iter=50)
policy = ValueIteration(mdp, bellman_tolerance=0.001).find_optimal_policy()
Model-Free Prediction
TODO
Model-Free Control
TODO
Function Approximation
TODO
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file samsara_rl-0.0.2.tar.gz.
File metadata
- Download URL: samsara_rl-0.0.2.tar.gz
- Upload date:
- Size: 103.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
702cde027ee038bc01cf471c667cf40b0f77fef2cfc7e626ddf29370d7a9915c
|
|
| MD5 |
dd6be10c819862e943560deb4c37afa3
|
|
| BLAKE2b-256 |
1907f8a5b7912998e2bb8f35e19ac7547a9c131bee5ac4029492cbda110ee2ae
|
File details
Details for the file samsara_rl-0.0.2-py3-none-any.whl.
File metadata
- Download URL: samsara_rl-0.0.2-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d63b65f1db55505413d9d022cea357944378e60edf1807f0c833f6bf3233686d
|
|
| MD5 |
f237acda6bd5b4a5abc682e6c8fe0246
|
|
| BLAKE2b-256 |
957200c6f79996507d04e99412d4f15a04ae27223a0651fccd949ab2dd3ebb87
|