MCPcopy Create free account
hub / github.com/cosdata/cosdata / standard_deviation

Function standard_deviation

org/src/project_to_dim.rs:93–112  ·  view source on GitHub ↗
(data: &[f64])

Source from the content-addressed store, hash-verified

91}
92
93fn standard_deviation(data: &[f64]) -> f64 {
94 let mut mean = 0.0;
95 let mut sum_squares = 0.0;
96 let mut count = 0.0; // Use f64 directly for count to avoid casting
97
98 for &x in data {
99 count += 1.0;
100 let delta = x - mean;
101 mean += delta / count;
102 sum_squares += delta * (x - mean);
103 }
104
105 // Return 0.0 if data is empty or has only one element
106 if count < 2.0 {
107 return 0.0;
108 }
109
110 // Calculate and return sample standard deviation
111 (sum_squares / (count - 1.0)).sqrt()
112}
113
114
115fn main() {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected