2023-01-24 18:57:18 +01:00
|
|
|
|
|
|
|
#ifndef MLPP_MULTI_OUTPUT_LAYER_H
|
|
|
|
#define MLPP_MULTI_OUTPUT_LAYER_H
|
|
|
|
|
2023-01-23 21:13:26 +01:00
|
|
|
//
|
|
|
|
// MultiOutputLayer.hpp
|
|
|
|
//
|
|
|
|
// Created by Marc Melikyan on 11/4/20.
|
|
|
|
//
|
|
|
|
|
2023-01-27 13:01:16 +01:00
|
|
|
#include "core/math/math_defs.h"
|
2023-02-04 13:36:52 +01:00
|
|
|
#include "core/string/ustring.h"
|
|
|
|
|
|
|
|
#include "core/object/reference.h"
|
2023-01-27 13:01:16 +01:00
|
|
|
|
2023-01-24 18:12:23 +01:00
|
|
|
#include "../activation/activation.h"
|
|
|
|
#include "../cost/cost.h"
|
2023-02-04 13:36:52 +01:00
|
|
|
#include "../regularization/reg.h"
|
|
|
|
#include "../utilities/utilities.h"
|
|
|
|
|
|
|
|
#include "../lin_alg/mlpp_matrix.h"
|
|
|
|
#include "../lin_alg/mlpp_vector.h"
|
2023-01-23 21:13:26 +01:00
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2023-01-24 19:00:54 +01:00
|
|
|
#include <vector>
|
2023-01-23 21:13:26 +01:00
|
|
|
|
2023-02-04 13:53:36 +01:00
|
|
|
class MLPPMultiOutputLayer : public Reference {
|
|
|
|
GDCLASS(MLPPMultiOutputLayer, Reference);
|
|
|
|
|
|
|
|
public:
|
|
|
|
int get_n_output();
|
|
|
|
void set_n_output(const int val);
|
|
|
|
|
|
|
|
int get_n_hidden();
|
|
|
|
void set_n_hidden(const int val);
|
|
|
|
|
|
|
|
MLPPActivation::ActivationFunction get_activation();
|
|
|
|
void set_activation(const MLPPActivation::ActivationFunction val);
|
|
|
|
|
|
|
|
MLPPCost::CostTypes get_cost();
|
|
|
|
void set_cost(const MLPPCost::CostTypes val);
|
|
|
|
|
|
|
|
Ref<MLPPMatrix> get_input();
|
|
|
|
void set_input(const Ref<MLPPMatrix> &val);
|
|
|
|
|
|
|
|
Ref<MLPPMatrix> get_weights();
|
|
|
|
void set_weights(const Ref<MLPPMatrix> &val);
|
|
|
|
|
|
|
|
Ref<MLPPVector> get_bias();
|
|
|
|
void set_bias(const Ref<MLPPVector> &val);
|
|
|
|
|
|
|
|
Ref<MLPPMatrix> get_z();
|
|
|
|
void set_z(const Ref<MLPPMatrix> &val);
|
|
|
|
|
|
|
|
Ref<MLPPMatrix> get_a();
|
|
|
|
void set_a(const Ref<MLPPMatrix> &val);
|
|
|
|
|
|
|
|
Ref<MLPPVector> get_z_test();
|
|
|
|
void set_z_test(const Ref<MLPPVector> &val);
|
|
|
|
|
|
|
|
Ref<MLPPVector> get_a_test();
|
|
|
|
void set_a_test(const Ref<MLPPVector> &val);
|
|
|
|
|
|
|
|
Ref<MLPPMatrix> get_delta();
|
|
|
|
void set_delta(const Ref<MLPPMatrix> &val);
|
|
|
|
|
|
|
|
MLPPReg::RegularizationType get_reg();
|
|
|
|
void set_reg(const MLPPReg::RegularizationType val);
|
|
|
|
|
|
|
|
real_t get_lambda();
|
|
|
|
void set_lambda(const real_t val);
|
|
|
|
|
|
|
|
real_t get_alpha();
|
|
|
|
void set_alpha(const real_t val);
|
|
|
|
|
|
|
|
MLPPUtilities::WeightDistributionType get_weight_init();
|
|
|
|
void set_weight_init(const MLPPUtilities::WeightDistributionType val);
|
|
|
|
|
|
|
|
void forward_pass();
|
|
|
|
void test(const Ref<MLPPVector> &x);
|
|
|
|
|
|
|
|
MLPPMultiOutputLayer(int p_n_hidden, MLPPActivation::ActivationFunction p_activation, Ref<MLPPMatrix> p_input, MLPPUtilities::WeightDistributionType p_weight_init, MLPPReg::RegularizationType p_reg, real_t p_lambda, real_t p_alpha);
|
|
|
|
|
|
|
|
MLPPMultiOutputLayer();
|
|
|
|
~MLPPMultiOutputLayer();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
int n_output;
|
|
|
|
int n_hidden;
|
|
|
|
MLPPActivation::ActivationFunction activation;
|
|
|
|
MLPPCost::CostTypes cost;
|
|
|
|
|
|
|
|
Ref<MLPPMatrix> input;
|
|
|
|
|
|
|
|
Ref<MLPPMatrix> weights;
|
|
|
|
Ref<MLPPVector> bias;
|
|
|
|
|
|
|
|
Ref<MLPPMatrix> z;
|
|
|
|
Ref<MLPPMatrix> a;
|
|
|
|
|
|
|
|
Ref<MLPPVector> z_test;
|
|
|
|
Ref<MLPPVector> a_test;
|
|
|
|
|
|
|
|
Ref<MLPPMatrix> delta;
|
|
|
|
|
|
|
|
// Regularization Params
|
|
|
|
MLPPReg::RegularizationType reg;
|
|
|
|
real_t lambda; /* Regularization Parameter */
|
|
|
|
real_t alpha; /* This is the controlling param for Elastic Net*/
|
|
|
|
|
|
|
|
MLPPUtilities::WeightDistributionType weight_init;
|
|
|
|
};
|
2023-01-24 19:20:18 +01:00
|
|
|
|
2023-02-04 13:36:52 +01:00
|
|
|
class MLPPOldMultiOutputLayer {
|
2023-01-24 19:00:54 +01:00
|
|
|
public:
|
2023-02-04 13:36:52 +01:00
|
|
|
MLPPOldMultiOutputLayer(int n_output, int n_hidden, std::string activation, std::string cost, std::vector<std::vector<real_t>> input, std::string weightInit, std::string reg, real_t lambda, real_t alpha);
|
2023-01-23 21:13:26 +01:00
|
|
|
|
2023-01-24 19:00:54 +01:00
|
|
|
int n_output;
|
|
|
|
int n_hidden;
|
|
|
|
std::string activation;
|
|
|
|
std::string cost;
|
|
|
|
|
2023-01-27 13:01:16 +01:00
|
|
|
std::vector<std::vector<real_t>> input;
|
2023-01-24 19:00:54 +01:00
|
|
|
|
2023-01-27 13:01:16 +01:00
|
|
|
std::vector<std::vector<real_t>> weights;
|
|
|
|
std::vector<real_t> bias;
|
2023-01-24 19:00:54 +01:00
|
|
|
|
2023-01-27 13:01:16 +01:00
|
|
|
std::vector<std::vector<real_t>> z;
|
|
|
|
std::vector<std::vector<real_t>> a;
|
2023-01-24 19:00:54 +01:00
|
|
|
|
2023-01-27 13:01:16 +01:00
|
|
|
std::map<std::string, std::vector<std::vector<real_t>> (MLPPActivation::*)(std::vector<std::vector<real_t>>, bool)> activation_map;
|
|
|
|
std::map<std::string, std::vector<real_t> (MLPPActivation::*)(std::vector<real_t>, bool)> activationTest_map;
|
|
|
|
std::map<std::string, real_t (MLPPCost::*)(std::vector<std::vector<real_t>>, std::vector<std::vector<real_t>>)> cost_map;
|
|
|
|
std::map<std::string, std::vector<std::vector<real_t>> (MLPPCost::*)(std::vector<std::vector<real_t>>, std::vector<std::vector<real_t>>)> costDeriv_map;
|
2023-01-23 21:13:26 +01:00
|
|
|
|
2023-01-27 13:01:16 +01:00
|
|
|
std::vector<real_t> z_test;
|
|
|
|
std::vector<real_t> a_test;
|
2023-01-24 19:00:54 +01:00
|
|
|
|
2023-01-27 13:01:16 +01:00
|
|
|
std::vector<std::vector<real_t>> delta;
|
2023-01-24 19:00:54 +01:00
|
|
|
|
|
|
|
// Regularization Params
|
|
|
|
std::string reg;
|
2023-01-27 13:01:16 +01:00
|
|
|
real_t lambda; /* Regularization Parameter */
|
|
|
|
real_t alpha; /* This is the controlling param for Elastic Net*/
|
2023-01-24 19:00:54 +01:00
|
|
|
|
|
|
|
std::string weightInit;
|
|
|
|
|
|
|
|
void forwardPass();
|
2023-01-27 13:01:16 +01:00
|
|
|
void Test(std::vector<real_t> x);
|
2023-01-24 19:00:54 +01:00
|
|
|
};
|
2023-01-24 19:20:18 +01:00
|
|
|
|
2023-01-24 19:00:54 +01:00
|
|
|
#endif /* MultiOutputLayer_hpp */
|