Skip to content

Commit

Permalink
Per issue #2206, added new function mean_abs_diff(). SL
Browse files Browse the repository at this point in the history
  • Loading branch information
Seth Linden committed Aug 24, 2022
1 parent faa6a13 commit 53c72f5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/basic/vx_util/num_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1273,4 +1273,33 @@ ConcatString write_css_hhmmss(const NumArray &na)
}


////////////////////////////////////////////////////////////////////////


double NumArray::mean_abs_diff() const

{

int i, j, count;
double sum, mad;

int n = n_elements();

for(i=0, count=0, sum=0.0; i<n; i++) {
for(j=i+1; j<n; j++) {

if( is_bad_data(e[i]) || is_bad_data(e[j]) ) continue;
sum += abs(e[i]-e[j]);
count++;
}
}

if(count == 0) mad = bad_data_double;
else mad = sum / (n*(n-1));

return(mad);

}


////////////////////////////////////////////////////////////////////////
3 changes: 2 additions & 1 deletion src/basic/vx_util/num_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ class NumArray {
double mean() const;
double mean_sqrt() const;
double mean_fisher() const;

double mean_abs_diff() const;

double variance(int skip_index = bad_data_int) const;
double stdev(int skip_index = bad_data_int) const;

Expand Down

0 comments on commit 53c72f5

Please sign in to comment.