OpenANN  1.1.0
An open source library for artificial neural networks.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CreateTwoSpiralsDataSet.h
Go to the documentation of this file.
1 #ifndef CREATE_TWO_SPIRALS_DATA_SET_H_
2 #define CREATE_TWO_SPIRALS_DATA_SET_H_
3 
4 #include <Eigen/Core>
7 
22 void createTwoSpiralsDataSet(int density, double maxDiameter,
23  Eigen::MatrixXd& Xtr, Eigen::MatrixXd& Ytr,
24  Eigen::MatrixXd& Xte, Eigen::MatrixXd& Yte)
25 {
26  // Number of interior data points per spiral to generate
27  const int points = 96 * density;
28 
29  Xtr.resize(points + 1, 2);
30  Ytr.resize(points + 1, 1);
31  Xte.resize(points + 1, 2);
32  Yte.resize(points + 1, 1);
33  int trIdx = 0;
34  int teIdx = 0;
35 
36  for(int i = 0; i <= points; i++)
37  {
38  // Angle is based on the iteration * PI/16, divided by point density
39  const double angle = i * M_PI / (16.0 * density);
40  // Radius is the maximum radius * the fraction of iterations left
41  const double radius = maxDiameter * (104 * density - i) / (104 * density);
42  // x and y are based upon cos and sin of the current radius
43  const double x = radius * cos(angle);
44  const double y = radius * sin(angle);
45 
46  if(i == points)
47  {
48  Xtr.row(trIdx) << x, y;
49  Ytr.row(trIdx) << 1.0;
50  Xte.row(trIdx) << -x, -y;
51  Yte.row(teIdx) << -1.0;
52  }
53  else if(i % 2 == 0)
54  {
55  OPENANN_CHECK_WITHIN(trIdx, 0, points);
56  Xtr.row(trIdx) << x, y;
57  Ytr.row(trIdx) << 1.0;
58  Xtr.row(trIdx + 1) << -x, -y;
59  Ytr.row(trIdx + 1) << -1.0;
60  trIdx += 2;
61  }
62  else
63  {
64  OPENANN_CHECK_WITHIN(teIdx, 0, points);
65  Xte.row(teIdx) << x, y;
66  Yte.row(teIdx) << 1.0;
67  Xte.row(teIdx + 1) << -x, -y;
68  Yte.row(teIdx + 1) << -1.0;
69  teIdx += 2;
70  }
71  }
72 
73  OpenANN::scaleData(Xte, 0.0, 1.0);
74  OpenANN::scaleData(Xtr, 0.0, 1.0);
75 }
76 
77 #endif // CREATE_TWO_SPIRALS_DATA_SET_H_