Guest User

GaussianTerms

a guest
May 3rd, 2015
3,440
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. double Guassian(int x, double sigma)
  2. {
  3.     double c = 2.0 * sigma * sigma;
  4.     return Math.Exp(-x * x / c) / Math.Sqrt(c * Math.PI);
  5. }
  6. double[] GuassianTerms(int kernalSize, double sigma)
  7. {
  8.     var terms = new double[kernalSize];
  9.     for (int i = 0; i < kernalSize; ++i) {
  10.         terms[i] = Guassian(i - kernalSize / 2, sigma);
  11.     }
  12.     return terms;
  13. }
  14. void Main()
  15. {
  16.     var terms = GuassianTerms(5, 1);
  17.     var sum = terms.Aggregate((t1, t2) => t1 + t2); // aggregate to normalise result
  18.     Console.WriteLine(String.Join("\r\n", terms.Select(i => (i / sum).ToString("0.00000"))));
  19. }
RAW Paste Data