TarzaNN
TarzaNN neural network simulator
C:/Users/albertlr/projects/TarzaNN/TarzaNN/Network.h
Go to the documentation of this file.
00001 #ifndef NETWORK_H_INCLUDED
00002 #define NETWORK_H_INCLUDED
00003 #include <map>
00004 #include <vector>
00005 
00006 #include <QTextStream>
00007 #include <QFile>
00008 class FeaturePlaneAbstract;
00009 class FeaturePlaneProxy;
00010 class InputFeaturePlane;
00011 class ConstantInputFeaturePlane;
00012 class InputSocketFeaturePlane;
00013 class InputVirtualFeaturePlane;
00014 class LearningFeaturePlane;
00015 class STSOMFeaturePlane;
00016 class SOMFeaturePlane;
00017 
00018 #include "Layer.h"
00019 #include "Node.h"
00020 #include "NodeProxy.h"
00021 
00022 class Network;
00023 class UI_MainWindow;
00024 class Monitor;
00025 typedef void (Network::*pt2Member)(QObject*, char*);
00026 
00027 #ifdef PREDEFINED
00028 enum{NN_XML, NN_2sand5s, NN_ACTIVE_VISION, NN_ROBOT_SOCKET, NN_ROBOT_VIRTUAL, NN_SPIKING, NN_NUM};
00029 #endif /*PREDEFINED*/
00030 
00031 using namespace std;
00032 
00036 class Network {
00037 public:
00038 
00043 #ifdef PREDEFINED
00044         Network(UI_MainWindow *theMainWindow, QObject *app, int configurationNo, char* inputFileName=NULL);
00045 #else
00046         Network(UI_MainWindow *theMainWindow, QObject *app, char* inputFileName=NULL);
00047 #endif /*PREDEFINED*/
00048 
00050         ~Network();
00052         void run();
00054         void terminate();
00055 
00057         void save(QString filename);
00059         void load(char* inputFileName);
00060 
00062         void resetLayers();
00064         void assignLayers();
00065 
00067         void XMLSerialize(int tabs, QTextStream *buf);
00069         static void tabulate(int tabs, QTextStream *buf);
00070 
00071     static Network* theNetworkInstance;
00072 
00073         static Network* getNetwork(){
00074         return theNetworkInstance;
00075     }
00076         static void setNetwork(Network* nn){
00077         theNetworkInstance=nn;
00078     }
00079 
00080         FeaturePlaneAbstract* addFeaturePlane(QString* newName, QString newFPType, paramMap newParams, int l);
00081         FeaturePlaneAbstract* editFeaturePlane(FeaturePlaneAbstract* theOld, QString* newName, QString newFPType, paramMap newParams, int l);
00082         void deleteFeaturePlane(FeaturePlaneAbstract* oldFP);
00083 
00084         FeaturePlaneInput* addFeaturePlaneInput(FeaturePlaneAbstract *FPSource, FeaturePlaneAbstract *FPDest, QString newFType, paramMap newParams, int newInputType, int newOutputIndex);
00085         FeaturePlaneInput* editFeaturePlaneInput(FeaturePlaneInput* oldElement, QString newFType, paramMap newParams, int newInputType, int newOutputIndex);
00086         void deleteFeaturePlaneInput(FeaturePlaneInput* theElement);
00087 
00089         vector<NodeProxy*> _nodeList;
00091         vector<FeaturePlaneAbstract*> _featurePlaneList;
00092         vector<FeaturePlaneAbstract*>* _learningFeaturePlanes;
00094         vector<Layer*> _featurePlaneLayers;
00095         QMutex* _featurePlaneLayerMutex;
00096         QWaitCondition* _featurePlaneLayerCond;
00097 
00099         static bool useStepByStep;
00101         static bool useLayerByLayer;
00102 
00103         // simulation status -> pause, terminate
00104         static QWaitCondition pauseWaitCond;
00105         static QMutex threadStatus;
00106         static bool shouldPause;
00107 
00108 
00109         int addLayer(QString name, int dirs, int scales, int type = 0);
00110         void addToLayer(FeaturePlaneAbstract* cur, int count);
00111         void setMonitor(Monitor* m);
00112         Monitor* getMonitor();
00113         void setLearningOutputFP(LearningFeaturePlane* fp);
00114         LearningFeaturePlane* getLearningOutputFP();
00115         void setLearningWinner(Matrix* c);
00116         Matrix* getLearningWinner();
00117         FeaturePlaneAbstract* getInputFP();
00118         FeaturePlaneAbstract* getFPByName(QString searchName);
00119 
00121         void applyIOR();
00122 
00124         int getLayerCount();
00126         Layer* getLayer(int layerIndex){
00127                 return _featurePlaneLayers[layerIndex];
00128         }
00129 
00131         int getDepth();
00132 
00133         void readLearningLayer();
00134         void readLearningLayer(QString s);
00135         void saveLearningLayer();
00136         void saveLearningLayer(QString s);
00137 
00138         UI_MainWindow* mainWindow;
00139         static bool doSTM_WTA;
00140         bool changed;
00141 
00143         bool isPaused(){return paused;}
00145         void setPaused(bool status){paused=status;}
00146 
00147         void notifyChangeDisplay();
00148 
00149         //*************************************************
00150         //** Executive controller
00151         //** might move to its own class at some point
00152         //*************************************************
00153 
00154 #define THRESHOLD_PERCENT 0.5f
00155 #define BIAS_PASS 1.0f
00156 #define BIAS_INHIBIT 0.2f
00157 #define BIAS_ZERO 0.0f
00158 
00160         void setupFeatureTask();
00162         void setupSpatialTask(OutputImage* tmpSpatialBias);
00163 
00164 
00165 
00166 
00167 private:
00168         void nn_xml(QObject* app, char* inputFileName=NULL);
00169 
00170         void _editFeaturePlaneHelper1(FeaturePlaneAbstract *theOld, FeaturePlaneAbstract *theNew, PlaneInputs* inputList, int type);
00171         void _editFeaturePlaneHelper2(FeaturePlaneAbstract *theOld, FeaturePlaneAbstract *theNew, PlaneInputs* inputList);
00172 
00173         void replaceFP(FeaturePlaneAbstract *theOld, FeaturePlaneAbstract *theNew);
00174         void removeFilter(Filter* theF);
00175         void _replaceFilter(Filter* theOld, Filter* theNew, PlaneInputs* inputList);
00176         void replaceFilter(Filter* oldF, Filter* newF);
00177 
00178         void _replaceFPHelper1(FeaturePlaneAbstract *theOld, FeaturePlaneAbstract *theNew, PlaneInputs* inputList, int type);
00179         void _replaceFPHelper2(FeaturePlaneAbstract *theOld, FeaturePlaneAbstract *theNew, PlaneInputs* inputList);
00180 
00182         Monitor* theMonitor;
00183         Matrix* learningWinner;
00184         LearningFeaturePlane* learningOutputFP;
00185 
00187         void traverseNetwork();
00189         void traverseNetwork(FeaturePlaneAbstract* theFP, int layerIndex, vector<FeaturePlaneAbstract*>*visited);
00191         int depth;
00192 
00194         bool paused;
00195 
00196 #ifdef PREDEFINED
00197         void nn_2sand5s(QObject* app, char* inputFileName=NULL);
00198         void nn_active_vision(QObject* app, char* inputFileName=NULL);
00199         void nn_spiking(QObject* app, char* inputFileName=NULL);
00200         void nn_robot_socket(QObject* app, char* inputFileName=NULL);
00201         void nn_robot_virtual(QObject* app, char* inputFileName=NULL);
00202 
00203         pt2Member function_table[NN_NUM];
00204 #endif /*PREDEFINED*/
00205 
00206 };
00207 #endif //NETWORK_H_INCLUDED
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines