feat(rl): create Policy traits and QLearning Struct
This commit is contained in:
1 parent
af3bf626d6
commit
91a74dc692
1 file changed
+30
@@ -1,3 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub trait Environment {
|
||||
type State;
|
||||
type Action;
|
||||
@@ -5,3 +7,31 @@ pub trait Environment {
|
||||
fn actions(state: &Self::State) -> Vec<Self::Action>;
|
||||
fn step(state: Self::State, action: Self::Action) -> (Option<Self::State>, Self::Reward);
|
||||
}
|
||||
|
||||
pub trait ToSaveState: Environment {
|
||||
type SaveState;
|
||||
fn to_save_state(state: Self::State) -> Self::SaveState;
|
||||
}
|
||||
|
||||
trait Policy<E: Environment> {
|
||||
type ActionEvaluator;
|
||||
fn choose_action(action_evaluator: Self::ActionEvaluator, state: E::State) -> E::Action;
|
||||
fn train(
|
||||
action_evaluator: Self::ActionEvaluator,
|
||||
num_training_episodes: usize,
|
||||
max_steps: usize,
|
||||
) -> Self::ActionEvaluator;
|
||||
}
|
||||
|
||||
trait SavePolicy<T: ToSaveState>: Policy<T> {
|
||||
fn save_policy(policy: Self::ActionEvaluator);
|
||||
}
|
||||
|
||||
enum PolicyKind {
|
||||
Greedy,
|
||||
EpsilonGreedy,
|
||||
}
|
||||
|
||||
struct QLearning<E: ToSaveState> {
|
||||
qtable: HashMap<E::SaveState, isize>,
|
||||
}
|
||||
Reference in new issue
Block a user