📄 ann.h
字号:
/* YAKS, Optann, a Khepera simulator including a separate GA and ANN (Genetic Algoritm, Artificial Neural Net). Copyright (C) 2000 Johan Carlsson (johanc@ida.his.se) 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 the Free Software Foundation; either version 2 of the License, or any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */#ifndef ANN_H#define ANN_H#include <stdlib.h>#include <stdio.h>#include <iostream.h>#include "neuron.h"#include "balloc/balloc.h"/*! \struct valuesS ann.h * \brief Structure for storing doubles. * * Used in various returns. */typedef struct{ /*! \var valuesS::nodes Number of doubles contained in the values list. */ int nodes; /*! \var valuesS::values An array of 'nodes' doubles. */ double *values;}valuesS;/** @class Ann ann.h * @brief ANN - Artificial Neural Net class, contains and maintains Neurons. * * This Neural Net implementation is based on the idee that all neurons has an * activation priority that determines when a neuron is activated. Neurons are * activated in rising order so the neuron with the smallest priority get * activated first. Neurons can all have unique prioritys or group of neurons * can share the same priority and by doing so form a "layer". * * @see Neuron */class Ann{ public: Ann(); Ann(int dontCare); ~Ann(); class Ann *duplicate() const; void addNeuron(int iLayerPriority, NODE_T inType, ACTIVATION_T iFuncT); void removeNeuron(int index); void connectNeurons(class Neuron *from, class Neuron *to, int initWeight); void connectLayer(int fromPri, int toPri); void connectLayerWithSCN(int fromPri, int toPri, int scnPri); void removeConnection(class Neuron *from, class Neuron *to); void copyWeightsFrom(class Ann *from); void mutateNeurons(int bitMutateProbability); void mutateNeuronsWithPri(int bitMutateProbability, int pri); valuesS *getValuesFromNodesWithPriority(int pri); void activateNet(); void resetNet(); int8_t getLinkWeight(int neuron,int link) const; int8_t *getLinkWeightPointer(int neuron,int link); int getNrOfLinks(int neuron) const; double getOutput(int index)const; double *getOutputPtr(int index); void setInput(int index,double value); double getInput(int index) const; double *getInputPointer(int index); double *getActivationPointer(int index); int getNrOfInputNodes() const; int getNrOfOutputNodes() const; int getNrOfNodes() const; void printNet() const; void saveWeights(FILE *fp) const; void loadWeights(FILE *fp); void compareAnn(class Ann *net) const; private: int countSCNNodesWithPri(int scnPri) const; int countUnUsedSCNNodesWithPri(int scnPri) const; int countNodesWithPri(int cntPri) const; int nextUnUsedSCNNodeWithPri(int scnPri) const; void addNeuron(int iLayerPriority, NODE_T inType, ACTIVATION_T iFuncT, long int id); void addInNode(class Neuron *node); void addOutNode(class Neuron *node); void addSCNNode(class Neuron *node); void sort(); /** Pointers to the actual neurons in an unsorted order. */ Neuron **neurons; /** Help pointers to output **neurons. */ Neuron **outNodes; /** Help pointers to input **neurons. */ Neuron **inNodes; /** Help pointers to **neurons sorted in activation order. */ Neuron **actOrder; /** Help pointers to SCN **neurons. */ Neuron **SCNNodes; /** Total number of neurons, includes all neurons even bias. */ int nrOfNeurons; /** Total number of neurons declared as input neurons. */ int nrOfInputs; /** Total number of neurons declared as output neurons. */ int nrOfOutputs; /** Total number of neurons declared as SCN neurons. */ int nrOfSCNs;};#endif /* ANN_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -