fix error 0.5 and add math pdf
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <hack/logger/logger.hpp>
|
||||
#include "utils.hpp"
|
||||
#include <array>
|
||||
#include <math.h>
|
||||
|
||||
// Линейная форма - это прямой расчет прохода ошибки по математиченским формулам.
|
||||
@@ -26,7 +27,16 @@ namespace linear
|
||||
return 1.0 / (1 + r);
|
||||
}
|
||||
|
||||
inline void run()
|
||||
// Результат одного шага: новые веса, ошибка и выход сети.
|
||||
struct result
|
||||
{
|
||||
utils::matrix_leaner W_1;
|
||||
utils::matrix_leaner W_2;
|
||||
float error;
|
||||
std::array<float, 3> out;
|
||||
};
|
||||
|
||||
inline result run()
|
||||
{
|
||||
std::vector<float> Inp = { 1.0, 2.0, 3.0 };
|
||||
std::vector<float> T = { 0.1, 0.2, 0.3 };
|
||||
@@ -100,10 +110,11 @@ namespace linear
|
||||
hack::log()("Out 2 =", Out_2);
|
||||
hack::log()("Out 3 =", Out_3);
|
||||
|
||||
// Ошибка
|
||||
auto E_1 = std::pow((Out_1 - T[0]), 2);
|
||||
auto E_2 = std::pow((Out_2 - T[1]), 2);
|
||||
auto E_3 = std::pow((Out_3 - T[2]), 2);
|
||||
// Ошибка: E = (1/2) * sum((Out_j - T_j)^2), как в конспекте.
|
||||
const float E_1 = 0.5f * (Out_1 - T[0]) * (Out_1 - T[0]);
|
||||
const float E_2 = 0.5f * (Out_2 - T[1]) * (Out_2 - T[1]);
|
||||
const float E_3 = 0.5f * (Out_3 - T[2]) * (Out_3 - T[2]);
|
||||
const float E = E_1 + E_2 + E_3;
|
||||
|
||||
hack::log()();
|
||||
hack::log()("Ошибка");
|
||||
@@ -111,12 +122,13 @@ namespace linear
|
||||
hack::log()("E 1 =", E_1);
|
||||
hack::log()("E 2 =", E_2);
|
||||
hack::log()("E 3 =", E_3);
|
||||
hack::log()("E =", E);
|
||||
|
||||
// ОБРАТНЫЙ ПРОХОД (backward)
|
||||
// Вклад нейрона в ошибку (дельта)
|
||||
auto delta_1_2 = 2 * (Out_1 - T[0]) * Out_1 * (1 - Out_1);
|
||||
auto delta_2_2= 2 * (Out_2 - T[1]) * Out_2 * (1 - Out_2);
|
||||
auto delta_3_2 = 2 * (Out_3 - T[2]) * Out_3 * (1 - Out_3);
|
||||
const float delta_1_2 = (Out_1 - T[0]) * Out_1 * (1.0f - Out_1);
|
||||
const float delta_2_2 = (Out_2 - T[1]) * Out_2 * (1.0f - Out_2);
|
||||
const float delta_3_2 = (Out_3 - T[2]) * Out_3 * (1.0f - Out_3);
|
||||
|
||||
hack::log()();
|
||||
hack::log()("=========================");
|
||||
@@ -296,5 +308,7 @@ namespace linear
|
||||
hack::log()(W_2[0]);
|
||||
hack::log()(W_2[1]);
|
||||
hack::log()(W_2[2]);
|
||||
|
||||
return { W_1, W_2, E, { Out_1, Out_2, Out_3 } };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user