Advertisement
Guest User

Untitled

a guest
May 29th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. private double Pearson(ObiektDecyzyjny a, ObiektDecyzyjny b)
  2. {
  3. double x1 = 0.00;
  4. double y1 = 0.00;
  5. for (var i = 0; i < a.deskryptory.Count(); i++)
  6. {
  7. x1 += a.deskryptory[i].wartosc;
  8. y1 += b.deskryptory[i].wartosc;
  9. }
  10. x1 = x1 / a.deskryptory.Count();
  11. y1 = y1 / b.deskryptory.Count();
  12.  
  13. double x2 = 0.00;
  14. double y2 = 0.00;
  15. for (var i = 0; i < a.deskryptory.Count(); i++)
  16. {
  17. x2 += Math.Pow(a.deskryptory[i].wartosc - x1, 2);
  18. y2 += Math.Pow(b.deskryptory[i].wartosc - y1, 2);
  19. }
  20. x2 = Math.Sqrt(x2 / a.deskryptory.Count());
  21. y2 = Math.Sqrt(y2 / b.deskryptory.Count());
  22. double r = 0.00;
  23. for (var i = 0; i < a.deskryptory.Count(); i++)
  24. {
  25. r += ((a.deskryptory[i].wartosc - x1) / x2) * ((b.deskryptory[i].wartosc - y1) / y2);
  26. }
  27. r = r / a.deskryptory.Count();
  28. double d = 0;
  29. d = 1 - (Math.Abs(r));
  30. return d;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement