use anyhow::Result;
use num::Float;
use std::fmt::Debug;
use crate::utils::cast;
pub enum Schedule<F: Float> {
Logarithmic,
Exponential {
gamma: F,
},
Fast,
Custom {
f: fn(k: usize, t: F, t_0: F) -> Result<F>,
},
}
impl<F: Float + Debug> Schedule<F> {
#[allow(clippy::missing_panics_doc)]
#[allow(clippy::unwrap_in_result)]
#[allow(clippy::unwrap_used)]
pub fn cool(&self, k: usize, t: F, t_0: F) -> Result<F> {
match *self {
Schedule::Logarithmic => Ok(t_0 * F::ln(F::from(2.).unwrap()) / F::ln(cast(k + 1)?)),
Schedule::Exponential { gamma } => Ok(gamma * t),
Schedule::Fast => Ok(t_0 / cast(k)?),
Schedule::Custom { f } => f(k, t, t_0),
}
}
}