Skip to main content

power_memory

Function power_memory 

Source
pub fn power_memory(n: usize) -> usize
Expand description

Power-law growing memory p_n = floor(n^0.4), clamped to [2, n/4] — the Fine–Hwang-style window. Satisfies p_n²/n → 0 (Hwang) but not p_n³/n → 0 (Berk 1974 / Lewis–Reinsel 1985 uniform results). It was the package default until the benchmark showed the poly-log window dominating it (notably on seasonal AR, where n^0.4 < 12 until n ≈ 800); the default is now polylog_memory(n, 2.0) via crate::Statistic::default_memory. Kept as an option and for the benchmark.

Examples found in repository?
examples/review_check.rs (line 60)
18fn main() {
19    let mut r = Rng(3);
20    let wn: Vec<f64> = (0..2000).map(|_| r.n()).collect();
21    let shifted: Vec<f64> = wn.iter().map(|v| v + 50.0).collect();
22    for (name, x) in [("ruido branco", &wn), ("ruido branco + 50", &shifted)] {
23        for s in [
24            Statistic::Pacf,
25            Statistic::LongArOls,
26            Statistic::LongArYw,
27            Statistic::AcfBartlett,
28        ] {
29            let f = fh_order(
30                x,
31                FhConfig {
32                    statistic: s,
33                    ..Default::default()
34                },
35            )
36            .unwrap();
37            println!("{name:18} {:14} -> ordem {}", s.name(), f.order);
38        }
39    }
40    let f = fh_order(
41        &wn,
42        FhConfig {
43            threshold: Threshold::BicLike { c: -1.0 },
44            ..Default::default()
45        },
46    )
47    .unwrap();
48    println!("c=-1: ordem {} tau {}", f.order, f.tau);
49    let f = fh_order(
50        &wn,
51        FhConfig {
52            threshold: Threshold::Fixed(-5.0),
53            ..Default::default()
54        },
55    )
56    .unwrap();
57    println!("fixed(-5): ordem {} tau {}", f.order, f.tau);
58    // Hwang condition p_n/(n eta^2) with eta = tau/sqrt(n)
59    for n in [100usize, 1000, 10000, 100000] {
60        let p = power_memory(n);
61        let tau = Threshold::default().value(n, p);
62        println!(
63            "n={n} p_n={p} tau={tau:.2}  p_n/(n eta^2)=p_n/tau^2={:.2}",
64            p as f64 / (tau * tau)
65        );
66    }
67}