-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Began implementation.
- Loading branch information
Showing
5 changed files
with
152 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
# Things I need to do! | ||
# Updated 16th July 2011 | ||
# Updated 24th July 2011 | ||
|
||
# Improvements | ||
|
||
- For ease, make Net extend Neuron | ||
|
||
# Tests to write | ||
|
||
|
||
# New features | ||
|
||
- More logical realisations(and, xor, nor, xnor) | ||
- More logical realisations(xor, nor, xnor) | ||
- Hopfield net | ||
- MLP | ||
- Kohonen net |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* File: ANDnet.h | ||
* Author: will | ||
* | ||
* Created on July 24, 2011, 9:15 AM | ||
*/ | ||
|
||
#ifndef ANDNET_H | ||
#define ANDNET_H | ||
|
||
#define NET_TYPE_ANDNET "ANDNET" | ||
|
||
#include "nn-simulator/main/nets/BDN/LogicalArchitecture.h" | ||
#include "nn-simulator/main/model/Net.h" | ||
#include "nn-simulator/main/model/Input.h" | ||
|
||
class ANDnet : public Net { | ||
public: | ||
ANDnet(int const noInputs); | ||
virtual ~ANDnet(); | ||
protected: | ||
virtual void createInputVectors(); | ||
virtual void createLayers(); | ||
virtual void createNeurons(); | ||
private: | ||
int noInputs; | ||
Input *expectedInput; | ||
Input *necessaryInput; | ||
}; | ||
|
||
#endif /* ANDNET_H */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* File: ANDnet.cpp | ||
* Author: will | ||
* | ||
* Created on July 24, 2011, 9:15 AM | ||
*/ | ||
|
||
#include "nn-simulator/main/nets/BDN/realisations/ANDnet.h" | ||
#include "nn-simulator/main/nets/BDN/BDNTrainer.h" | ||
#include "nn-simulator/main/nets/BDN/BDN.h" | ||
#include "nn-simulator/main/nets/NeuronFactory.h" | ||
|
||
using namespace std; | ||
|
||
ANDnet::ANDnet(int const noInputs) : | ||
Net(auto_ptr<Architecture>(new LogicalArchitecture()), 1, noInputs, | ||
NET_TYPE_ANDNET) { | ||
ANDnet::noInputs = noInputs; | ||
createInputVectors(); | ||
createLayers(); | ||
createNeurons(); | ||
} | ||
|
||
ANDnet::~ANDnet() { | ||
} | ||
|
||
void ANDnet::createInputVectors() { | ||
expectedInput = new Input(noInputs); | ||
necessaryInput = new Input(noInputs); | ||
for (int i = 0; i < getNoInputs(); i++) { | ||
expectedInput->setValue(i, 1.0f); | ||
necessaryInput->setValue(i, 1.0f); | ||
} | ||
} | ||
|
||
void ANDnet::createLayers() { | ||
Layer *l = new Layer(1, false); | ||
setLayer(0, auto_ptr<Layer > (l)); | ||
} | ||
|
||
void ANDnet::createNeurons() { | ||
auto_ptr<BDN> n = Factory<BDN, Architecture>:: | ||
createInstance((*getArchitecture()), getNoInputs()); | ||
n->setExpectedInput(auto_ptr<Input > (expectedInput)); | ||
n->setNecessaryInput(auto_ptr<Input > (necessaryInput)); | ||
BDNTrainer *trainer = (BDNTrainer*) getArchitecture()->getTrainer(); | ||
trainer->initWeights(n.get()); | ||
trainer->setThreshold(n.get()); | ||
auto_ptr<Neuron> neuronPointer = auto_ptr<Neuron > (n); | ||
getLayer(0)->setNeuron(0, neuronPointer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* File: ANDnetTest.cpp | ||
* Author: will | ||
* | ||
* Created on July 24, 2011, 9:25 AM | ||
*/ | ||
|
||
#include "gtest/gtest.h" | ||
#include "nn-simulator/main/nets/BDN/realisations/ANDnet.h" | ||
#include "nn-simulator/main/model/Input.h" | ||
#include "nn-simulator/main/nets/BDN/LogicalArchitecture.h" | ||
#include "nn-simulator/main/nets/BDN/BDN.h" | ||
|
||
namespace { | ||
|
||
class ANDnetTest : public ::testing::Test { | ||
protected: | ||
|
||
ANDnetTest() { | ||
noInputs = 1; | ||
net = new ANDnet(noInputs); | ||
} | ||
|
||
virtual ~ANDnetTest() { | ||
delete net; | ||
} | ||
|
||
int noInputs; | ||
ANDnet *net; | ||
}; | ||
|
||
/* | ||
* Tests whether the parent constructor is called | ||
* correctly. | ||
* | ||
*/ | ||
TEST_F(ANDnetTest, ConstructorTest) { | ||
EXPECT_EQ(noInputs, net->getNoInputs()); | ||
EXPECT_EQ(1, net->getNoLayers()); | ||
EXPECT_EQ(0, strcmp(NET_TYPE_ANDNET, net->getNetType())); | ||
LogicalArchitecture *la = (LogicalArchitecture*) | ||
net->getArchitecture(); | ||
Layer *l = net->getLayer(0); | ||
BDN *bdn = (BDN*) l->getNeuron(0); | ||
} | ||
|
||
/* | ||
* Tests whether the function works correctly. | ||
* | ||
*/ | ||
TEST_F(ANDnetTest, FunctionTest) { | ||
Input trueInput = Input(noInputs); | ||
for (int i = 0; i < noInputs; i++) { | ||
trueInput.setValue(i, 1.0f); | ||
} | ||
EXPECT_EQ(1.0f, net->processInput(trueInput).getValue()); | ||
|
||
Input falseInput = Input(noInputs); | ||
for (int i = 0; i < noInputs; i++) { | ||
falseInput.setValue(i, (i == 0) ? 1.0f : 0.0f); | ||
} | ||
EXPECT_EQ(0.0f, net->processInput(falseInput).getValue()); | ||
} | ||
} |