Shifter.h
Go to the documentation of this file.
1 /*!
2  * \brief Implements the Shifter 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_SHIFTER_H
29 #define UNSUPERVISED_RBM_PROBLEMS_SHIFTER_H
30 
31 #include <shark/Data/Dataset.h>
32 #include <shark/LinAlg/Base.h>
33 
34 
35 namespace shark{
36 
37 ///Shifter problem
38 class Shifter{
39 private:
41 public:
43  std::vector<RealVector> data(768,RealVector(19));
44  for(unsigned x=0; x<=255; x++) {
45  RealVector element(19);
46  for(size_t i=0; i<8; i++) {
47  element(i) = (x & (1<<i)) > 0;
48  }
49  for(int label=0; label<=2; label++) {
50  unsigned char y;
51  if(label==0) {
52  y = (x<<1 | x>>7);
53  element(16)=1;
54  element(17)=0;
55  element(18)=0;
56  }
57  else if(label==1) {
58  y = x;
59  element(16)=0;
60  element(17)=1;
61  element(18)=0;
62  }
63  else {
64  y = (x>>1 | x<<7);
65  element(16)=0;
66  element(17)=0;
67  element(18)=1;
68  }
69  for(size_t i=0; i<8; i++) {
70  element(i+8) = (y & (1<<i)) > 0;
71  }
72  data[x*3+label]=element;
73  }
74  }
75  m_data = createDataFromRange(data);
76  }
77 
78  ///returns the generated dataset
80  return m_data;
81  };
82  ///returns the dimensionality of the data
83  std::size_t inputDimension() const {
84  return 19;
85  }
86 };
87 }
88 #endif