OpenANN  1.1.0
An open source library for artificial neural networks.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TwoSpiralsVisualization.h
Go to the documentation of this file.
1 #ifndef TWO_SPIRALS_VISUALIZATION_H_
2 #define TWO_SPIRALS_VISUALIZATION_H_
3 
4 #include <OpenANN/OpenANN>
6 #include <Eigen/Core>
7 #include <QGLWidget>
8 #include <QKeyEvent>
9 #include <QMutex>
10 
11 using namespace OpenANN;
12 
14 
15 class TwoSpiralsDataSet : public DataSet
16 {
17  Eigen::MatrixXd in, out;
18  DirectStorageDataSet dataSet;
19  TwoSpiralsVisualization* visualization;
20 public:
21  TwoSpiralsDataSet(const Eigen::MatrixXd& inputs, const Eigen::MatrixXd& outputs);
22  void setVisualization(TwoSpiralsVisualization* visualization);
23  virtual ~TwoSpiralsDataSet() {}
24  virtual int samples() { return dataSet.samples(); }
25  virtual int inputs() { return dataSet.inputs(); }
26  virtual int outputs() { return dataSet.outputs(); }
27  virtual Eigen::VectorXd& getInstance(int i) { return dataSet.getInstance(i); }
28  virtual Eigen::VectorXd& getTarget(int i) { return dataSet.getTarget(i); }
29  virtual void finishIteration(Learner& learner);
30 };
31 
32 class TwoSpiralsVisualization : public QGLWidget
33 {
34  Q_OBJECT
35  int width, height;
36  QMutex classesMutex;
37  double classes[100][100];
38  TwoSpiralsDataSet trainingSet;
39  TwoSpiralsDataSet testSet;
40  bool showTraining, showTest, showPrediction, showSmooth;
41  Net* net;
43 
44 public:
45  TwoSpiralsVisualization(const Eigen::MatrixXd& trainingInput, const Eigen::MatrixXd& trainingOutput,
46  const Eigen::MatrixXd& testInput, const Eigen::MatrixXd& testOutput);
47  virtual ~TwoSpiralsVisualization();
48  void predictClass(int x, int y, double predictedClass);
49 
50 protected:
51  virtual void initializeGL();
52  virtual void resizeGL(int width, int height);
53  virtual void paintGL();
54  void paintPrediction();
55  void paintDataSet(bool training);
56  virtual void keyPressEvent(QKeyEvent* keyEvent);
57 
58 signals:
59  void updatedData();
60 };
61 
62 #endif // TWO_SPIRALS_VISUALIZATION_H_