MachineIntelligenceCore:Algorithms
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
MatrixSDREncoder.hpp
Go to the documentation of this file.
1 
23 #ifndef SRC_ENCODERS_MATRIXSDRENCODER_HPP_
24 #define SRC_ENCODERS_MATRIXSDRENCODER_HPP_
25 
26 #include <encoders/Encoder.hpp>
27 
28 #include <types/MatrixTypes.hpp>
29 
30 namespace mic {
31 namespace encoders {
32 
40 template <typename inputDataType, typename outputDataType = float>
41 class MatrixSDREncoder : public mic::encoders::Encoder <inputDataType, mic::types::Matrix<outputDataType> > {
42 public:
47  MatrixSDREncoder(size_t sdr_length_) : mic::encoders::Encoder<inputDataType, mic::types::Matrix<outputDataType> >(),
48  sdr_length(sdr_length_)
49  {
50 // std::cout<<" Hello MatrixXfSDREncoder\n";
51  };
52 
56  virtual ~MatrixSDREncoder() { }
57 
58 
64  virtual std::shared_ptr<mic::types::Matrix<outputDataType> > encodeBatch(const std::vector<std::shared_ptr<inputDataType> >& batch_) {
65  // Create returned matrix.
66  std::shared_ptr<mic::types::Matrix<outputDataType> > sdrs (new mic::types::Matrix<outputDataType> (sdr_length, batch_.size()));
67 
68  // Encode the samples one by one.
69  for (size_t i=0; i < batch_.size(); i++ ) {
70  // Encode single sample.
71  std::shared_ptr<mic::types::Matrix<outputDataType> > sample_sdr = this->encodeSample(batch_[i]);
72 
73  // Set SDR rows.
74  sdrs->col(i) = sample_sdr->col(0);
75  }//: for
76 
77  // Return the matrix containing SDRs.
78  return sdrs;
79  }
80 
81 
87  virtual std::vector<std::shared_ptr<inputDataType> > decodeBatch(const std::shared_ptr<mic::types::Matrix<outputDataType> >& sdrs_) {
88  // Create the output vector.
89  std::vector<std::shared_ptr<inputDataType> > output;
90  std::shared_ptr<mic::types::Matrix<outputDataType> > sample_sdr (new mic::types::Matrix<outputDataType> (sdrs_->rows(), 1));
91 
92  // Iterate through columns and decode them one by one.
93  for (size_t i=0; i < (size_t)sdrs_->cols(); i++ ) {
94  sample_sdr->col(0) = sdrs_->col(i);
95  std::shared_ptr<inputDataType> decoded = this->decodeSample(sample_sdr);
96  // Add result to vector.
97  output.push_back(decoded);
98  }//: for
99 
100  // Return the decoded vector.
101  return output;
102  }
103 
104 
108  size_t getSDRLength() {
109  return sdr_length;
110  }
111 
116  void setSDRLength(size_t sdr_length_) {
117  sdr_length = sdr_length_;
118  }
119 
120 protected:
121 
123  size_t sdr_length;
124 };
125 
126 } /* namespace encoders */
127 } /* namespace mic */
128 
129 #endif /* SRC_ENCODERS_MATRIXSDRENCODER_HPP_ */
MatrixSDREncoder(size_t sdr_length_)
Constructor.
virtual std::shared_ptr< inputDataType > decodeSample(const std::shared_ptr< mic::types::Matrix< outputDataType > > &sdr_)=0
Contains definition of basic matrix datatypes derived from Eigen.
Contains definition of an abstract, template parent class for all auto-encoders.
Abstract parent class for all encoders using MatrixXf as SDR datatype.
virtual std::vector< std::shared_ptr< inputDataType > > decodeBatch(const std::shared_ptr< mic::types::Matrix< outputDataType > > &sdrs_)
void setSDRLength(size_t sdr_length_)
Abstract parent class for all encoders.
Definition: Encoder.hpp:48
virtual std::shared_ptr< mic::types::Matrix< outputDataType > > encodeBatch(const std::vector< std::shared_ptr< inputDataType > > &batch_)
Template-typed Matrix of dynamic size. Uses OpenBLAS if found by CMAKE - overloaded, specializations of * operator for types: float, double.
Definition: Matrix.hpp:64
virtual std::shared_ptr< mic::types::Matrix< outputDataType > > encodeSample(const std::shared_ptr< inputDataType > &sample_)=0
Method responsible for encoding input sample into SDR.