| 586 | } |
| 587 | |
| 588 | pub fn get_konto_entropy(message: &str, window: usize) -> f64 { |
| 589 | if message.len() < 2 { |
| 590 | return 0.0; |
| 591 | } |
| 592 | let points: Vec<usize> = if window == 0 { |
| 593 | (1..=message.len() / 2).collect() |
| 594 | } else { |
| 595 | let w = window.min(message.len() / 2); |
| 596 | (w..=message.len() - w).collect() |
| 597 | }; |
| 598 | let mut sum = 0.0; |
| 599 | let mut num = 0.0; |
| 600 | for i in points { |
| 601 | let l = match_length(message, i, if window == 0 { i } else { window }); |
| 602 | let denom = if window == 0 { (i + 1) as f64 } else { (window + 1) as f64 }; |
| 603 | sum += denom.log2() / l as f64; |
| 604 | num += 1.0; |
| 605 | } |
| 606 | if num == 0.0 { |
| 607 | 0.0 |
| 608 | } else { |
| 609 | sum / num |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | pub struct MicrostructuralFeaturesGenerator { |
| 614 | tick_num_iter: std::vec::IntoIter<usize>, |