use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum Distribution {
Uniform { low: f64, high: f64 },
LogUniform { low: f64, high: f64 },
IntUniform { low: i64, high: i64 },
Categorical { choices: Vec<String> },
}
impl Distribution {
pub fn contains(&self, value: &crate::Value) -> bool {
use crate::Value;
match (self, value) {
(Distribution::Uniform { low, high }, Value::Float(x))
| (Distribution::LogUniform { low, high }, Value::Float(x)) => *low <= *x && *x <= *high,
(Distribution::IntUniform { low, high }, Value::Int(x)) => *low <= *x && *x <= *high,
(Distribution::Categorical { choices }, Value::Categorical(s)) => choices.contains(s),
_ => false,
}
}
}