From 8807e753df3a18d9a60917d9b2d5a157c116cf0f Mon Sep 17 00:00:00 2001 From: Shin Date: Sun, 30 Oct 2016 20:45:06 +0100 Subject: [PATCH] removed Cellular encoding --- CMakeLists.txt | 3 - .../CelularEncoding/Cell.h | 182 ------------- .../CelularEncoding/CelularEncoding.h | 182 ------------- .../CelularEncoding/Exception.h | 23 -- .../CelularEncoding/Instruction/Bias.h | 143 ---------- .../CelularEncoding/Instruction/Division.h | 101 -------- .../CelularEncoding/Instruction/Finish.h | 58 ----- .../CelularEncoding/Instruction/Instruction.h | 32 --- .../CelularEncoding/Instruction/Link.h | 245 ------------------ .../CelularEncoding/Instruction/Other.h | 34 --- .../CellularEncoding/Cell.cpp | 12 - .../CellularEncoding/CellularEncoding.cpp | 20 -- tests/CMakeLists.txt | 6 - 13 files changed, 1041 deletions(-) delete mode 100644 include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Cell.h delete mode 100644 include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/CelularEncoding.h delete mode 100644 include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Exception.h delete mode 100644 include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Instruction/Bias.h delete mode 100644 include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Instruction/Division.h delete mode 100644 include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Instruction/Finish.h delete mode 100644 include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Instruction/Instruction.h delete mode 100644 include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Instruction/Link.h delete mode 100644 include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Instruction/Other.h delete mode 100644 src/NeuralNetwork/ConstructiveAlgorithms/CellularEncoding/Cell.cpp delete mode 100644 src/NeuralNetwork/ConstructiveAlgorithms/CellularEncoding/CellularEncoding.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index cc802dc..a3b7b1c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,9 +76,6 @@ set (LIBRARY_SOURCES src/NeuralNetwork/Neuron.cpp src/NeuralNetwork/IMPL.cpp - - src/NeuralNetwork/ConstructiveAlgorithms/CellularEncoding/CellularEncoding.cpp - src/NeuralNetwork/ConstructiveAlgorithms/CellularEncoding/Cell.cpp ) add_library(NeuralNetwork STATIC ${LIBRARY_SOURCES}) diff --git a/include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Cell.h b/include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Cell.h deleted file mode 100644 index 03fa359..0000000 --- a/include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Cell.h +++ /dev/null @@ -1,182 +0,0 @@ -#pragma once - -#include -#include "./Instruction/Instruction.h" - -#include -#include - -namespace NeuralNetworks { -namespace ConstructiveAlgorithms { -namespace CelularEncoding { - class CelularEncoding; - - class Link { - public: - Link(bool status_, float value_, std::size_t neuron_) : status(status_), value(value_), neuron(neuron_) { - - } - - bool status=false; - float value=0.0; - std::size_t neuron; - }; - - class Cell { - friend Instruction::Instruction; - - public: - Cell(const Cell&)=delete; - Cell&operator=(const Cell&)=delete; - - Cell(Cell &&r): id(r.id), codePtr(r.codePtr), _isOutput(r._isOutput), _isInput(r._isInput), alive(r.alive), life(r.life), bias(r.bias), links(r.links) { - - } - - Cell(const std::size_t& id_, const EvolutionaryAlgorithm::GeneticPrograming::CodeTree* codePtr_): id(id_), codePtr(codePtr_) { - - } - - void step(CelularEncoding&); - - bool isAlive() const { - return alive; - }; - - void die() { - alive=false; - }; - - std::size_t getLife() const { - return life; - } - - void setLife(const std::size_t &newLife) { - life=newLife; - } - - float getBias() const { - return bias; - } - void setBias(const float &newBias) { - bias=newBias; - } - - std::size_t getLinkRegister() const { - return linkRegister; - } - - void setLinkRegister(const std::size_t &newLinkRegister) { - linkRegister=newLinkRegister; - } - - const std::vector& getLinks() const { - return links; - } - - void setLinks(const std::vector &links_) { - links=links_; - } - - void addLink(const Link& l) { - for(auto &link:links) { - if(link.neuron ==l.neuron) { - link.value=l.value; - link.status=l.status; - return; - } - } - links.push_back(l); - } - - bool getLinkStatus(const std::size_t index) const { - if(index < links.size()) { - return links[index].status; - } - return false; - } - - void setLinkStatus(const std::size_t index, const bool &status) { - if(index < links.size()) { - links[index].status=status; - } - } - - float getLinkValue(const std::size_t index) const { - if(index < links.size()) { - return links[index].value; - } - return 0.0; - } - - void setLinkValue(const std::size_t index, const float &value) { - if(index < links.size()) { - links[index].value = value; - } - } - - void setCodePointer(const EvolutionaryAlgorithm::GeneticPrograming::CodeTree *c) { - codePtr=c; - } - - const EvolutionaryAlgorithm::GeneticPrograming::CodeTree* getCodePointer() const { - return codePtr; - } - - std::size_t getID() const { - return id; - } - - bool isOutput() const { - return _isOutput; - } - - void setOutput() { - _isOutput=true; - } - void disableOutput() { - _isOutput=false; - } - - bool isInput() const { - return _isInput; - } - - void setInput() { - _isInput=true; - } - void disableInput() { - _isInput=false; - } - - protected: - std::size_t id; - - const EvolutionaryAlgorithm::GeneticPrograming::CodeTree *codePtr; - //const Code &code; - - bool _isOutput=false; - bool _isInput=false; - - bool alive=true; - std::size_t life=1; - float bias = 0.0; - - std::size_t linkRegister=0; - - std::vector links = std::vector(); -/* - std::size_t codePosition; - std::size_t linkRegister; - - std::size_t sigme; - std::size_t dyn; - std::size_t link; - std::size_t simplif; -*/ - // 150 of paper - private: - }; -} -} -} \ No newline at end of file diff --git a/include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/CelularEncoding.h b/include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/CelularEncoding.h deleted file mode 100644 index 7f38fab..0000000 --- a/include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/CelularEncoding.h +++ /dev/null @@ -1,182 +0,0 @@ -#pragma once - -#include "Exception.h" -#include "Cell.h" - -#include - -#include -#include - -namespace NeuralNetworks { - namespace ConstructiveAlgorithms { - namespace CelularEncoding { - class CelularEncoding { - public: - CelularEncoding(const CelularEncoding &) = delete; - - CelularEncoding &operator=(const CelularEncoding &) = delete; - - CelularEncoding() { - - } - - void setActivationFunction(const std::shared_ptr &fun) { - _activationFunction=fun; - } - - void setMaxSteps(std::size_t steps) { - _maxSteps=steps; - } - - NeuralNetwork::Recurrent::Network run() { - std::size_t cellsStep = 0; - std::size_t steps=0; - do { - cellsStep = step(); - steps++; - } - while(cellsStep > 0 && steps < _maxSteps); - - if(steps >= _maxSteps) { - throw Exception("Went over max steps"); - } - - if(cells.size() > _maxCells) { - throw Exception("Went over max cells"); - } - - std::size_t outputs = 0; - std::size_t inputs = 0; - - std::vector cells2Neurons; - cells2Neurons.resize(cells.size()); - - std::size_t indexOfNeuronTmp=1; - - for(std::size_t i = 0; i < cells.size(); i++) { - if(cells[i]->isInput()) { - cells2Neurons[i] = indexOfNeuronTmp++; - inputs++; - } - } - - for(std::size_t i = 0; i < cells.size(); i++) { - if(cells[i]->isOutput()) { - if(!cells[i]->isInput()) { - cells2Neurons[i] = indexOfNeuronTmp++; - } - outputs++; - } - } - - for(std::size_t i = 0; i < cells.size(); i++) { - if(!cells[i]->isOutput() && !cells[i]->isInput()) { - cells2Neurons[i] = indexOfNeuronTmp++; - } - } - - std::size_t hiddenNeurons = static_cast(cells.size()) - static_cast(inputs) - static_cast(outputs) < 0 ? 0 : cells.size() - inputs - outputs; - - NeuralNetwork::Recurrent::Network netw(inputs, outputs, hiddenNeurons); - for(std::size_t i = 0; i < cells.size(); i++) { - - const auto &cell = cells[i]; - - std::size_t indexOfNeuron = cells2Neurons[i]; - auto& neuron = netw[indexOfNeuron]; - if(cells2Neurons[i] > inputs) { - neuron.setActivationFunction(*_activationFunction); - } - - neuron.weight(0)=cell->getBias(); - - for(auto &link: cells[i]->getLinks()) { - if(link.status == true) { - neuron.weight(cells2Neurons[link.neuron]) = link.value; - } else { - neuron.weight(cells2Neurons[link.neuron]) = 0.0; - } - } - } - - return netw; - } - - Cell &addCell(const EvolutionaryAlgorithm::GeneticPrograming::CodeTree *c) { - cells.push_back(std::make_shared(cells.size(), c)); - - return (*cells.back()); - } - - void setAcyclicTopology() { - cells.clear(); -/* - for(std::size_t i = 0; i < inputSize; i++) { - addCell(code).die(); - } -*/ - Cell &cell = addCell(code); - cell.setLife(_initialLife); - _processingOrder.push_back(cell.getID()); - - cell.setOutput(); - cell.setInput(); -/* - for(std::size_t i = 0; i < inputSize; i++) { - Link l(true, 1.0, i); - cell.addLink(l); - } -*/ - } - - void setCyclicTopology() { - setAcyclicTopology(); - // Acyclic + reccurent link - Link l(true, 1.0, cells.back()->getID()); - cells.back()->addLink(l); - } - - void setCode(const EvolutionaryAlgorithm::GeneticPrograming::CodeTree *code_) { - code = code_; - } - - const EvolutionaryAlgorithm::GeneticPrograming::CodeTree *getCodeStart() const { - return code; - } - - std::vector> &getCells() { - return cells; - } - - void addCellToProcessingOrder(std::size_t id) { - auto position = std::find(_processingOrder.begin(),_processingOrder.end(),currentID); - if(position == _processingOrder.end()) { - _processingOrder.push_back(id); - } else { - _processingOrder.insert(position+1,id); - } - } - - void setInitiaLife(std::size_t life) { - _initialLife=life; - } - - protected: - std::size_t step(); - - private: - std::size_t _maxCells= 15; - std::size_t _maxSteps = std::numeric_limits::max(); - std::size_t _initialLife = 2.0; - - std::shared_ptr _activationFunction = std::make_shared(); - std::vector _processingOrder = {}; - std::size_t currentID = 0; - const EvolutionaryAlgorithm::GeneticPrograming::CodeTree *code = nullptr; - std::vector> cells = {}; - }; - - } - } -} \ No newline at end of file diff --git a/include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Exception.h b/include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Exception.h deleted file mode 100644 index 9830a23..0000000 --- a/include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Exception.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include -#include - -namespace NeuralNetworks { - namespace ConstructiveAlgorithms { - namespace CelularEncoding { - class Exception : public std::exception { - public: - Exception (const std::string &e) : _what(e) { - - } - - virtual const char* what() const noexcept override { - return _what.c_str(); - } - protected: - std::string _what; - }; - } - } -} \ No newline at end of file diff --git a/include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Instruction/Bias.h b/include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Instruction/Bias.h deleted file mode 100644 index c040140..0000000 --- a/include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Instruction/Bias.h +++ /dev/null @@ -1,143 +0,0 @@ -#pragma once - -#include "./Instruction.h" -#include "../Cell.h" -#include "../CelularEncoding.h" - -namespace NeuralNetworks { -namespace ConstructiveAlgorithms { -namespace CelularEncoding { -namespace Instruction{ - class IncBias : public Instruction{ - public: - virtual void run(Cell &cell, CelularEncoding &, const std::vector &) override { - cell.setBias(cell.getBias()+1.0); - cell.setCodePointer(cell.getCodePointer()->c1); - } - - virtual std::size_t numberOfNodes() const override { - return 1; - } - - virtual std::string toString() const override { - return "IncBias"; - } - }; - - class DecBias : public Instruction{ - public: - virtual void run(Cell &cell, CelularEncoding &, const std::vector &) override { - cell.setBias(cell.getBias()-1.0); - cell.setCodePointer(cell.getCodePointer()->c1); - } - - virtual std::size_t numberOfNodes() const override { - return 1; - } - - virtual std::string toString() const override { - return "DecBias"; - } - - }; - class MulBias : public Instruction{ - public: - virtual void run(Cell &cell, CelularEncoding &, const std::vector &) override { - cell.setBias(cell.getBias()*2.0); - cell.setCodePointer(cell.getCodePointer()->c1); - } - - virtual std::size_t numberOfNodes() const override { - return 1; - } - - virtual std::string toString() const override { - return "MulBias"; - } - }; - - class DivBias : public Instruction{ - public: - virtual void run(Cell &cell, CelularEncoding &, const std::vector &) override { - cell.setBias(cell.getBias()*0.5); - cell.setCodePointer(cell.getCodePointer()->c1); - } - - virtual std::size_t numberOfNodes() const override { - return 1; - } - - virtual std::string toString() const override { - return "DivBias"; - } - }; - - class SetBiasZero : public Instruction{ - public: - SetBiasZero(bool terminal = true) : _nodes(terminal ? 0 : 1) { - - } - - virtual void run(Cell &cell, CelularEncoding &, const std::vector &) override { - cell.setBias(0.0); - cell.setCodePointer(cell.getCodePointer()->c1); - } - - virtual std::size_t numberOfNodes() const override { - return _nodes; - } - - virtual std::string toString() const override { - return "SetBiasZero"; - } - protected: - std::size_t _nodes; - }; - - class SetBiasOne : public Instruction{ - public: - SetBiasOne(bool terminal = true) : _nodes(terminal ? 0 : 1) { - - } - - virtual void run(Cell &cell, CelularEncoding &, const std::vector &) override { - cell.setBias(1.0); - cell.setCodePointer(cell.getCodePointer()->c1); - } - - virtual std::size_t numberOfNodes() const override { - return _nodes; - } - - virtual std::string toString() const override { - return "SetBiasZero"; - } - protected: - std::size_t _nodes; - }; - - class SetBiasMinusOne : public Instruction{ - public: - SetBiasMinusOne(bool terminal = true) : _nodes(terminal ? 0 : 1) { - - } - - virtual void run(Cell &cell, CelularEncoding &, const std::vector &) override { - cell.setBias(-1.0); - cell.setCodePointer(cell.getCodePointer()->c1); - } - - virtual std::size_t numberOfNodes() const override { - return _nodes; - } - - virtual std::string toString() const override { - return "SetBiasZero"; - } - protected: - std::size_t _nodes; - }; -} -} -} -} \ No newline at end of file diff --git a/include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Instruction/Division.h b/include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Instruction/Division.h deleted file mode 100644 index 5e30fff..0000000 --- a/include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Instruction/Division.h +++ /dev/null @@ -1,101 +0,0 @@ -#pragma once - -#include "./Instruction.h" -#include "../Cell.h" -#include "../CelularEncoding.h" - -namespace NeuralNetworks { -namespace ConstructiveAlgorithms { -namespace CelularEncoding { -namespace Instruction{ - class Par : public Instruction{ - public: - virtual void run(Cell &cell, CelularEncoding &encoding, const std::vector &) override { - Cell &newCell = encoding.addCell(cell.getCodePointer()->c2); - - if(cell.isOutput()) { - newCell.setOutput(); - } - - if(cell.isInput()) { - newCell.setInput(); - } - - newCell.setLife(cell.getLife()); - newCell.setBias(cell.getBias()); - - newCell.setLinks(cell.getLinks()); - - for(auto &cellI:encoding.getCells()) { - for( const Link &link: cellI->getLinks()) { - if(link.neuron == cell.getID()) { - Link newLink (link); - newLink.neuron=newCell.getID(); - cellI->addLink(newLink); - break; - } - } - } - encoding.addCellToProcessingOrder(newCell.getID()); - cell.setCodePointer(cell.getCodePointer()->c1); - } - - virtual std::size_t numberOfNodes() const override { - return 2; - } - - virtual std::string toString() const override { - return "Par"; - } - - protected: - private: - }; - - class Seq : public Instruction{ - public: - virtual void run(Cell &cell, CelularEncoding &encoding, const std::vector &) override { - Cell &newCell = encoding.addCell(cell.getCodePointer()->c2); - - Link l(true, 1.0, cell.getID()); - - if(cell.isOutput()) { - newCell.setOutput(); - cell.disableOutput(); - } - - newCell.addLink(l); - - for(auto& cellIter:encoding.getCells()) { - if(cellIter->getID() != newCell.getID()) { - auto links = cellIter->getLinks(); - for(auto& link: links) { - if(link.neuron==cell.getID()) { - link.neuron=newCell.getID(); - } - } - cellIter->setLinks(links); - } - } - - newCell.setLife(cell.getLife()); - encoding.addCellToProcessingOrder(newCell.getID()); - cell.setCodePointer(cell.getCodePointer()->c1); - //TODO: copy registers - } - - virtual std::size_t numberOfNodes() const override { - return 2; - } - - virtual std::string toString() const override { - return "Seq"; - } - - protected: - private: - }; -} -} -} -} \ No newline at end of file diff --git a/include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Instruction/Finish.h b/include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Instruction/Finish.h deleted file mode 100644 index 89d4bbd..0000000 --- a/include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Instruction/Finish.h +++ /dev/null @@ -1,58 +0,0 @@ -#pragma once - -#include "./Instruction.h" -#include "../Cell.h" -#include "../CelularEncoding.h" - -namespace NeuralNetworks { -namespace ConstructiveAlgorithms { -namespace CelularEncoding { -namespace Instruction{ - class End : public Instruction{ - public: - virtual void run(Cell &cell, CelularEncoding &, const std::vector &) override { - cell.die(); - } - - virtual std::size_t numberOfNodes() const override { - return 0; - } - - virtual std::string toString() const override { - return "End"; - } - protected: - private: - }; - - class Rec : public Instruction{ - public: - Rec(bool terminal = true) : _nodes(terminal ? 0 : 1) { - - } - - virtual void run(Cell &cell, CelularEncoding &encoding, const std::vector &) override { - if(cell.getLife()<=1) { - cell.setCodePointer(cell.getCodePointer()->c1); - cell.die(); - }else { - cell.setLife(cell.getLife()-1); - cell.setCodePointer(encoding.getCodeStart()); - } - } - - virtual std::size_t numberOfNodes() const override { - return _nodes; - } - - virtual std::string toString() const override { - return "Rec"; - } - protected: - std::size_t _nodes; - private: - }; -} -} -} -} \ No newline at end of file diff --git a/include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Instruction/Instruction.h b/include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Instruction/Instruction.h deleted file mode 100644 index 8d785cb..0000000 --- a/include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Instruction/Instruction.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include - -#include - -namespace NeuralNetworks { -namespace ConstructiveAlgorithms { -namespace CelularEncoding { - - class Cell; - class CelularEncoding; - - namespace Instruction { - class Instruction : public EvolutionaryAlgorithm::GeneticPrograming::Instruction { - public: - virtual ~Instruction() { - - } - - // todo what implement?? - void operator()() {} - - virtual void run(Cell &, CelularEncoding &, const std::vector &) = 0; - - protected: - private: - }; - } -} -} -} \ No newline at end of file diff --git a/include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Instruction/Link.h b/include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Instruction/Link.h deleted file mode 100644 index b52860b..0000000 --- a/include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Instruction/Link.h +++ /dev/null @@ -1,245 +0,0 @@ -#pragma once - -#include "./Instruction.h" -#include "../Cell.h" -#include "../CelularEncoding.h" - -namespace NeuralNetworks { - namespace ConstructiveAlgorithms { - namespace CelularEncoding { - namespace Instruction { - class Inclr : public Instruction { - public: - virtual void run(Cell &cell, CelularEncoding &, const std::vector &) override { - if(cell.getLinkRegister() == cell.getLinks().size() - 1) { - cell.setLinkRegister(0); - } else { - cell.setLinkRegister(cell.getLinkRegister() + 1); - } - cell.setCodePointer(cell.getCodePointer()->c1); - } - - virtual std::size_t numberOfNodes() const override { - return 1; - } - - virtual std::string toString() const override { - return "IncLr"; - } - - protected: - private: - }; - - class Declr : public Instruction { - public: - virtual void run(Cell &cell, CelularEncoding &, const std::vector &) override { - if(cell.getLinkRegister() == 0) { - if(cell.getLinks().size() > 1) { - cell.setLinkRegister(cell.getLinks().size() - 1); - } - } else { - cell.setLinkRegister(cell.getLinkRegister() - 1); - } - - cell.setCodePointer(cell.getCodePointer()->c1); - } - - virtual std::size_t numberOfNodes() const override { - return 1; - } - - virtual std::string toString() const override { - return "Declr"; - } - - protected: - private: - }; - - class ValPlus : public Instruction { - public: - virtual void run(Cell &cell, CelularEncoding &, const std::vector &) override { - cell.setLinkValue(cell.getLinkRegister(), 1.0); - cell.setCodePointer(cell.getCodePointer()->c1); - } - - virtual std::size_t numberOfNodes() const override { - return 1; - } - - virtual std::string toString() const override { - return "Val+"; - } - - protected: - private: - }; - - class ValMinus : public Instruction { - public: - virtual void run(Cell &cell, CelularEncoding &, const std::vector &) override { - cell.setLinkValue(cell.getLinkRegister(), -1.0); - cell.setCodePointer(cell.getCodePointer()->c1); - } - - virtual std::size_t numberOfNodes() const override { - return 1; - } - - virtual std::string toString() const override { - return "Val-"; - } - - protected: - private: - }; - - class Inc : public Instruction { - public: - virtual void run(Cell &cell, CelularEncoding &, const std::vector &) override { - cell.setLinkValue(cell.getLinkRegister(), cell.getLinkValue(cell.getLinkRegister()) + 1.0); - cell.setCodePointer(cell.getCodePointer()->c1); - } - - virtual std::size_t numberOfNodes() const override { - return 1; - } - - virtual std::string toString() const override { - return "Inc"; - } - - protected: - private: - }; - - class Dec : public Instruction { - public: - virtual void run(Cell &cell, CelularEncoding &, const std::vector &) override { - cell.setLinkValue(cell.getLinkRegister(), cell.getLinkValue(cell.getLinkRegister()) - 1.0); - cell.setCodePointer(cell.getCodePointer()->c1); - } - - virtual std::size_t numberOfNodes() const override { - return 1; - } - - virtual std::string toString() const override { - return "Dec"; - } - - protected: - private: - }; - - class Mult : public Instruction { - public: - virtual void run(Cell &cell, CelularEncoding &, const std::vector &) override { - cell.setLinkValue(cell.getLinkRegister(), cell.getLinkValue(cell.getLinkRegister()) * 2.0); - cell.setCodePointer(cell.getCodePointer()->c1); - } - - virtual std::size_t numberOfNodes() const override { - return 1; - } - - virtual std::string toString() const override { - return "Mult"; - } - - protected: - private: - }; - - class Div : public Instruction { - public: - virtual void run(Cell &cell, CelularEncoding &, const std::vector &) override { - cell.setLinkValue(cell.getLinkRegister(), cell.getLinkValue(cell.getLinkRegister()) * 0.5); - cell.setCodePointer(cell.getCodePointer()->c1); - } - - virtual std::size_t numberOfNodes() const override { - return 1; - } - - virtual std::string toString() const override { - return "Div"; - } - - protected: - private: - }; - - class On : public Instruction { - public: - virtual void run(Cell &cell, CelularEncoding &, const std::vector &) override { - cell.setLinkStatus(cell.getLinkRegister(), true); - cell.setCodePointer(cell.getCodePointer()->c1); - } - - virtual std::size_t numberOfNodes() const override { - return 1; - } - - virtual std::string toString() const override { - return "On"; - } - - protected: - private: - }; - - class Cyc : public Instruction { - public: - virtual void run(Cell &cell, CelularEncoding &, const std::vector &) override { - bool exists = false; - for(std::size_t i = 0; i < cell.getLinks().size(); i++) { - auto &link = cell.getLinks()[i]; - if(link.neuron == cell.getID()) { - exists = true; - cell.setLinkStatus(i,true); - } - } - - if(!exists) { - cell.addLink(Link(true, 1.0, cell.getID())); - } - - cell.setCodePointer(cell.getCodePointer()->c1); - } - - virtual std::size_t numberOfNodes() const override { - return 1; - } - - virtual std::string toString() const override { - return "Cyc"; - } - - protected: - private: - }; - - class Off : public Instruction { - public: - virtual void run(Cell &cell, CelularEncoding &, const std::vector &) override { - cell.setLinkStatus(cell.getLinkRegister(), false); - cell.setCodePointer(cell.getCodePointer()->c1); - } - - virtual std::size_t numberOfNodes() const override { - return 1; - } - - virtual std::string toString() const override { - return "Off"; - } - - protected: - private: - }; - } - } - } -} \ No newline at end of file diff --git a/include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Instruction/Other.h b/include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Instruction/Other.h deleted file mode 100644 index e4c0a1f..0000000 --- a/include/NeuralNetwork/ConstructiveAlgorithms/CelularEncoding/Instruction/Other.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include "./Instruction.h" -#include "../Cell.h" -#include "../CelularEncoding.h" - -namespace NeuralNetworks { - namespace ConstructiveAlgorithms { - namespace CelularEncoding { - namespace Instruction{ - class Wait : public Instruction{ - public: - Wait(bool terminal = false) : _numberOfNodes(terminal? 0 : 1) { - - } - - virtual void run(Cell &cell, CelularEncoding &, const std::vector &) override { - cell.setCodePointer(cell.getCodePointer()->c1); - } - - virtual std::size_t numberOfNodes() const override { - return _numberOfNodes; - } - - virtual std::string toString() const override { - return "Wait"; - } - protected: - std::size_t _numberOfNodes; - }; - } - } - } -} \ No newline at end of file diff --git a/src/NeuralNetwork/ConstructiveAlgorithms/CellularEncoding/Cell.cpp b/src/NeuralNetwork/ConstructiveAlgorithms/CellularEncoding/Cell.cpp deleted file mode 100644 index f5e1aed..0000000 --- a/src/NeuralNetwork/ConstructiveAlgorithms/CellularEncoding/Cell.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -void NeuralNetworks::ConstructiveAlgorithms::CelularEncoding::Cell::step(CelularEncoding &c) { - if(isAlive()) { - reinterpret_cast(codePtr->instruction.lock().get())->run(*this, c, codePtr->parameters); - } - - if(codePtr == nullptr) { - die(); - } -} \ No newline at end of file diff --git a/src/NeuralNetwork/ConstructiveAlgorithms/CellularEncoding/CellularEncoding.cpp b/src/NeuralNetwork/ConstructiveAlgorithms/CellularEncoding/CellularEncoding.cpp deleted file mode 100644 index ae62066..0000000 --- a/src/NeuralNetwork/ConstructiveAlgorithms/CellularEncoding/CellularEncoding.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include - -std::size_t NeuralNetworks::ConstructiveAlgorithms::CelularEncoding::CelularEncoding::step() { - std::size_t activeCellCount = 0; - std::vector processingOrder(_processingOrder); - for(std::size_t i = 0; i < processingOrder.size(); i++) { - std::size_t cell = processingOrder[i]; - if(cells[cell]->isAlive()) { - currentID = cells[cell]->getID(); - cells[cell]->step(*this); - activeCellCount++; - } else { - auto iter = std::find(_processingOrder.begin(), _processingOrder.end(), cell); - if(iter != _processingOrder.end()) { - _processingOrder.erase(iter); - } - } - } - return activeCellCount; -} \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c3aa6d5..09ef39a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -28,12 +28,6 @@ target_link_libraries(recurrent NeuralNetwork gtest gtest_main) add_executable(quickpropagation quickpropagation.cpp) target_link_libraries(quickpropagation NeuralNetwork gtest gtest_main) -add_executable(celular_code celular_code.cpp) -target_link_libraries(celular_code NeuralNetwork gtest gtest_main) - -add_executable(genetic_programing genetic_programing.cpp) -target_link_libraries(genetic_programing NeuralNetwork gtest gtest_main) - # PERF add_executable(backpropagation_function_cmp backpropagation_function_cmp.cpp)