Changeset eac29c7


Ignore:
Timestamp:
11/15/18 17:01:27 (2 years ago)
Author:
Jacob Van Walraven <jcv9@…>
Branches:
develop
Children:
f611921
Parents:
96ec511
Message:

Improve skewness calculation by using median instead of mode

File:
1 edited

Legend:

Unmodified
Added
Removed
  • examples/tutorial/ipdist-parallel.c

    r96ec511 reac29c7  
    3333        double mean_src[4];
    3434        double mean_dst[4];
     35        double median_src[4];
     36        double median_dst[4];
    3537        double stddev_src[4];
    3638        double stddev_dst[4];
     
    6466uint64_t tickrate;
    6567
    66 char *stats_outputdir = "/home/jcv9/output-spectre/";
     68char *stats_outputdir = "";
    6769/* Calculate and plot the percentage change from the previous plot */
    6870int stats_percentage_change = 0;
     
    159161                        }
    160162                }
     163
    161164                tally->stats->mean_src[k] = (k + (ex / n));
    162165                tally->stats->variance_src[k] = ((ex2 - (ex*ex)/n) / n);
     
    180183                tally->stats->variance_dst[k] = ((ex2 - (ex*ex)/n) / n);
    181184                tally->stats->stddev_dst[k] = sqrt(tally->stats->variance_dst[k]);
    182 
     185                /* Get the median */
     186                int c = (n/2) - tally->src[k][0];
     187                int c2 = 0;
     188                while(c > 0) {
     189                        c2 += 1;
     190                        c -= tally->src[k][c2];
     191                }
     192                tally->stats->median_src[k] = c2;
     193                c = (n/2) - tally->dst[k][0];
     194                c2 = 0;
     195                while(c > 0) {
     196                        c2 += 1;
     197                        c -= tally->dst[k][c2];
     198                }
     199                tally->stats->median_dst[k] = c2;
     200                /* Get the mode which is the first item in the priority queue */
    183201                tally->stats->mode_src[k] = peak(&tally->stats->rank_src[k]);
    184202                tally->stats->mode_dst[k] = peak(&tally->stats->rank_src[k]);
    185                 /* Calculate skewness using pearsons mode method. This is accurate with large amounts of data */
    186                 tally->stats->skewness_src[k] = (tally->stats->mean_src[k] - tally->stats->mode_src[k]) / tally->stats->stddev_src[k];
    187                 tally->stats->skewness_dst[k] = (tally->stats->mean_dst[k] - tally->stats->mode_dst[k]) / tally->stats->stddev_dst[k];
    188         }
    189 
    190         printf("skewnesss: %f\n", tally->stats->skewness_dst[1]);
     203                /* Calculate skewness */
     204                tally->stats->skewness_src[k] = (tally->stats->mean_src[k] - tally->stats->median_src[k]) / tally->stats->stddev_src[k];
     205                tally->stats->skewness_dst[k] = (tally->stats->mean_dst[k] - tally->stats->median_dst[k]) / tally->stats->stddev_dst[k];
     206        }
    191207
    192208}
     
    392408                tally->stats->mean_src[i] = 0;
    393409                tally->stats->mean_dst[i] = 0;
     410                tally->stats->median_src[i] = 0;
     411                tally->stats->median_dst[i] = 0;
    394412                tally->stats->stddev_src[i] = 0;
    395413                tally->stats->stddev_dst[i] = 0;
     
    452470        tmp = fopen(outputfile_stats, "w");
    453471        /* append stats data to end of file */
    454         fprintf(tmp, "#\tmean\tstddev\tvariance\tmode\tskewness\n");
     472        fprintf(tmp, "#\tmean\tstddev\tvariance\tmedian\tmode\tskewness\n");
    455473        for(i=0;i<4;i++) {
    456                 fprintf(tmp, "src%d\t%0.f\t%0.f\t%0.f\t\t%0.f\t%f\n", i+1, tally->stats->mean_src[i], tally->stats->stddev_src[i], tally->stats->variance_src[i], tally->stats->mode_src[i], tally->stats->skewness_src[i]);
    457                 fprintf(tmp, "dst%d\t%0.f\t%0.f\t%0.f\t\t%0.f\t%f\n", i+1, tally->stats->mean_dst[i], tally->stats->stddev_dst[i], tally->stats->variance_dst[i], tally->stats->mode_dst[i], tally->stats->skewness_dst[i]);
     474                fprintf(tmp, "src%d\t%0.f\t%0.f\t%0.f\t\t%0.f\t%0.f\t%f\n", i+1, tally->stats->mean_src[i], tally->stats->stddev_src[i], tally->stats->variance_src[i], tally->stats->median_src[i], tally->stats->mode_src[i], tally->stats->skewness_src[i]);
     475                fprintf(tmp, "dst%d\t%0.f\t%0.f\t%0.f\t\t%0.f\t%0.f\t%f\n", i+1, tally->stats->mean_dst[i], tally->stats->stddev_dst[i], tally->stats->variance_dst[i], tally->stats->median_src[i], tally->stats->mode_dst[i], tally->stats->skewness_dst[i]);
    458476                fprintf(tmp, "\n\n");
    459477        }
Note: See TracChangeset for help on using the changeset viewer.