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.0.tar.gz (12.4 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.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: qagentlib-0.1.0.tar.gz
  • Upload date:
  • Size: 12.4 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.0.tar.gz
Algorithm Hash digest
SHA256 5499718fa49935f059efbc965c7df93538faabc724ce1386ab5a094410b596f7
MD5 19bb4431a824d3adf212da94988c667b
BLAKE2b-256 a6b3484c4451c92d7b8536cf255af5932ed35e77378cf079974a2ad25cd9076e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: qagentlib-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fd73df8dc0b8deb916aaa5175118b94e3b9f8cb2efa0b96e02acad9e736effcf
MD5 7bae7e170c3a7d47fc73f61f7fdc49a3
BLAKE2b-256 b8aa731bbee4fa01b314bda8e45fb9df3926a04159d1069e57f1099aeadcd5b3

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