summaryrefslogtreecommitdiffstats
path: root/ai/Layer.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2007-05-05 15:57:58 +0000
committerBen Boeckel <MathStuf@gmail.com>2007-05-05 15:57:58 +0000
commit0d2d8121cbb6a45180d88021fe2e5ac86b3532e3 (patch)
tree512385f11f6d152f76ac36c7950bfe75992291ff /ai/Layer.cpp
parent21cb50c82f18b3a2ee1e77a7de11413ce45e6587 (diff)
downloadsigen-0d2d8121cbb6a45180d88021fe2e5ac86b3532e3.tar.gz
sigen-0d2d8121cbb6a45180d88021fe2e5ac86b3532e3.tar.xz
sigen-0d2d8121cbb6a45180d88021fe2e5ac86b3532e3.zip
Got rid of XML for INI format, in process of moving over; added /ai/Net.{h, cpp}
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@8 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'ai/Layer.cpp')
-rw-r--r--ai/Layer.cpp33
1 files changed, 30 insertions, 3 deletions
diff --git a/ai/Layer.cpp b/ai/Layer.cpp
index 6f36be67..97ba87b6 100644
--- a/ai/Layer.cpp
+++ b/ai/Layer.cpp
@@ -1,10 +1,10 @@
/////////////////////////////////////////////////////////////////////////////
-// Name: Layer.cpp
+// Name: ai/Layer.cpp
// Purpose: A layer of a NeuralNet
// Author: Ben Boeckel
// Modified by: Ben Boeckel
// Created: Thu May 5 15:55:21 2007
-// Copyright: ©2007 Ben Boeckel and Nerdy Productions
+// Copyright: ©2007 Nerdy Productions
// Licence:
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -33,6 +33,33 @@ PokeGen::NeuralNetwork::Layer::Layer(Layer *par, Layer *child, int num)
parent->RandomizeWeights();
}
+void PokeGen::NeuralNetwork::Layer::AddNode()
+{
+ nodes.push_back(Node(this, GetNumNodes()));
+ parent->UpdateBias();
+}
+
+void PokeGen::NeuralNetwork::Layer::DeleteNode(int n)
+{
+ if ((0 < n) && (n < GetNumNodes()))
+ {
+ nodes.erase(nodes.begin() + n);
+ parent->UpdateBias(n);
+ }
+}
+
+void PokeGen::NeuralNetwork::Layer::UpdateBias(int n)
+{
+ if (n < 0)
+ bias.push_back((abs(std::rand())%201)/100.0);
+ else if (n < GetNumNodes())
+ bias.erase(bias.begin() + n);
+ else
+ return;
+ for (int i = 0; i < GetNumNodes(); ++i)
+ nodes[i].UpdateWeights(n);
+}
+
int PokeGen::NeuralNetwork::Layer::GetNumNodes()
{
return nodes.size();
@@ -42,7 +69,7 @@ void PokeGen::NeuralNetwork::Layer::RandomizeWeights()
{
bias.clear();
for (int i = 0; i < child->GetNumNodes(); ++i)
- bias.push_back((abs(rand())%201)/100.0);
+ bias.push_back((abs(std::rand())%201)/100.0);
for (int i = 0; i < GetNumNodes(); ++i)
nodes[i].RandomizeWeights();
}