use crate::finance::ml::models::q_net::SimpleQNet;
use crate::finance::ml::traits::MlStrategy;
use crate::finance::ml::errors::MlError;
pub fn apply_scar_damage(model: &mut SimpleQNet, scar_count: u32) -> Result<(), MlError> {
match scar_count {
0 => {}, 1..=2 => {
model.exploration_rate = (model.exploration_rate + 0.05).min(0.9);
}
3..=5 => {
model.exploration_rate = (model.exploration_rate + 0.1).min(0.9);
model.mutate(0.1, 0.01)?;
}
_ => {
model.mutate(0.5, 0.05)?;
model.exploration_rate = 0.5;
}
}
Ok(())
}
pub fn should_spawn_offspring(roi: f32, survival_threshold: f32) -> bool {
roi > survival_threshold
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_spawn_threshold() {
assert!(should_spawn_offspring(10.0, 5.0));
assert!(!should_spawn_offspring(3.0, 5.0));
assert!(should_spawn_offspring(5.01, 5.0));
}
}