Working net, calculates the mean value of two inputs
This commit is contained in:
parent
6ed30e56c4
commit
4eb232b1e9
2 changed files with 28 additions and 7 deletions
|
@ -46,13 +46,13 @@ void Layer::connectTo(const Layer & nextLayer)
|
||||||
{
|
{
|
||||||
for (Neuron &neuron : *this)
|
for (Neuron &neuron : *this)
|
||||||
{
|
{
|
||||||
neuron.createOutputWeights(nextLayer.sizeWithoutBiasNeuron(), 0.5);
|
neuron.createOutputWeights(nextLayer.sizeWithoutBiasNeuron(), 1.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layer::updateInputWeights(Layer & prevLayer)
|
void Layer::updateInputWeights(Layer & prevLayer)
|
||||||
{
|
{
|
||||||
static const double trainingRate = 0.2;
|
static const double trainingRate = 0.3;
|
||||||
|
|
||||||
for (size_t targetLayerIndex = 0; targetLayerIndex < sizeWithoutBiasNeuron(); ++targetLayerIndex)
|
for (size_t targetLayerIndex = 0; targetLayerIndex < sizeWithoutBiasNeuron(); ++targetLayerIndex)
|
||||||
{
|
{
|
||||||
|
|
31
Neuro.cpp
31
Neuro.cpp
|
@ -2,8 +2,12 @@
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#include "Net.h"
|
#include "Net.h"
|
||||||
|
|
||||||
|
const double pi = std::acos(-1);
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -12,7 +16,12 @@ int main()
|
||||||
|
|
||||||
Net myNet({ 2, 3, 1 });
|
Net myNet({ 2, 3, 1 });
|
||||||
|
|
||||||
size_t numIterations = 10000;
|
size_t batchSize = 5000;
|
||||||
|
size_t batchIndex = 0;
|
||||||
|
double batchMaxError = 0.0;
|
||||||
|
double batchMeanError = 0.0;
|
||||||
|
|
||||||
|
size_t numIterations = 1000000;
|
||||||
for (size_t iteration = 0; iteration < numIterations; ++iteration)
|
for (size_t iteration = 0; iteration < numIterations; ++iteration)
|
||||||
{
|
{
|
||||||
std::vector<double> inputValues =
|
std::vector<double> inputValues =
|
||||||
|
@ -23,7 +32,7 @@ int main()
|
||||||
|
|
||||||
std::vector<double> targetValues =
|
std::vector<double> targetValues =
|
||||||
{
|
{
|
||||||
*std::max_element(inputValues.begin(), inputValues.end())
|
(inputValues[0] + inputValues[1]) / 2.0
|
||||||
};
|
};
|
||||||
|
|
||||||
myNet.feedForward(inputValues);
|
myNet.feedForward(inputValues);
|
||||||
|
@ -32,9 +41,21 @@ int main()
|
||||||
|
|
||||||
double error = outputValues[0] - targetValues[0];
|
double error = outputValues[0] - targetValues[0];
|
||||||
|
|
||||||
std::cout << "Error: ";
|
batchMeanError += error;
|
||||||
std::cout << std::abs(error);
|
batchMaxError = std::max<double>(batchMaxError, error);
|
||||||
std::cout << std::endl;
|
|
||||||
|
if (batchIndex++ == batchSize)
|
||||||
|
{
|
||||||
|
std::cout << "Batch error (" << batchSize << " iterations, max/mean): ";
|
||||||
|
std::cout << std::abs(batchMaxError);
|
||||||
|
std::cout << " / ";
|
||||||
|
std::cout << std::abs(batchMeanError / batchSize);
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
batchIndex = 0;
|
||||||
|
batchMaxError = 0.0;
|
||||||
|
batchMeanError = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
myNet.backProp(targetValues);
|
myNet.backProp(targetValues);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue