Advertisement
szmelu

PSI1

Oct 12th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <ctime>
  4. #include <cstdlib>
  5. using namespace std;
  6. float* NN(float *a, float W, float b) {
  7. float * nowa = new float[100];
  8. for (int i = 0; i<100; i++) {
  9. nowa[i] = W*a[i] + b;
  10. }
  11. return nowa;
  12. }
  13.  
  14. float MSE(float *a, float *b){
  15. float wynik=0.0;
  16. for(int i=0;i<100;i++){
  17. wynik+=(a[i]-b[i])*(a[i]-b[i]);
  18. }
  19. return wynik/100.0;
  20. }
  21.  
  22. int main()
  23. {
  24. srand(time(NULL));
  25. //y=2x+0,5
  26. float x[100];
  27. float y[100];
  28. for(int i = 0; i<100; i++){
  29. x[i]=( float ) rand() / RAND_MAX *2;
  30. y[i]=2*x[i]+0.5;
  31. }
  32.  
  33. float w, b;
  34. w = ( float )rand() / RAND_MAX *6-3;
  35. b = ( float )rand() / RAND_MAX *6-3;
  36.  
  37. float * Z = NN(x, w, b);
  38. float mse = MSE(y, Z);
  39. cout <<mse<<endl;
  40. Z = NN(x, 2, 0.5);
  41. mse = MSE(y, Z);
  42. cout << mse;
  43. system("pause");
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement