From 37b5153d6a595dda3410443c1b54947caee57643 Mon Sep 17 00:00:00 2001 From: mandlm Date: Mon, 26 Oct 2015 20:34:26 +0100 Subject: [PATCH] Cleaned up code to work with MinGW/GCC Kit --- Layer.cpp | 4 +++- Net.cpp | 12 +++++++----- Net.h | 1 + Neuron.cpp | 6 ++++-- Neuron.h | 2 ++ 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Layer.cpp b/Layer.cpp index 4b14db9..96010c5 100644 --- a/Layer.cpp +++ b/Layer.cpp @@ -1,5 +1,7 @@ #include "Layer.h" +#include + Layer::Layer(size_t numNeurons) { for (unsigned int i = 0; i < numNeurons; ++i) @@ -12,7 +14,7 @@ void Layer::setOutputValues(const std::vector & outputValues) { 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(); diff --git a/Net.cpp b/Net.cpp index 2a540b3..62c786d 100644 --- a/Net.cpp +++ b/Net.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include Net::Net() { @@ -25,7 +27,7 @@ void Net::initialize(std::initializer_list layerSizes) 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) @@ -50,7 +52,7 @@ void Net::feedForward(const std::vector &inputValues) 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); @@ -83,7 +85,7 @@ void Net::backProp(const std::vector &targetValues) 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 resultValues = getOutput(); @@ -133,7 +135,7 @@ void Net::save(const std::string &filename) outFile.open(filename); 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; @@ -163,7 +165,7 @@ void Net::load(const std::string &filename) inFile.open(filename, std::ios::binary); if (!inFile.is_open()) { - throw std::exception("unable to open input file"); + throw std::runtime_error("unable to open input file"); } clear(); diff --git a/Net.h b/Net.h index ad2e53c..41a80c0 100644 --- a/Net.h +++ b/Net.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "Layer.h" diff --git a/Neuron.cpp b/Neuron.cpp index afa6a5e..5df927a 100644 --- a/Neuron.cpp +++ b/Neuron.cpp @@ -1,6 +1,8 @@ -#pragma once - #include "Neuron.h" + +#include +#include + #include "Layer.h" Neuron::Neuron(double value) diff --git a/Neuron.h b/Neuron.h index 20b1684..c4ac780 100644 --- a/Neuron.h +++ b/Neuron.h @@ -1,5 +1,7 @@ #pragma once +#include + #include #include