learning_config.rs 1.93 KB
Newer Older
Bharat Garhewal's avatar
Bharat Garhewal committed
1
use num_format::{Locale, ToFormattedString};
2
3
4
5
use std::fmt;

#[derive(PartialEq, Eq, Clone, Debug)]
pub enum EqOracle {
6
7
    Internal,
    Hads,
8
9
}

10
#[derive(PartialEq, Eq, Clone, Debug)]
11
12
13
14
15
16
17
18
19
pub enum Rule2 {
    Nothing,
    Ads,
    SepSeq,
}

#[derive(PartialEq, Eq, Clone, Debug)]
pub enum Rule3 {
    SepSeq,
20
21
22
    Ads,
}

23
pub struct LearnResult {
24
25
26
27
28
29
30
    pub rounds: usize,
    pub success: bool,
    pub learn_inputs: usize,
    pub learn_resets: usize,
    pub test_inputs: usize,
    pub test_resets: usize,
    pub eq_oracle: EqOracle,
Bharat's avatar
Update    
Bharat committed
31
32
    pub num_states: usize,
    pub num_inputs: usize,
Bharat's avatar
Bharat committed
33
    pub ads_score: f32,
34
35
36
37
    pub ly_ads_threshold: f32,
    pub times_ly_ads_used: usize,
    pub ly_ads_inputs: usize,
    pub ly_ads_resets: usize,
38
39
40
}

impl LearnResult {
41
42
    pub fn to_csv_entry(&self) -> String {
        format!(
43
            "{},{},{},{},{},{},{},{},{},{},{},{},{}",
44
45
            self.success,
            self.rounds,
Bharat's avatar
Update    
Bharat committed
46
47
48
49
50
            self.num_states,
            self.num_inputs,
            self.learn_inputs,
            self.learn_resets,
            self.test_inputs,
Bharat's avatar
Bharat committed
51
            self.test_resets,
52
53
54
55
56
            self.ads_score,
            self.ly_ads_threshold,
            self.times_ly_ads_used,
            self.ly_ads_inputs,
            self.ly_ads_resets
57
58
        )
    }
59
60
61
}

impl fmt::Display for LearnResult {
62
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Bharat's avatar
Update    
Bharat committed
63
64
        writeln!(f, "Number of rounds : {}", self.rounds).unwrap();
        writeln!(f, "Model learned : {}", self.success).unwrap();
65
66
67
        writeln!(
            f,
            "Learning Inputs / Resets : {} / {}",
Bharat Garhewal's avatar
update    
Bharat Garhewal committed
68
69
            self.learn_inputs.to_formatted_string(&Locale::en),
            self.learn_resets.to_formatted_string(&Locale::en)
Bharat's avatar
Update    
Bharat committed
70
71
        )
        .unwrap();
72
73
74
        writeln!(
            f,
            "Testing Inputs / Resets : {} / {}",
Bharat Garhewal's avatar
update    
Bharat Garhewal committed
75
76
            self.test_inputs.to_formatted_string(&Locale::en),
            self.test_resets.to_formatted_string(&Locale::en)
77
78
        )
    }
79
}