BVB Source Codes

Algorithm-Implementations Show stat_mode.c Source code

Return Download Algorithm-Implementations: download stat_mode.c Source code - Download Algorithm-Implementations Source code - Type:.c
  1. // Patrick Yevsukov
  2.  
  3. // 2013 CC BY-NC-SA 4.0 http://patrick.yevsukov.com
  4.  
  5. // github.com/PatrickYevsukov/Statistics-Calculator
  6.  
  7. #include "stat_mode.h"
  8.  
  9. double *
  10. StatMode(double *sample, int *sample_size)
  11. {
  12.     int ii = 0;
  13.  
  14.     int kk = 0;
  15.  
  16.     int num_modes = 0;
  17.  
  18.     int previous_freq = 0;
  19.  
  20.     int current_freq = 1; // Every value must occur at least once
  21.  
  22.     double *modes = NULL;
  23.    
  24.     modes = (double *) malloc(MAX_SAMPLE * sizeof *modes);
  25.  
  26.     for (ii = 0; ii <= *sample_size - 1; ii++)
  27.     {
  28.         if (sample[ii] == sample[ii + 1])
  29.         {
  30.             current_freq++;
  31.         }
  32.         else
  33.         {
  34.             if (current_freq > previous_freq)
  35.             {
  36.                 kk = 0; // Reset
  37.                
  38.                 previous_freq = current_freq;
  39.  
  40.                 modes[kk] = sample[ii];
  41.             }
  42.  
  43.             else if (current_freq == previous_freq)
  44.             {
  45.                 kk++;
  46.  
  47.                 modes[kk] = sample[ii];
  48.             }
  49.  
  50.             current_freq = 1; // Reset
  51.         }
  52.     }
  53.  
  54.     num_modes = kk + 1;
  55.  
  56.     return modes;
  57. }
  58.  
  59. // I devised this algorithm to identify the statistical mode or
  60. // modes of a dataset. It requires one pass through the set to
  61. // identify the set's mode or modes.
  62.  
  63. // This algorithm works by keeping track of the number of times a
  64. // unique value occurs in the set. If a unique value has occurred
  65. // more times than the ones before it, it is added to the list of
  66. // modes. As the loop continues all values which occur this number
  67. // of times are added to the list of modes, unless another unique
  68. // value occurs more times than the currently identified modes. If
  69. // this happens, the mode array indexing variable is reset to zero
  70. // and the previously identified values are overwritten by the new
  71. // modes. When finished, the mode array indexing variable will be
  72. // one less than the number of modes.
  73.  
  74. // This algorithm requires a set of values in which all instances
  75. // of a unique value are listed next to one another.
  76.  
downloadstat_mode.c Source code - Download Algorithm-Implementations Source code
Related Source Codes/Software:
raty - 2017-04-22
RDVTabBarController - Highly customizable tabBar and tabBarController fo... 2017-04-22
material-icon-lib - Library containing over 1500 material vector icons... 2017-04-21
httpdiff - Perform the same request against two HTTP servers ... 2017-04-21
jquerytools - The missing UI library for the Web ... 2017-04-21
mcrouter - Mcrouter is a memcached protocol router for scalin... 2017-04-22
dynomite - A generic dynamo implementation for different k-v ... 2017-04-22
kityminder - Baidu brain figure 2017-04-22
llvm - Mirror of official llvm git repository located at ... 2017-04-22
RBBAnimation - Block-based animations made easy, comes with easin... 2017-04-22
ied - 2017-04-29
Nimble - A Matcher Framework for Swift and Objective-C 2017-04-29
MHVideoPhotoGallery - A Photo and Video Gallery 2017-04-29
shoulda-matchers - Collection of testing matchers extracted from Shou... 2017-04-29
Android-SlideExpandableListView - A better ExpandableListView, with animated expanda... 2017-04-29
AppSales-Mobile - App Sales allows iPhone and Mac App Store develope... 2017-04-29
react-templates - Light weight templates for react ... 2017-04-28
afterglow-theme - A minimal dark Theme for Sublime Text 2 and 3 2017-04-28
jwt-go - Golang implementation of JSON Web Tokens (JWT) 2017-04-28
DeerResume - Tool MarkDown online resume, online preview, edit,... 2017-04-28

 Back to top