Advertisement
Guest User

Average Accuracy

a guest
Feb 12th, 2013
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. //We are trying to find a mode estimation for a continuous
  2. //distributed set.
  3. //Anyway I am still working on a solution called 'half range method' and I came across a c# peculiarity.
  4. //I have a recursive binary search (essentially) and we are trying to
  5. //performance optimize it by instead of recreating the array of floats each pass,
  6. //use indices to narrow down the search.
  7. //Riddle me this:
  8.  
  9. float test = input.Average();
  10.  
  11. int count = (top - bottom) + 1;//number of elements in this iteration
  12. int pos = bottom;
  13. float average = 0f;//working average
  14. while (pos <= top)
  15. {
  16.      average += input[pos];
  17.      pos++;
  18. }
  19. average = average / count;
  20.  
  21. //my average method returns 2 places less accuracy than c# .Average()
  22. //example:
  23. //0.0371166766 - c#
  24. //0.03711666 - my loop
  25.  
  26. //125090.148 - c#
  27. //125090.281 - my loop
  28.  
  29. //Any light you could shed on the subject would be much appreciated!
  30. //No rush.
  31. //Thanks in advance
  32. // - ST
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement