time_series_datasets/
time_series_datasets.rs

1use scirs2_core::ndarray::s;
2use scirs2_datasets::time_series::electrocardiogram;
3
4#[allow(dead_code)]
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    println!("Loading time series datasets...\n");
7
8    // Load the electrocardiogram dataset
9    let ecg = electrocardiogram()?;
10
11    println!("Electrocardiogram dataset:");
12    println!("  Time steps: {}", ecg.n_samples());
13    println!("  Features: {}", ecg.n_features());
14    println!(
15        "  Sampling rate: {} Hz",
16        ecg.metadata
17            .get("sampling_rate")
18            .unwrap_or(&"unknown".to_string())
19    );
20    println!(
21        "  Duration: {}",
22        ecg.metadata
23            .get("duration")
24            .unwrap_or(&"unknown".to_string())
25    );
26
27    // Get a slice of the data and display basic statistics
28    let ecg_slice = ecg.data.slice(s![0..10, 0]);
29    println!("  First 10 data points: {ecg_slice:?}");
30
31    // Calculate some basic statistics
32    let ecgdata = ecg.data.column(0);
33    let min = ecgdata.fold(f64::INFINITY, |a, &b| a.min(b));
34    let max = ecgdata.fold(f64::NEG_INFINITY, |a, &b| a.max(b));
35    let mean = ecgdata.sum() / ecgdata.len() as f64;
36
37    println!("  Min: {min:.3} mV");
38    println!("  Max: {max:.3} mV");
39    println!("  Mean: {mean:.3} mV");
40
41    // Note: Stock market and weather datasets are commented out because their source data
42    // is not yet available.
43
44    /*
45    // Load the stock market dataset
46    println!("\nStock market dataset:");
47
48    // Get price changes (returns)
49    let stock_returns = stock_market(true)?;
50    println!("  Time steps: {}", stock_returns.n_samples());
51    println!("  Companies: {}", stock_returns.n_features());
52
53    // Print companies
54    if let Some(featurenames) = &stock_returns.featurenames {
55        println!("  Companies: {}", featurenames.join(", "));
56    }
57
58    // Load the weather dataset
59    println!("\nWeather dataset:");
60    let tempdata = weather(Some("temperature"))?;
61
62    println!("  Time steps: {}", tempdata.n_samples());
63    println!("  Locations: {}", tempdata.n_features());
64    */
65
66    println!("\nTime series dataset loaded successfully!");
67
68    Ok(())
69}