The source code and dockerfile for the GSW2024 AI Lab.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

51 lines
1.0 KiB

4 weeks ago
  1. /*Curve fitting problem by Least Squares
  2. Nigel_Galloway@operamail.com
  3. October 1st., 2007
  4. */
  5. set Sample;
  6. param Sx {z in Sample};
  7. param Sy {z in Sample};
  8. var X;
  9. var Y;
  10. var Ex{z in Sample};
  11. var Ey{z in Sample};
  12. /* sum of variances is zero for Sx*/
  13. variencesX{z in Sample}: X + Ex[z] = Sx[z];
  14. zumVariancesX: sum{z in Sample} Ex[z] = 0;
  15. /* sum of variances is zero for Sy*/
  16. variencesY{z in Sample}: Y + Ey[z] = Sy[z];
  17. zumVariancesY: sum{z in Sample} Ey[z] = 0;
  18. solve;
  19. param b1 := (sum{z in Sample} Ex[z]*Ey[z])/(sum{z in Sample} Ex[z]*Ex[z]);
  20. printf "\nbest linear fit is:\n\ty = %f %s %fx\n\n", Y-b1*X, if b1 < 0 then "-" else "+", abs(b1);
  21. data;
  22. param:
  23. Sample: Sx Sy :=
  24. 1 0 1
  25. 2 0.5 0.9
  26. 3 1 0.7
  27. 4 1.5 1.5
  28. 5 1.9 2
  29. 6 2.5 2.4
  30. 7 3 3.2
  31. 8 3.5 2
  32. 9 4 2.7
  33. 10 4.5 3.5
  34. 11 5 1
  35. 12 5.5 4
  36. 13 6 3.6
  37. 14 6.6 2.7
  38. 15 7 5.7
  39. 16 7.6 4.6
  40. 17 8.5 6
  41. 18 9 6.8
  42. 19 10 7.3
  43. ;
  44. end;