Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. double w0, w1, w2, w3, w4, w5; // wagi
  8. double b1, b2, b3; // biasy
  9.  
  10. double random() // losuje 0.01 - 1.00
  11.     return ((rand()%100)+1)/100.0;
  12. }
  13.  
  14. double sigmoid(double x) // funkcja aktywuj¹ca
  15. {
  16.     return 1/(1+exp(-x));
  17. }
  18.  
  19. double derivsigmoid(double x)
  20. {
  21.     return sigmoid(x)*(1-sigmoid(x));
  22. }
  23.  
  24. double mse_loss(double* y, double* ypred, int n) // n - liczba probek, ypred - wartosci obliczone, y - wartosci docelowe
  25. {
  26.     double result = 0;
  27.     for(int i=0; i<n; i++)
  28.         result+=pow((y[i]-ypred[i]), 2);
  29.     return result/(double)n;
  30. }
  31.  
  32. double feedforward(double* x) // wynik neuronu
  33. {
  34.     double h0 = sigmoid(w0*x[0] + w1*x[1] + b1);
  35.     double h1 = sigmoid(w2*x[0] + w3*x[1] + b2);
  36.     return sigmoid(w4*h0 + w5*h1 + b2);
  37. }
  38.  
  39. void train(double* data, double* y, double learn_rate, int epochs, int n)
  40. {
  41.     for(int i=0; i<epochs; i++)
  42.     {
  43.  
  44.         // inicjacja neuronu + losowanie wag
  45.  
  46.         // feedforward dla calej sieci
  47.         // calculate mse
  48.         // calculate delta  (W4, W5, B2, H0, H1, W0, W1, B1, W2, W3, B2)
  49.         // aktualizacja wag
  50.     }
  51.  
  52.     if(epochs%n==0) // co ile n wypisac dane
  53.     {
  54.         //ypred = feedforward()
  55.         //mseloss(y,ypred)
  56.         //print mse, ypred
  57.     }
  58. }
  59.  
  60. int main()
  61. {
  62.     srand(time(NULL));
  63.     w0 = random();
  64.     w1 = random();
  65.     w2 = random();
  66.     w3 = random();
  67.     w4 = random();
  68.     w5 = random();
  69.     b1 = random();
  70.     b2 = random();
  71.     b3 = random();
  72.  
  73.  
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement