OCR / XOR / NN / NN_Tools / error.c
error.c
Raw
#include "error.h"

float MeanSquaredError(t_layer* output, float* expected)
{
	float f = 0;
	for (int i = 0; i < output->nbNeuron; i++)
	{
		f += pow(expected[i] - output->neuron[i], 2);
	}
	return f / output->nbNeuron;

}

float* MeanSquaredError_Derivative(t_layer* output, float* expected)
{
	int count = output->nbNeuron;
	float* ret = CreateMatrix(count, 1);
	float f = 2.0 / count;

	for (int i = 0; i < count; i++)
	{
		ret[i] = f * (output->neuron[i] - expected[i]);
	}
	return ret;
}