Skip to content

Instantly share code, notes, and snippets.

@Alakhator

Alakhator/c++9.cpp

Created Apr 10, 2020
Embed
What would you like to do?
for (int i = 0; i < 40; i ++) { //Since there are 10 values in our dataset and we want to run for 4 epochs so total for loop run 40 times
int idx = i % 10; //for accessing index after every epoch
double p = -(b0 + b1 * x1[idx]+ b2* x2[idx]); //making the prediction
double pred = 1/(1+ pow(e,p)); //calculating final prediction applying sigmoid
err = y[idx]-pred; //calculating the error
b0 = b0 - alpha * err*pred *(1-pred)* 1.0; //updating b0
b1 = b1 + alpha * err * pred*(1-pred) *x1[idx];//updating b1
b2 = b2 + alpha * err * pred*(1-pred) * x2[idx];//updating b2
cout<<"B0="<<b0<<" "<<"B1="<<b1<<" "<<"B2="<<b2<<" error="<<err<<endl;// printing values after every step
error.push_back(err);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment