Skip to main content

fdars_core/depth/
random_projection.rs

1//! Random projection depth measures.
2
3use crate::matrix::FdMatrix;
4
5use super::random_depth_core;
6
7/// Compute random projection depth for 1D functional data.
8///
9/// Projects curves to scalars using random projections and computes
10/// average univariate depth.
11///
12/// # Arguments
13/// * `data_obj` - Data to compute depth for
14/// * `data_ori` - Reference data
15/// * `nproj` - Number of random projections
16#[must_use = "expensive computation whose result should not be discarded"]
17pub fn random_projection_1d(data_obj: &FdMatrix, data_ori: &FdMatrix, nproj: usize) -> Vec<f64> {
18    random_projection_1d_seeded(data_obj, data_ori, nproj, None)
19}
20
21/// Compute random projection depth with optional seed for reproducibility.
22#[must_use = "expensive computation whose result should not be discarded"]
23pub fn random_projection_1d_seeded(
24    data_obj: &FdMatrix,
25    data_ori: &FdMatrix,
26    nproj: usize,
27    seed: Option<u64>,
28) -> Vec<f64> {
29    random_depth_core(
30        data_obj,
31        data_ori,
32        nproj,
33        seed,
34        0.0,
35        |acc, d| acc + d,
36        |acc, n| acc / n as f64,
37    )
38}
39
40/// Compute random projection depth for 2D functional data.
41#[must_use = "expensive computation whose result should not be discarded"]
42pub fn random_projection_2d(data_obj: &FdMatrix, data_ori: &FdMatrix, nproj: usize) -> Vec<f64> {
43    random_projection_1d(data_obj, data_ori, nproj)
44}