# MSE() $MSE(X,Y)=\frac{1}{2n}\Sigma_{i=1}^{n} (X_i-Y_i)^2$

kero.multib.NeuralNetwork.py

def MSE(Y_set,Y0_set):
return mse

Arguments/Return

 Y_set List of numpy matrix, [Y]. Each numpy matrix Y is a column vector Y0_set List of numpy matrix, [Y0]. Each numpy matrix Y is a column vector. There should be equal number of Y in Y_set as Y0 in Y0_set mse Mean squared values computed by the formula above.

Example Usage 1

testMSE.py

Y0_set= [
[1,2,3],
[4,5,6]
]

Y_set = [[1.1*x for x in y] for y in Y0_set]
print("Y0_set=",Y0_set)
print("Y_set=",Y_set)

import numpy as np
# convert to list of numpy matrix
Y0_set = [np.transpose(np.matrix(x)) for x in Y0_set]
Y_set = [np.transpose(np.matrix(x)) for x in Y_set]

import kero.multib.NeuralNetwork as nn

mse=nn.MSE(Y_set,Y0_set)
print("MSE test:\n  mse=",mse)

# manual computation
mse_= 0.01*(1**2+2**2+3**2+4**2+5**2+6**2)
mse_=mse_/(2*2)
print("  compare: ",mse_)

import kero.utils.utils as ut
print("nabla MSE test:\n  nabla mse = ")

nabla_mse = nn.nabla_MSE(Y_set,Y0_set)
ut.print_numpy_matrix(nabla_mse,formatting="%6.2f",no_of_space=5)
nabla_mse_ = 1/2* ((Y_set-Y0_set)+(Y_set-Y0_set))
print("  compare: ")
ut.print_numpy_matrix(nabla_mse_,formatting="%6.2f",no_of_space=5)

This will print

Y0_set= [[1, 2, 3], [4, 5, 6]]
Y_set= [[1.1, 2.2, 3.3000000000000003], [4.4, 5.5, 6.6000000000000005]]
MSE test:
mse= 0.22750000000000029
compare:  0.2275
nabla MSE test:
nabla mse =
0.25
0.35
0.45
compare:
0.25
0.35
0.45

kero version: 0.6.2