SHARE
TWEET

Untitled

DarkGenius Mar 4th, 2015 233 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. static Dictionary<Double, Double> calc_distribution(List<double> v, int n){
  2.             var result = new Dictionary<double, double>();
  3.             double wmin = v[0], wmax = v[0];
  4.             int wcount = 0;
  5.             int wzero = 0;
  6.             foreach (var p in v){
  7.                 if (p == -1) continue;
  8.                 if (p == 0) ++wzero;
  9.                 if (p < wmin) wmin = p;
  10.                 if (p > wmax) wmax = p;
  11.                 ++wcount;
  12.             }
  13.             double delta = (wmax-wmin)/n;
  14.    
  15.             List<double> c = new List<double>();
  16.             c.AddRange(Enumerable.Repeat<double>(0,n));
  17.             foreach (var p in v){
  18.                 if (p < 0) continue;
  19.                 int i = Math.Min((int)(p/delta),c.Count-1);
  20.                 ++c[i];
  21.             }
  22.             result.Add(0,(double)wzero/wcount);
  23.             result.Add(delta, c[0] / wcount);
  24.             for (int i=1; i<c.Count; ++i){
  25.                 c[i] += c[i-1];
  26.                 result.Add(delta * (i + 1), c[i] / wcount);
  27.             }
  28.             return result;
  29.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top