00001 #ifndef KANAL
00002 #define KANAL
00003
00004 #include "Control.h"
00005 #include "defines.h"
00006 #include "EucledianTopology.h"
00007
00008 namespace annie {
00009
00010 #define AXES 2
00011
00012 class KohonenAnalyzer : public Video::Redrawer {
00013 public:
00014 struct Outs {
00015 uint arr[AXES];
00016 Outs(uint x, uint y) {
00017 arr[0] = x;
00018 arr[1] = y;
00019 }
00020 };
00021 KohonenAnalyzer(uint inputs, const Outs &outputs, PublicValues &ctrl=defaultControl) : control(ctrl), _topology(outputs.arr), _parameters(_topology.getMaxDim(), control["slope"]), _net(inputs, _topology, _parameters) {}
00022
00027 virtual void draw();
00028
00032 virtual void calibrate()=0;
00033
00035 virtual void trainAndAnalyze(uint epochs)=0;
00036
00037 uint getInputCount() const { return _net.getInputCount(); }
00038 const KohonenNetwork &getNet() const { return _net; }
00039
00040 protected:
00042 void calibrateStep(const Vector &in);
00043 void analyzeStep(const Vector &in);
00044
00045 PublicValues &control;
00046 typedef EucledianTopology<AXES> MyTopology;
00047 MyTopology _topology;
00048 StandardKohonenParameters _parameters;
00049 KohonenNetwork _net;
00050 };
00051
00055 class MLPKohonenAnalyzer : public KohonenAnalyzer {
00056 public:
00057 MLPKohonenAnalyzer(const Outs &outputs, MultiLayerNetwork &net, TrainingSet &ts) : KohonenAnalyzer(net.getLinksCount(), outputs), analyzedNet(net), ts(ts) {
00058 net.setControl(mlpControl);
00059 }
00060 virtual void calibrate();
00061 virtual void trainAndAnalyze(uint epochs);
00062 protected:
00064 void getWeights(Vector &v) const;
00065
00067 void loop(uint epochs, bool adapt, bool draw);
00068
00069 PublicValues mlpControl;
00070 MultiLayerNetwork &analyzedNet;
00071 TrainingSet &ts;
00072 };
00073
00074 void runKohonenAnalyzer(KohonenAnalyzer &ka);
00075
00076 }
00077 #endif //_H