detect_edges

Function detect_edges 

Source
pub fn detect_edges<F: Float + FromPrimitive>(
    entropy_values: &[(usize, F)],
    high_threshold: F,
    low_threshold: F,
) -> Vec<EntropyEdge<F>>
Expand description

Detects rising and falling edges in a sequence of entropy values.

Uses hysteresis to avoid spurious edge detection: a rising edge is only detected when entropy crosses above high_threshold, and a falling edge when it crosses below low_threshold.

§Arguments

  • entropy_values - Slice of (block_index, entropy) tuples where entropy is in bits (0-8)
  • high_threshold - Normalized threshold (0.0-1.0) for detecting rising edges
  • low_threshold - Normalized threshold (0.0-1.0) for detecting falling edges

§Returns

A vector of detected entropy edges

§Example

use shannon::{detect_edges, EdgeType};

// Entropy values in bits (0-8): starts high, drops low
let values = vec![(0, 7.8_f64), (1, 7.9), (2, 2.0), (3, 1.0)];
let edges = detect_edges(&values, 0.95, 0.85);
assert_eq!(edges.len(), 2);
assert_eq!(edges[0].edge_type, EdgeType::Rising);
assert_eq!(edges[0].block_index, 0);
assert_eq!(edges[1].edge_type, EdgeType::Falling);
assert_eq!(edges[1].block_index, 2);