Skip to content

Commit 75998e1

Browse files
committed
fix: create and add fbm test
1 parent 354bdbf commit 75998e1

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "stochastic-rs"
3-
version = "0.2.1"
3+
version = "0.2.2"
44
edition = "2021"
55
license = "MIT"
66
description = "A Rust library for stochastic processes"
@@ -23,4 +23,5 @@ rand_distr = "0.4.3"
2323
rustfft = "6.1.0"
2424

2525
[lib]
26+
name = "stochastic_rs"
2627
crate-type = ["cdylib"]

src/main.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/processes/bm.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::noises::gn;
55
pub fn bm(n: usize, t: Option<f64>) -> Vec<f64> {
66
let gn = gn::gn(n - 1, t.unwrap_or(1.0));
77
let mut bm = Array1::<f64>::zeros(n);
8-
bm[0] = 0.0;
98

109
for i in 1..n {
1110
bm[i] = bm[i - 1] + gn[i - 1];

src/processes/fbm.rs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{
22
noises::{fgn_cholesky, fgn_fft},
33
utils::NoiseGenerationMethod,
44
};
5-
use nalgebra::RowDVector;
5+
use ndarray::Array1;
66

77
pub fn fbm(
88
hurst: f64,
@@ -14,13 +14,37 @@ pub fn fbm(
1414
NoiseGenerationMethod::Fft => fgn_fft::fgn(hurst, n, t.unwrap_or(1.0)),
1515
NoiseGenerationMethod::Cholesky => fgn_cholesky::fgn(hurst, n - 1, t.unwrap_or(1.0)),
1616
};
17-
18-
let mut fbm = RowDVector::<f64>::zeros(n);
19-
fbm[0] = 0.0;
17+
let mut fbm = Array1::<f64>::zeros(n);
2018

2119
for i in 1..n {
2220
fbm[i] = fbm[i - 1] + fgn[i - 1];
2321
}
2422

25-
fbm.data.as_vec().clone()
23+
fbm.to_vec()
24+
}
25+
26+
#[cfg(test)]
27+
mod tests {
28+
use super::*;
29+
use crate::statistics::fractal_dim::higuchi_fd;
30+
use crate::utils::NoiseGenerationMethod;
31+
32+
#[test]
33+
fn test_fbm() {
34+
let (hurst, n) = (0.7, 10000);
35+
36+
let path = fbm(hurst, n, None, Some(NoiseGenerationMethod::Fft));
37+
assert_eq!(path.len(), n);
38+
assert_eq!(path[0], 0.0);
39+
40+
let h = higuchi_fd(&path, 10);
41+
println!("Higuchi FD: {}", h);
42+
assert!((2.0 - h) < 10e-1);
43+
44+
let path = fbm(hurst, n, None, Some(NoiseGenerationMethod::Cholesky));
45+
assert_eq!(path.len(), n);
46+
47+
let h = higuchi_fd(&path, 10);
48+
assert!((2.0 - h) < 10e-1);
49+
}
2650
}

0 commit comments

Comments
 (0)