I've been studying NNs with tensorflow and decided to code a simple NN from scratch to get a better idea on hwo they work.
It my understanding that the cost is used in backpropagation, so basically you calculate the error between prediction and actual and backpropagate from there.
However, in all the examples I read online, even the ones doing classification, just use:
error=actual-prediction instead of: error=mse(actual-prediction) or: error=cross_entropy(actual-prediction)
And they leave mae/rmse etc just as a metric, as per my understanding (probably wrong) understanding, these should/could be used to calculate the error as well. On the other hand, while working with tensorflow, the loss function I use, does change the output and its not just a metric.
What's my error in here?
In other words, isn't the loss function same as the error function?
Example code (taken from: machinelearninggeek.com/backpropagation-neural-network-using-python/):
Note how the MSE is used as metric only, while backpropagation only uses pred-outputs. (E1 = A2 - y_train)
for itr in range(iterations):
# feedforward propagation
# on hidden layer
Z1 = np.dot(x_train, W1)
A1 = sigmoid(Z1)
# on output layer
Z2 = np.dot(A1, W2)
A2 = sigmoid(Z2)
# Calculating error
mse = mean_squared_error(A2, y_train)
acc = accuracy(A2, y_train)
results=results.append({"mse":mse, "accuracy":acc},ignore_index=True )
# backpropagation
E1 = A2 - y_train
dW1 = E1 * A2 * (1 - A2)
E2 = np.dot(dW1, W2.T)
dW2 = E2 * A1 * (1 - A1)
# weight updates
W2_update = np.dot(A1.T, dW1) / N
W1_update = np.dot(x_train.T, dW2) / N
W2 = W2 - learning_rate * W2_update
W1 = W1 - learning_rate * W1_update
```