Skip to main content

A reinforcement learning library inspired by Agentic Learn Pro, focusing on Q-learning.

Project description

QAgentLib

A specialized reinforcement learning package inspired by and building upon the core concepts of Agentic Learn Pro, with targeted features for specific domains.

Overview

This library provides a clean, modular, and well-documented implementation of Q-learning with specialized extensions for targeted applications. It demonstrates the influence and advancement inspired by the original Agentic Learn Pro project, while focusing on specific use cases and advanced reinforcement learning techniques.

Attribution

This package is an independent implementation inspired by the foundational work of Agentic Learn Pro, created by Stephanie Ewelu. We acknowledge and appreciate the significant contributions of Agentic Learn Pro to the field of reinforcement learning and agentic AI.

Installation

pip install QAgentLib

Usage

Basic Q-Learning

from QAgentLib.agent import QLearningAgent
from QAgentLib.environment import SimpleEnv

env = SimpleEnv()
agent = QLearningAgent(state_space=env.state_space, action_space=env.action_space)

for episode in range(100):
    state = env.reset()
    done = False
    while not done:
        action = agent.choose_action(state)
        next_state, reward, done = env.step(action)
        agent.learn(state, action, reward, next_state)
        state = next_state
    agent.decay_exploration()
print("Q-table after training:", agent.q_table)

Targeted Q-Learning with Advanced Features

from QAgentLib.agent import TargetedQLearningAgent
from QAgentLib.environment import GridWorldEnv

# Create a grid world with obstacles
env = GridWorldEnv(
    width=5, 
    height=5, 
    start_pos=(0, 0), 
    goal_pos=(4, 4),
    obstacles=[(1, 1), (2, 1), (3, 1), (1, 3), (2, 3), (3, 3)]
)

# Create a targeted agent for grid navigation
agent = TargetedQLearningAgent(
    state_space=[(x, y) for x in range(env.width) for y in range(env.height)],
    action_space=[0, 1, 2, 3],  # up, right, down, left
    target_domain="grid_navigation"
)

# Training loop with experience replay
for episode in range(200):
    state = env.reset()
    total_reward = 0
    done = False
    
    while not done:
        action = agent.choose_action(state)
        next_state, reward, done, info = env.step(action)
        agent.learn(state, action, reward, next_state)
        
        # Replay experiences periodically
        if episode > 10 and episode % 5 == 0:
            agent.replay_experience(batch_size=10)
            
        state = next_state
        total_reward += reward
        
    # Adjust learning rate based on performance
    agent.adaptive_learning_rate()
    agent.decay_exploration(0.95)
    
    if episode % 20 == 0:
        metrics = agent.get_performance_metrics()
        print(f"Episode {episode}, Avg Reward: {metrics['avg_reward']:.2f}")
        print(env.render())

Multi-Objective Reinforcement Learning

from QAgentLib.agent import TargetedQLearningAgent
from QAgentLib.environment import MultiObjectiveEnv

# Create environment with 3 competing objectives
env = MultiObjectiveEnv(
    num_objectives=3,
    objective_weights=[0.5, 0.3, 0.2]  # Prioritize first objective
)

# Create agent for multi-objective optimization
agent = TargetedQLearningAgent(
    state_space=env.state_space,
    action_space=list(range(env.action_space)),
    target_domain="multi_objective"
)

# Training loop
for episode in range(100):
    state = env.reset()
    done = False
    
    while not done:
        action = agent.choose_action(state[0])  # state is (state_index, objective_values)
        next_state, reward, done, info = env.step(action)
        agent.learn(state[0], action, reward, next_state[0])
        state = next_state
        
    if episode % 10 == 0:
        metrics = agent.get_performance_metrics()
        print(f"Episode {episode}, Performance: {metrics['avg_reward']:.2f}")
        print(f"Objective values: {info['objective_values']}")

Development

For development, clone the repository and install in editable mode:

git clone https://github.com/your_username/QAgentLib.git
cd QAgentLib
pip install -e .

Testing

To run tests:

pytest

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

qagentlib-0.1.1.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

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

qagentlib-0.1.1-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file qagentlib-0.1.1.tar.gz.

File metadata

  • Download URL: qagentlib-0.1.1.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.8

File hashes

Hashes for qagentlib-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9d2171504163942cfa63690b7be694e75de0d23dc4cdddd29aaa1633914e944f
MD5 5ccd697a76bf398cbb2056ede84e9248
BLAKE2b-256 50bee0a1867398ca62dfae892b0fb9ce4963eaa0441a89746367414bae8e708a

See more details on using hashes here.

File details

Details for the file qagentlib-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: qagentlib-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.8

File hashes

Hashes for qagentlib-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 557763ebf124009948d1628f0fe1cbc606b25d0ebaea32ef149470aa33290657
MD5 39a4fc12c1b3dcc43b1e40b61e1343e9
BLAKE2b-256 6d42eb2b0944b0c857c83292e7a33ac880e2db97137b5ff3186e5034e297a8be

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