Skip to main content

review_check/
review_check.rs

1use tsorder_core::*;
2struct Rng(u64);
3impl Rng {
4    fn u(&mut self) -> f64 {
5        let mut x = self.0;
6        x ^= x << 13;
7        x ^= x >> 7;
8        x ^= x << 17;
9        self.0 = x;
10        (x >> 11) as f64 / (1u64 << 53) as f64
11    }
12    fn n(&mut self) -> f64 {
13        let a = self.u().max(1e-300);
14        let b = self.u();
15        (-2.0 * a.ln()).sqrt() * (2.0 * std::f64::consts::PI * b).cos()
16    }
17}
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}