Skip to content

Commit

Permalink
Per issue #2206, added new function weighted_mean_absolute_diff(). SL
Browse files Browse the repository at this point in the history
  • Loading branch information
Seth Linden committed Sep 7, 2022
1 parent f16f217 commit 2c13f4a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 29 deletions.
80 changes: 51 additions & 29 deletions src/basic/vx_util/num_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1233,39 +1233,72 @@ double NumArray::stdev(int skip_index) const

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

//
// Utility Functions
//

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


ConcatString write_css(const NumArray &na)
double NumArray::mean_abs_diff() const

{

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

for ( int i=0; i<na.n_elements(); ++i ) {
css << (i == 0 ? "" : ",") << na[i];
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(css);
return(mad);

}


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


ConcatString write_css_hhmmss(const NumArray &na)
double NumArray::weighted_mean_abs_diff() const

{

double mad, weighted_mad;

int n = n_elements();

mad = mean_abs_diff();

if( is_bad_data(mad) )
weighted_mad = bad_data_double;
else
weighted_mad = (1/(2*n)) * mad;

return(weighted_mad);

}

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

//
// Utility Functions
//

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


ConcatString write_css(const NumArray &na)

{

ConcatString css;

for ( int i=0; i<na.n_elements(); ++i ) {
css << (i == 0 ? "" : ",") << sec_to_hhmmss(na[i]);
css << (i == 0 ? "" : ",") << na[i];
}

return(css);
Expand All @@ -1276,28 +1309,17 @@ ConcatString write_css_hhmmss(const NumArray &na)
////////////////////////////////////////////////////////////////////////


double NumArray::mean_abs_diff() const
ConcatString write_css_hhmmss(const NumArray &na)

{

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

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++;
}
for ( int i=0; i<na.n_elements(); ++i ) {
css << (i == 0 ? "" : ",") << sec_to_hhmmss(na[i]);
}

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

return(mad);
return(css);

}

Expand Down
1 change: 1 addition & 0 deletions src/basic/vx_util/num_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class NumArray {
double mean_sqrt() const;
double mean_fisher() const;
double mean_abs_diff() const;
double weighted_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 2c13f4a

Please sign in to comment.