40 void setup(
const std::shared_ptr<Optimizer> &optimizer,
41 LOSS loss = LOSS::QUADRATIC);
48 void addLayer(std::shared_ptr<Layer> &layer);
64 std::shared_ptr<Layer>
getLayer(
int index)
const;
103 double train(std::vector<std::vector<double>> X, std::vector<double> y,
105 const std::vector<std::shared_ptr<Callback>> callbacks = {},
106 bool progBar =
true);
121 double train(std::vector<std::vector<std::vector<double>>> X,
122 std::vector<double> y,
int epochs = 1,
123 const std::vector<std::shared_ptr<Callback>> callbacks = {},
124 bool progBar =
true);
139 TrainingData<std::vector<std::vector<double>>, std::vector<double>>
142 const std::vector<std::shared_ptr<Callback>> callbacks = {},
143 bool progBar =
true);
161 const std::vector<std::shared_ptr<Callback>> callbacks = {},
162 bool progBar =
true);
171 Eigen::MatrixXd
predict(std::vector<std::vector<double>> inputs);
180 Eigen::MatrixXd
predict(std::vector<std::vector<std::vector<double>>> inputs);
187 void to_file(
const std::string &filename)
override {
189 std::ofstream file(filename, std::ios::binary);
190 cereal::BinaryOutputArchive archive(file);
201 assert(fileExistsWithExtension(filename,
".bin") &&
202 "The file doesn't exists or is not binary '.bin'");
205 std::ifstream file(filename, std::ios::binary);
206 cereal::BinaryInputArchive archive(file);
214 friend class cereal::access;
216 std::vector<std::shared_ptr<Layer>> layers;
220 double (*cmpLoss)(
const Eigen::MatrixXd &,
const Eigen::MatrixXd &);
221 Eigen::MatrixXd (*cmpLossGrad)(
const Eigen::MatrixXd &,
222 const Eigen::MatrixXd &);
223 std::shared_ptr<Optimizer> optimizer;
225 template <
class Archive>
226 void save(Archive &archive)
const {
227 archive(cereal::base_class<Model>(
this), layers, lossFunc);
228 archive.serializeDeferments();
231 template <
class Archive>
232 void load(Archive &archive) {
233 archive(cereal::base_class<Model>(
this), layers, lossFunc);
257 template <
typename D1,
typename D2>
258 double onlineTraining(std::vector<D1> inputs, std::vector<D2> labels,
260 std::vector<std::shared_ptr<Callback>> callbacks = {});
279 template <
typename D1,
typename D2>
280 double trainer(TrainingData<D1, D2> trainingData,
int epochs,
281 std::vector<std::shared_ptr<Callback>> callbacks = {});
300 template <
typename D1,
typename D2>
301 double miniBatchTraining(
302 TrainingData<D1, D2> trainingData,
int epochs,
303 std::vector<std::shared_ptr<Callback>> callbacks = {});
321 template <
typename D1,
typename D2>
322 double batchTraining(TrainingData<D1, D2> trainingData,
int epochs,
323 std::vector<std::shared_ptr<Callback>> callbacks = {});
333 Eigen::MatrixXd forwardProp(
334 std::vector<std::vector<std::vector<double>>> &inputs,
335 bool training =
false);
345 Eigen::MatrixXd forwardProp(std::vector<std::vector<double>> &inputs,
346 bool training =
false);
356 Eigen::MatrixXd forwardProp(Eigen::MatrixXd &inputs,
bool training =
false);
358 Eigen::MatrixXd feedForward(Eigen::MatrixXd inputs,
int startIdx = 0,
359 bool training =
false);
368 void backProp(Eigen::MatrixXd &outputs, Eigen::MatrixXd &y);
379 void trainingCheckpoint(std::string checkpointName,
380 std::vector<std::shared_ptr<Callback>> callbacks);
391 double computeAccuracy(Eigen::MatrixXd &outputs, Eigen::MatrixXd &y);
398 void updateOptimizerSetup(
size_t numLayers);
double train(std::vector< std::vector< double > > X, std::vector< double > y, int epochs=1, const std::vector< std::shared_ptr< Callback > > callbacks={}, bool progBar=true)
This method will Train the model with the given inputs and labels.
Definition Network.cpp:70