BarsAndStripes.h
Go to the documentation of this file.
1 /*!
2  * \brief Implements the Bars & Stripes benchmark problem.
3  *
4  * \author O. Krause, A.Fischer, K.Bruegge
5  * \date 2012
6  *
7  *
8  * \par Copyright 1995-2017 Shark Development Team
9  *
10  * <BR><HR>
11  * This file is part of Shark.
12  * <http://shark-ml.org/>
13  *
14  * Shark is free software: you can redistribute it and/or modify
15  * it under the terms of the GNU Lesser General Public License as published
16  * by the Free Software Foundation, either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * Shark is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public License
25  * along with Shark. If not, see <http://www.gnu.org/licenses/>.
26  *
27  */
28 #ifndef UNSUPERVISED_RBM_PROBLEMS_BARSANDSTRIPES_H
29 #define UNSUPERVISED_RBM_PROBLEMS_BARSANDSTRIPES_H
30 
31 #include <shark/Data/Dataset.h>
32 #include <shark/LinAlg/Base.h>
33 namespace shark{
34 
35 ///Generates the Bars-And-Stripes problem. In this problem, a 4x4 image has either rows or columns of the same value.
37 private:
39 public:
40  BarsAndStripes(std::size_t batchSize = 32, bool bipolar = false){
41  std::vector<RealVector> data(32,RealVector(16));
42  RealVector line(4);
43  for(size_t x=0; x != 16; x++) {
44  for(size_t j=0; j != 4; j++) {
45  line(j) = (x & (std::size_t(1)<<j)) > 0;
46  if(bipolar && line(j)==0) line(j) = -1;
47  }
48 
49  for(int i=0; i != 4; i++) {
50  subrange(data[x],i*4 ,i*4 + 4) = line;
51  }
52  for(int i=0; i != 4; i++) {
53  for(int l=0; l<4; l++) {
54  data[16+x](l*4 + i) = line(l);
55  }
56  }
57  }
58  m_data = createDataFromRange(data,batchSize);
59  }
60  ///Returns all input pattern of the BarsAndStripes problem
62  return m_data;
63  };
64 
65  ///returns the dimensionality of the data
66  std::size_t inputDimension() const {
67  return 16;
68  }
69 };
70 
71 }
72 #endif