tensorlogic_train/hyperparameter/
value.rs1use std::collections::HashMap;
4
5pub type HyperparamConfig = HashMap<String, HyperparamValue>;
7
8#[derive(Debug, Clone, PartialEq)]
10pub enum HyperparamValue {
11 Float(f64),
13 Int(i64),
15 Bool(bool),
17 String(String),
19}
20
21impl HyperparamValue {
22 pub fn as_float(&self) -> Option<f64> {
24 match self {
25 HyperparamValue::Float(v) => Some(*v),
26 HyperparamValue::Int(v) => Some(*v as f64),
27 _ => None,
28 }
29 }
30
31 pub fn as_int(&self) -> Option<i64> {
33 match self {
34 HyperparamValue::Int(v) => Some(*v),
35 HyperparamValue::Float(v) => Some(*v as i64),
36 _ => None,
37 }
38 }
39
40 pub fn as_bool(&self) -> Option<bool> {
42 match self {
43 HyperparamValue::Bool(v) => Some(*v),
44 _ => None,
45 }
46 }
47
48 pub fn as_string(&self) -> Option<&str> {
50 match self {
51 HyperparamValue::String(v) => Some(v),
52 _ => None,
53 }
54 }
55}
56
57#[derive(Debug, Clone)]
59pub struct HyperparamResult {
60 pub config: HyperparamConfig,
62 pub score: f64,
64 pub metrics: HashMap<String, f64>,
66}
67
68impl HyperparamResult {
69 pub fn new(config: HyperparamConfig, score: f64) -> Self {
71 Self {
72 config,
73 score,
74 metrics: HashMap::new(),
75 }
76 }
77
78 pub fn with_metric(mut self, name: String, value: f64) -> Self {
80 self.metrics.insert(name, value);
81 self
82 }
83}