Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <ctime>
- using namespace std;
- double w0, w1, w2, w3, w4, w5; // wagi
- double b1, b2, b3; // biasy
- double random() // losuje 0.01 - 1.00
- return ((rand()%100)+1)/100.0;
- }
- double sigmoid(double x) // funkcja aktywuj¹ca
- {
- return 1/(1+exp(-x));
- }
- double derivsigmoid(double x)
- {
- return sigmoid(x)*(1-sigmoid(x));
- }
- double mse_loss(double* y, double* ypred, int n) // n - liczba probek, ypred - wartosci obliczone, y - wartosci docelowe
- {
- double result = 0;
- for(int i=0; i<n; i++)
- result+=pow((y[i]-ypred[i]), 2);
- return result/(double)n;
- }
- double feedforward(double* x) // wynik neuronu
- {
- double h0 = sigmoid(w0*x[0] + w1*x[1] + b1);
- double h1 = sigmoid(w2*x[0] + w3*x[1] + b2);
- return sigmoid(w4*h0 + w5*h1 + b2);
- }
- void train(double* data, double* y, double learn_rate, int epochs, int n)
- {
- for(int i=0; i<epochs; i++)
- {
- // inicjacja neuronu + losowanie wag
- // feedforward dla calej sieci
- // calculate mse
- // calculate delta (W4, W5, B2, H0, H1, W0, W1, B1, W2, W3, B2)
- // aktualizacja wag
- }
- if(epochs%n==0) // co ile n wypisac dane
- {
- //ypred = feedforward()
- //mseloss(y,ypred)
- //print mse, ypred
- }
- }
- int main()
- {
- srand(time(NULL));
- w0 = random();
- w1 = random();
- w2 = random();
- w3 = random();
- w4 = random();
- w5 = random();
- b1 = random();
- b2 = random();
- b3 = random();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement