Added 64-bit configuration and support

This commit is contained in:
Michael Mandl 2015-10-15 22:37:13 +02:00
parent 953db0a17e
commit ea454b58c6
8 changed files with 81 additions and 10 deletions

View file

@ -1,6 +1,6 @@
#include "Layer.h" #include "Layer.h"
Layer::Layer(unsigned int numNeurons) Layer::Layer(size_t numNeurons)
{ {
for (unsigned int i = 0; i < numNeurons; ++i) for (unsigned int i = 0; i < numNeurons; ++i)
{ {

View file

@ -7,7 +7,7 @@
class Layer : public std::vector < Neuron > class Layer : public std::vector < Neuron >
{ {
public: public:
Layer(unsigned int numNeurons); Layer(size_t numNeurons);
void setOutputValues(const std::vector<double> & outputValues); void setOutputValues(const std::vector<double> & outputValues);
void feedForward(const Layer &inputLayer); void feedForward(const Layer &inputLayer);

View file

@ -1,13 +1,13 @@
#include "Net.h" #include "Net.h"
Net::Net(std::initializer_list<unsigned int> layerSizes) Net::Net(std::initializer_list<size_t> layerSizes)
{ {
if (layerSizes.size() < 3) if (layerSizes.size() < 3)
{ {
throw std::exception("A net needs at least 3 layers"); throw std::exception("A net needs at least 3 layers");
} }
for (unsigned int numNeurons : layerSizes) for (size_t numNeurons : layerSizes)
{ {
push_back(Layer(numNeurons)); push_back(Layer(numNeurons));
} }
@ -67,7 +67,7 @@ void Net::backProp(const std::vector<double> &targetValues)
} }
std::vector<double> resultValues = getOutput(); std::vector<double> resultValues = getOutput();
unsigned int numResultValues = resultValues.size(); size_t numResultValues = resultValues.size();
double rmsError = 0.0; double rmsError = 0.0;
for (unsigned int i = 0; i < numResultValues; ++i) for (unsigned int i = 0; i < numResultValues; ++i)

2
Net.h
View file

@ -7,7 +7,7 @@
class Net : public std::vector < Layer > class Net : public std::vector < Layer >
{ {
public: public:
Net(std::initializer_list<unsigned int> layerSizes); Net(std::initializer_list<size_t> layerSizes);
void feedForward(const std::vector<double> &inputValues); void feedForward(const std::vector<double> &inputValues);
std::vector<double> getOutput(); std::vector<double> getOutput();

View file

@ -1,20 +1,26 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013 # Visual Studio 14
VisualStudioVersion = 12.0.31101.0 VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Neuro", "Neuro.vcxproj", "{EC045881-3BCD-4054-895B-176FAD3FB8C2}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Neuro", "Neuro.vcxproj", "{EC045881-3BCD-4054-895B-176FAD3FB8C2}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32 Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Release|Win32 = Release|Win32 Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EC045881-3BCD-4054-895B-176FAD3FB8C2}.Debug|Win32.ActiveCfg = Debug|Win32 {EC045881-3BCD-4054-895B-176FAD3FB8C2}.Debug|Win32.ActiveCfg = Debug|Win32
{EC045881-3BCD-4054-895B-176FAD3FB8C2}.Debug|Win32.Build.0 = Debug|Win32 {EC045881-3BCD-4054-895B-176FAD3FB8C2}.Debug|Win32.Build.0 = Debug|Win32
{EC045881-3BCD-4054-895B-176FAD3FB8C2}.Debug|x64.ActiveCfg = Debug|x64
{EC045881-3BCD-4054-895B-176FAD3FB8C2}.Debug|x64.Build.0 = Debug|x64
{EC045881-3BCD-4054-895B-176FAD3FB8C2}.Release|Win32.ActiveCfg = Release|Win32 {EC045881-3BCD-4054-895B-176FAD3FB8C2}.Release|Win32.ActiveCfg = Release|Win32
{EC045881-3BCD-4054-895B-176FAD3FB8C2}.Release|Win32.Build.0 = Release|Win32 {EC045881-3BCD-4054-895B-176FAD3FB8C2}.Release|Win32.Build.0 = Release|Win32
{EC045881-3BCD-4054-895B-176FAD3FB8C2}.Release|x64.ActiveCfg = Release|x64
{EC045881-3BCD-4054-895B-176FAD3FB8C2}.Release|x64.Build.0 = Release|x64
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View file

@ -5,10 +5,18 @@
<Configuration>Debug</Configuration> <Configuration>Debug</Configuration>
<Platform>Win32</Platform> <Platform>Win32</Platform>
</ProjectConfiguration> </ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32"> <ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration> <Configuration>Release</Configuration>
<Platform>Win32</Platform> <Platform>Win32</Platform>
</ProjectConfiguration> </ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup> </ItemGroup>
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<ProjectGuid>{EC045881-3BCD-4054-895B-176FAD3FB8C2}</ProjectGuid> <ProjectGuid>{EC045881-3BCD-4054-895B-176FAD3FB8C2}</ProjectGuid>
@ -22,6 +30,12 @@
<PlatformToolset>v140</PlatformToolset> <PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
@ -29,22 +43,41 @@
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup> </ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup> </ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental> <LinkIncremental>true</LinkIncremental>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental> <LinkIncremental>false</LinkIncremental>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile> <ClCompile>
<PrecompiledHeader> <PrecompiledHeader>
@ -59,6 +92,20 @@
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile> <ClCompile>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
@ -77,6 +124,24 @@
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Layer.cpp" /> <ClCompile Include="Layer.cpp" />
<ClCompile Include="Net.cpp" /> <ClCompile Include="Net.cpp" />

View file

@ -39,7 +39,7 @@ double Neuron::getWeightedOutputValue(unsigned int outputNeuron) const
return 0.0; return 0.0;
} }
void Neuron::createRandomOutputWeights(unsigned int numberOfWeights) void Neuron::createRandomOutputWeights(size_t numberOfWeights)
{ {
outputWeights.clear(); outputWeights.clear();

View file

@ -17,7 +17,7 @@ public:
static double transferFunctionDerivative(double inputValue); static double transferFunctionDerivative(double inputValue);
void feedForward(double inputValue); void feedForward(double inputValue);
double getWeightedOutputValue(unsigned int outputNeuron) const; double getWeightedOutputValue(unsigned int outputNeuron) const;
void createRandomOutputWeights(unsigned int numberOfWeights); void createRandomOutputWeights(size_t numberOfWeights);
double getOutputValue() const; double getOutputValue() const;
void calcOutputGradients(double targetValue); void calcOutputGradients(double targetValue);