@@ -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
77pub 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