<commit_before>
pub trait Classified<T> {
    fn class(&self) -> T;
}

pub fn entropy<C:PartialEq, T:Classified<C>>(data:&Vec<T>, classes:&Vec<C>) -> f64 {
    let mut sum: f64 = 0f64;
    for c in classes {
        let mut p: f64 = 0f64;
        for d in data {
            if d.class() == *c {
                p = p + 1f64;
            }
        }
        p = p / (data.len() as f64);
        p = - p * p.log2();
        sum += p;
    }
    sum
}<commit_msg>src/junk/minamoto/entropy.rs: more functional stuff<commit_after>
pub trait Classified<T> {
    fn class(&self) -> T;
}

pub fn entropy<C:PartialEq, T:Classified<C>>(data:&Vec<T>, classes:&Vec<C>) -> f64 {
    let mut sum: f64 = 0f64;
    for c in classes {
        let mut p: f64;
        p = data.iter().filter(|&x| x.class() == *c).fold(0f64, |x, _y| x + 1f64);
        p = p / (data.len() as f64);
        p = - p * p.log2();
        sum += p;
    }
    sum
}
{'fraction_non_alphanumeric': 0.17768147345612134, 'fraction_numerical': 0.0390032502708559, 'mean_word_length': 1.8256880733944953, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '654177', 'n_tokens_mistral': 386, 'n_tokens_neox': 359, 'n_words': 96}