Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement SAC #34

Open
will-maclean opened this issue Jun 16, 2024 · 1 comment
Open

Implement SAC #34

will-maclean opened this issue Jun 16, 2024 · 1 comment
Assignees
Labels
algorithm A new algorithm to implement

Comments

@will-maclean
Copy link
Owner

No description provided.

@will-maclean will-maclean added the algorithm A new algorithm to implement label Jun 16, 2024
@will-maclean
Copy link
Owner Author

Starting point:

#[derive(serde::Serialize, serde::Deserialize, Clone)]
pub enum EntCoefSetup {
    Static(f32),
    Trainable(f32)
}

pub enum EntCoef<B: AutodiffBackend> {
    Static(f32),
    Trainable(Tensor<B, 1>, OptimizerAdaptor<Adam<B::InnerBackend>, Tensor<B, 1>, B>)
}

impl<B: AutodiffBackend> EntCoef<B> {
    fn to_float(&self) -> f32 {
        match self {
            EntCoef::Static(v) => *v,
            EntCoef::Trainable(t, _) => t.clone().exp().into_scalar().elem(),
        }
    }
} 

pub struct SACAgent<O: SimpleOptimizer<B::InnerBackend>, B: AutodiffBackend> {
    pub net: SACNet<B>,
    pub optim: OptimizerAdaptor<O, SACNet<B>, B>,
    pub config: SACConfig,
    pub target_entropy: f32,
    pub ent_coef: EntCoef<B>,
    pub observation_space: ObsSpace,
    pub action_space: ActionSpace,
}

#[derive(serde::Serialize, serde::Deserialize, Clone)]
pub enum ActionNoise{
    None,
}

#[derive(Config)]
pub struct SACConfig {
    #[config(default = 0.05)]
    tau: f32,
    #[config(default = 0.99)]
    gamma: f32,
    action_noise: ActionNoise,
    #[config(default = 1)]
    target_update_interval: usize,
    ent_coef: EntCoefSetup,
    target_entropy: Option<f32>,
    #[config(default = false)]
    use_sde: bool,
    #[config(default = 1)]
    sde_sample_freq: usize,
    #[config(default = false)]
    use_sde_at_warmup: bool,
}

@will-maclean will-maclean mentioned this issue Jun 19, 2024
@will-maclean will-maclean self-assigned this Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
algorithm A new algorithm to implement
Projects
None yet
Development

No branches or pull requests

1 participant