4#include <cereal/access.hpp>
5#include <cereal/archives/binary.hpp>
6#include <cereal/archives/portable_binary.hpp>
7#include <cereal/types/base_class.hpp>
8#include <cereal/types/common.hpp>
9#include <cereal/types/polymorphic.hpp>
17#include "activations/activations.hpp"
18#include "utils/Enums.hpp"
19#include "utils/Functions.hpp"
20#include "utils/Serialize.hpp"
24enum class LayerType { DEFAULT, DENSE, FLATTEN, DROPOUT };
57 std::cout << this->outputs <<
"\n";
68 virtual Eigen::MatrixXd
feedInputs(std::vector<double> inputs,
69 bool training =
false) {
70 return this->
feedInputs(Eigen::MatrixXd::Map(&inputs[0], inputs.size(), 1));
80 virtual Eigen::MatrixXd
feedInputs(Eigen::MatrixXd inputs,
81 bool training =
false) = 0;
91 virtual void feedInputs(std::vector<std::vector<std::vector<double>>> inputs,
92 bool training =
false) {
94 "Cannot feed 3d vectors, a Flatten layer could do it though");
105 static const std::map<LayerType, std::string> typeMap = {
106 {LayerType::DEFAULT,
"Base"},
107 {LayerType::DENSE,
"Dense"},
108 {LayerType::FLATTEN,
"Flatten"},
109 {LayerType::DROPOUT,
"Dropout"}};
111 auto it = typeMap.find(this->type);
112 if (it != typeMap.end())
return it->second;
121 friend class cereal::access;
124 template <
class Archive>
125 void save(Archive &archive)
const {
126 archive(outputs, type, trainingOnly, nNeurons);
129 template <
class Archive>
130 void load(Archive &archive) {
131 archive(outputs, type, trainingOnly, nNeurons);
136 Eigen::MatrixXd outputs;
137 LayerType type = LayerType::DEFAULT;
138 bool trainingOnly =
false;
145 this->outputs = outputs;
159 assert(outputs.size() == nNeurons);
161 Eigen::MatrixXd ::Map(&outputs[0], this->
getNumNeurons(), 1);
174 bool training =
false) = 0;
181 virtual void init(
int args) {};
183 Layer(std::tuple<int, int> inputShape)
184 : nNeurons(std::get<0>(inputShape) *
185 std::get<1>(inputShape)){};
virtual Eigen::MatrixXd feedInputs(Eigen::MatrixXd inputs, bool training=false)=0
This method is used to feed the inputs to the layer.
virtual Eigen::MatrixXd computeOutputs(Eigen::MatrixXd inputs, bool training=false)=0
This method is used to feed the inputs to the layer.
Eigen::MatrixXd getOutputs() const
This method get the layer's outputs.
Definition Layer.hpp:37
virtual std::string getSlug() const =0
The slug of the layers (name + main parameter value)
virtual Eigen::MatrixXd feedInputs(std::vector< double > inputs, bool training=false)
This method is used to feed the inputs to the layer.
Definition Layer.hpp:68
void setOutputs(Eigen::MatrixXd outputs)
Definition Layer.hpp:143
const std::string typeStr()
Definition Layer.hpp:104
void printOutputs()
Method to print layer's outputs.
Definition Layer.hpp:56
virtual void feedInputs(std::vector< std::vector< std::vector< double > > > inputs, bool training=false)
This method is used to feed the inputs to the layer.
Definition Layer.hpp:91
void setOutputs(std::vector< double > outputs)
This method is used to set the outputs of the layer.
Definition Layer.hpp:158
virtual void init(int args)
Definition Layer.hpp:181
int getNumNeurons() const
This method get the number of neurons actually in the layer.
Definition Layer.hpp:44
Definition Network.hpp:29