Cleaned up code to work with MinGW/GCC Kit
This commit is contained in:
parent
1e716979a9
commit
37b5153d6a
5 changed files with 17 additions and 8 deletions
|
@ -1,5 +1,7 @@
|
||||||
#include "Layer.h"
|
#include "Layer.h"
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
Layer::Layer(size_t numNeurons)
|
Layer::Layer(size_t numNeurons)
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < numNeurons; ++i)
|
for (unsigned int i = 0; i < numNeurons; ++i)
|
||||||
|
@ -12,7 +14,7 @@ void Layer::setOutputValues(const std::vector<double> & outputValues)
|
||||||
{
|
{
|
||||||
if (size() - 1 != outputValues.size())
|
if (size() - 1 != outputValues.size())
|
||||||
{
|
{
|
||||||
throw std::exception("The number of output values has to match the layer size");
|
throw std::runtime_error("The number of output values has to match the layer size");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto neuronIt = begin();
|
auto neuronIt = begin();
|
||||||
|
|
12
Net.cpp
12
Net.cpp
|
@ -3,6 +3,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
Net::Net()
|
Net::Net()
|
||||||
{
|
{
|
||||||
|
@ -25,7 +27,7 @@ void Net::initialize(std::initializer_list<size_t> layerSizes)
|
||||||
|
|
||||||
if (layerSizes.size() < 2)
|
if (layerSizes.size() < 2)
|
||||||
{
|
{
|
||||||
throw std::exception("A net needs at least 2 layers");
|
throw std::runtime_error("A net needs at least 2 layers");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t numNeurons : layerSizes)
|
for (size_t numNeurons : layerSizes)
|
||||||
|
@ -50,7 +52,7 @@ void Net::feedForward(const std::vector<double> &inputValues)
|
||||||
|
|
||||||
if (inputLayer.size() - 1 != inputValues.size())
|
if (inputLayer.size() - 1 != inputValues.size())
|
||||||
{
|
{
|
||||||
throw std::exception("The number of input values has to match the input layer size");
|
throw std::runtime_error("The number of input values has to match the input layer size");
|
||||||
}
|
}
|
||||||
|
|
||||||
inputLayer.setOutputValues(inputValues);
|
inputLayer.setOutputValues(inputValues);
|
||||||
|
@ -83,7 +85,7 @@ void Net::backProp(const std::vector<double> &targetValues)
|
||||||
|
|
||||||
if (targetValues.size() != outputLayer.size())
|
if (targetValues.size() != outputLayer.size())
|
||||||
{
|
{
|
||||||
throw std::exception("The number of target values has to match the output layer size");
|
throw std::runtime_error("The number of target values has to match the output layer size");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<double> resultValues = getOutput();
|
std::vector<double> resultValues = getOutput();
|
||||||
|
@ -133,7 +135,7 @@ void Net::save(const std::string &filename)
|
||||||
outFile.open(filename);
|
outFile.open(filename);
|
||||||
if (!outFile.is_open())
|
if (!outFile.is_open())
|
||||||
{
|
{
|
||||||
throw std::exception("unable to open output file");
|
throw std::runtime_error("unable to open output file");
|
||||||
}
|
}
|
||||||
|
|
||||||
outFile << size() << std::endl;
|
outFile << size() << std::endl;
|
||||||
|
@ -163,7 +165,7 @@ void Net::load(const std::string &filename)
|
||||||
inFile.open(filename, std::ios::binary);
|
inFile.open(filename, std::ios::binary);
|
||||||
if (!inFile.is_open())
|
if (!inFile.is_open())
|
||||||
{
|
{
|
||||||
throw std::exception("unable to open input file");
|
throw std::runtime_error("unable to open input file");
|
||||||
}
|
}
|
||||||
|
|
||||||
clear();
|
clear();
|
||||||
|
|
1
Net.h
1
Net.h
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "Layer.h"
|
#include "Layer.h"
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Neuron.h"
|
#include "Neuron.h"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <random>
|
||||||
|
|
||||||
#include "Layer.h"
|
#include "Layer.h"
|
||||||
|
|
||||||
Neuron::Neuron(double value)
|
Neuron::Neuron(double value)
|
||||||
|
|
2
Neuron.h
2
Neuron.h
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue