-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmse.h
33 lines (28 loc) · 948 Bytes
/
mse.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "layer.h"
double mse (const Vector& y_true , const Vector& y_pred)
{
if (y_true.size() != y_pred.size())
{
std::cerr << "Error : size of predicted values and actual values isn't same." << std::endl;
exit(0);
}
double square_diff_sum = 0.00 ;
for (int i = 0 ; i < y_pred.size() ; ++i){
double difference = y_pred[i] - y_true[i];
square_diff_sum = difference * difference;
}
return square_diff_sum / y_pred.size();
}
Vector mse_prime (const Vector& y_true , const Vector& y_pred)
{
if (y_true.size() != y_pred.size())
{
std::cerr << "Error : size of predicted values and actual values isn't same." << std::endl;
exit(0);
}
Vector output_gradient (y_true.size() , 0.00);
for (size_t i = 0; i < y_true.size() ; ++i){
output_gradient[i] = 2 * (y_pred[i] - y_true[i] ) / y_true.size();
}
return output_gradient;
}