TarzaNN
TarzaNN neural network simulator
C:/Users/albertlr/projects/TarzaNN/TarzaNN/FeaturePlaneAbstract.h
Go to the documentation of this file.
00001 #ifndef FEATUREPLANEABSTRACT_H_INCLUDED
00002 #define FEATUREPLANEABSTRACT_H_INCLUDED
00003 
00004 
00005 class FeaturePlaneInput;
00006 
00007 #include <vector>
00008 
00009 #include <set>
00010 #include <stdlib.h>
00011 #include <string.h>
00012 #include <QMutex>
00013 #include <QSemaphore>
00014 
00015 #include <QRunnable>
00016 #include <QWaitCondition>
00017 #include <QTextStream>
00018 #include "common.h"
00019 #include "nowarn.h"
00020 #include "Observer.h"
00021 #include "Viewable.h"
00022 #include "Filter.h"
00023 #include "OutputImage.h"
00024 #include "FeaturePlaneHelpers.h"
00025 #include "NotifyStrategyAbstract.h"
00026 #include "Neuron.h"
00027 #include "FPDesignerInfo.h"
00028 
00029 typedef std::vector<FeaturePlaneInput*> PlaneInputs;
00030 
00031 using namespace std;
00032 
00033 class UI_NeuronTimeCourse;
00034 class UI_FeaturePlane;
00035 
00036 class NodeAbstract;
00037 class NodeProxy;
00038 class Neuron;
00039 class Network;
00040 class Layer;
00041 
00042 #define DO_WTA (is_WTA &&  Network::doSTM_WTA)
00043 
00044 class FeaturePlaneAbstract : public QRunnable, public Observer, public Viewable{
00045         friend class FeaturePlaneFactory;
00046         friend class ClientSocket;
00047         friend class UI_FeaturePlaneProp;
00048         friend class UI_FilterProp;
00049         friend class Network;
00050         friend class UI_DesignerPropDisplay;
00051 
00052 public:
00054         ~FeaturePlaneAbstract();
00055 
00057         void run();
00058 
00060         void notify();
00063         void notify(bool functional);
00064 
00065         virtual void updateNN(Observer* sourceFP, bool functional);
00066 
00068         void attachProxy(NodeProxy* np);
00069 
00071         void addToHistory(OutputImage* tmpElement, set<OutputImage*>* tmpOutputHistory);
00072 
00074         void addToHistory(OutputImage* tmpElement, set<OutputImage*>* tmpOutputHistory, OutputImage **currOutput, QMutex *currOutputMutex);
00075 
00077         void emptyHistory( set<OutputImage*>* tmpOutputHistory);
00078 
00079         void StartThread();
00080         void PauseThread();
00081 
00082         void TerminateThread();
00083 
00089         void setName(QString* tmpName);
00091         double getDisplayScale();
00093         double getDisplayAngle();
00095         double getDisplayDelta();
00096 
00098         QString* getName();
00099 
00101         void setTheta(float t);
00102 
00104         void setLayerIndex(int l);
00105 
00107         int getLayerIndex();
00108 
00110         Layer* getLayer(int layerIndex);
00111 
00112         inline int getSpeeds(){return speeds;}
00113         inline int getSpeed(){return speed;}
00114         inline int getAngles(){return angles;}
00115         inline int getAngle(){return alpha;}
00116 
00118         void setFeatureBias(float tmpBias);
00120         float getFeatureBias();
00122         void setSpatialBias(Matrix * tmpSpatialBias);
00123 
00126         void setSpatialTaskBias(OutputImage* tmpSpatialBias);
00127 
00128         int getXSize();
00129 
00130         int getYSize();
00131         bool isWTA();
00132 
00134         virtual FeaturePlaneInput* addFilter(Filter* f, FeaturePlaneAbstract*fp, int type, int fpOutputIndex, bool wta){ return NULL;};
00135         virtual void editFeaturePlaneInput(FeaturePlaneInput *oldElement,FeaturePlaneInput *newElement) {};
00136         virtual void removeFeaturePlaneInput(FeaturePlaneInput *theElement) {};
00137         virtual void removeFeaturePlaneInput(FeaturePlaneAbstract *theElement) {};
00138         virtual void removeFeaturePlaneInputs() {};
00139 
00142         virtual OutputImage* getCurrentOutput(int index);
00143         OutputImage* getGatingControlOutput(int index);
00144         int getGatingControlOutputCount();
00145         int gatingControlInputCount;
00146         virtual void inhibitReturn();
00147         void initSelectiveTuning();
00149         Matrix* iorMap;
00150 
00152         virtual OutputImage* getCurrentOutput();
00153 
00155         OutputImage* getImage(){
00156                 return getCurrentOutput();
00157         };
00158 
00160         Matrix* getMap(){
00161                 return getGatingControl();
00162         }
00163 
00164         void releaseMap(){
00165                 releaseGatingControl();
00166         }
00167 
00168         virtual PlaneInputs* getRegularInputList() {return NULL;}
00169         virtual PlaneInputs* getMaskingInputList() {return NULL;}
00170         virtual PlaneInputs* getNonFourierInputList() {return NULL;}
00171         virtual PlaneInputs* getGatingControlInputList() {return &gatingControlInputList;}
00172         virtual int getGatingControlInputListSize() {return gatingControlInputList.size();}
00173         virtual float getMaxActivation() {return 0.0f;}
00174 
00175         virtual bool isInputFP() {return false;}
00176 
00178         virtual Matrix* getGatingControl();
00180         virtual void releaseGatingControl();
00181 
00182         void setParameters(paramMap params);
00183         void XMLSerialize(int tabs, QTextStream *buf);
00184 
00186         int getID();
00187 
00189         void setNode(NodeAbstract* n);
00190 
00192         void setThreshold(float t);
00193         void setThresholdPercent(float t);
00194         void setThresholdBinarize(float t);
00195 
00198         void setFunction(pt2Function theFunction);
00199 
00200         static int getType(const QString name);
00201         static QString getType(int value);
00202 
00207         virtual bool moveHead(int deltaX, int deltaY, bool notify=true) {return true;} // InputControllerAbstract
00208         virtual void processTargetPlane() {} // InputControllerAbstract
00209         virtual OutputImage* getHeadImage(){return NULL;} //InputControllerAbstract
00210         virtual QImage* getVirtualImage(bool showRect){return NULL;} //InputVirtualFeaturePlane
00211 
00212         /**********************************************************************************************/
00213 
00214 
00215         // computation synchronization
00217         //    static bool useThreadSync;
00218 
00219         static QWaitCondition* workingThreadsCond;
00220 
00221         static QMutex workingThreadsMutex;
00222         static int currentLayer;
00223         static int workingThreads;
00224         static int totalWorkingThreads;
00225 
00227         int iterations;
00228 
00229         int fpType; // check the FP_ defines above
00230 
00232         NotifyStrategyAbstract* theNotifyStrategy; 
00234         Neuron* theNeuronStrategy; 
00235 
00237         FPDesignerInfo designerInfo; 
00238 
00239         //sort by layer predicate
00240         static bool CompareLayer(const FeaturePlaneAbstract* d1, const FeaturePlaneAbstract* d2){
00241                 return d1->layerIndex < d2->layerIndex;
00242         }
00243 
00245         UI_FeaturePlane* fpViewerWindow;
00247         UI_NeuronTimeCourse* neuronTimeCourseWindow;
00248 
00250         void selectWinner(int selectX, int selectY);
00251 
00252 private:
00254         QString* fpName;
00255 
00257         QVector<double> displayParameters;
00258 
00259 protected:
00261         FeaturePlaneAbstract();
00262 
00278         FeaturePlaneAbstract( Network* net, int l, QString* n, int w, int h, int angles, int speeds, int alpha, int speed, bool isWTA, bool visible, NotifyStrategyAbstract* notify, Neuron* neuron=NULL);
00279         void init();
00280 
00281         Network* nn;
00282         int layerIndex;
00283         OutputImage* currentOutput;
00284         set<OutputImage*> outputHistory;
00285         QMutex currentOutputMutex;
00286         OutputImage** workOutputList;
00287         OutputImage** currentOutputList;
00288         OutputImage** currentGatingControlOutputList;
00289         int gatingControlOutputCount;
00290         QMutex currentOutputListMutex;
00291         QMutex gatingControlOutputListMutex;
00292         set<OutputImage*>** outputHistoryList;
00293         set<OutputImage*>** gatingControlHistoryList;   
00295         OutputImage* workOutput;
00296 
00298         QMutex gcMutex;
00299         PlaneInputs gatingControlInputList;
00300         OutputImage* theGatingControl;
00301         void createGatingControl();
00302         void applyGatingControl();
00303 
00304         int speeds;
00305         int angles;
00306         int speed;
00307         int alpha;
00308 
00309         int width, height;
00310         int outputs;
00311         int inputs;
00312         bool is_WTA;
00313         float theta;
00315         float threshold;
00317         float threshold_percent;
00319         float threshold_binarize;
00320 
00322         Matrix* spatialBias; //like alpha mask, only normalized 0-1
00324         float featureBias;
00325 
00326         int fpID;
00327         NodeAbstract* _parentNode;
00328 
00329         pt2Function functionCall; // the function that will be invoked once the current computation step is done
00330         paramMap initParams;
00331         void _XMLSerialize(int &tabs, QTextStream *buf, PlaneInputs* tmpList, int type);
00332         QMutex observerProxyMutex;
00333         list<NodeProxy*> _observersProxyList;   
00334 };
00335 #endif //FEATUREPLANEABSTRACT_H_INCLUDED
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines