22 个版本 (7 个重大变更)
0.8.0 | 2022 年 11 月 13 日 |
---|---|
0.7.0 | 2022 年 9 月 29 日 |
0.4.3 | 2022 年 7 月 31 日 |
#530 在 机器学习
每月 60 次下载
84KB
2K SLoC
EntityGym for Rust
EntityGym 是一个 Python 库,它定义了一种基于实体的强化学习环境的创新抽象,这可以使深度强化学习代理的训练非常便捷和高效。这个软件包提供了绑定,允许 Rust 程序作为 EntityGym 训练环境使用,并在纯 Rust 应用程序中本地加载和运行使用 Entity Neural Network Trainer 训练的神经网络代理。
概述
entity-gym-rs 的核心抽象是 Agent
特性。它定义了一个高级 API,用于神经网络代理,允许它们直接与 Rust 数据结构交互。要使用 entity-gym-rs 提供的任何 Agent
实现之一,您只需要派生 Action
和 Featurizable
特性,这些特性定义了代理可以观察的信息和可以采取的操作
Action
特性 允许 Rust 类型作为Agent
的操作返回。这个特性可以自动派生自只有单元变体的枚举。Featurizable
特性 将对象转换为神经网络可以处理的格式。它可以派生自大多数固定大小的struct
,以及具有单元变体的enum
。代理可以观察包含任意数量Featurizable
对象的集合。
示例
基本示例,演示如何构建观察并从 Agent
中采样随机操作
use entity_gym_rs::agent::{Agent, AgentOps, Obs, Action, Featurizable};
#[derive(Action, Debug)]
enum Move { Up, Down, Left, Right }
#[derive(Featurizable)]
struct Player { x: i32, y: i32 }
#[derive(Featurizable)]
struct Cake {
x: i32,
y: i32,
size: u32,
}
fn main() {
// Creates an agent that acts completely randomly.
let mut agent = Agent::random();
// Alternatively, load a trained neural network agent from a checkpoint.
// let mut agent = Agent::load("agent");
// Construct an observation with one `Player` entity and two `Cake entities.
let obs = Obs::new(0.0)
.entities([Player { x: 0, y: 0 }])
.entities([
Cake { x: 4, y: 0, size: 4 },
Cake { x: 10, y: 42, size: 12 },
]);
// To obtain an action from an agent, we simple call the `act` method
// with the observation we constructed.
let action = agent.act::<Move>(obs);
println!("{:?}", action);
}
有关包含训练神经网络来玩蛇的更完整示例,请参阅 examples/bevy_snake。
文档
- bevy_snake:如何在使用EntityGym Rust在Bevy游戏中应用的示例。
- bevy-snake-ai:一个更复杂的Bevy应用程序,通过多个智能体的对抗训练来创建AI对手。
- EntityGym Rust API文档:Rust API参考。
- 如果您有任何问题,也可以在我们的discord服务器上获得帮助。
依赖项
~14–35MB
~540K SLoC