2023-02-07 17:36:03 +01:00
|
|
|
//
|
|
|
|
// OutputLayer.cpp
|
|
|
|
//
|
|
|
|
// Created by Marc Melikyan on 11/4/20.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "output_layer_old.h"
|
2023-04-22 17:17:58 +02:00
|
|
|
#include "../lin_alg/lin_alg_old.h"
|
2023-02-07 17:36:03 +01:00
|
|
|
#include "../utilities/utilities.h"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <random>
|
|
|
|
|
|
|
|
MLPPOldOutputLayer::MLPPOldOutputLayer(int p_n_hidden, std::string p_activation, std::string p_cost, std::vector<std::vector<real_t>> p_input, std::string p_weightInit, std::string p_reg, real_t p_lambda, real_t p_alpha) {
|
|
|
|
n_hidden = p_n_hidden;
|
|
|
|
activation = p_activation;
|
|
|
|
cost = p_cost;
|
|
|
|
input = p_input;
|
|
|
|
weightInit = p_weightInit;
|
|
|
|
reg = p_reg;
|
|
|
|
lambda = p_lambda;
|
|
|
|
alpha = p_alpha;
|
|
|
|
|
|
|
|
weights = MLPPUtilities::weightInitialization(n_hidden, weightInit);
|
|
|
|
bias = MLPPUtilities::biasInitialization();
|
|
|
|
|
2023-04-22 14:11:07 +02:00
|
|
|
activation_map["Linear"] = &MLPPActivationOld::linear;
|
|
|
|
activationTest_map["Linear"] = &MLPPActivationOld::linear;
|
2023-02-07 17:36:03 +01:00
|
|
|
|
2023-04-22 14:11:07 +02:00
|
|
|
activation_map["Sigmoid"] = &MLPPActivationOld::sigmoid;
|
|
|
|
activationTest_map["Sigmoid"] = &MLPPActivationOld::sigmoid;
|
2023-02-07 17:36:03 +01:00
|
|
|
|
2023-04-22 14:11:07 +02:00
|
|
|
activation_map["Swish"] = &MLPPActivationOld::swish;
|
|
|
|
activationTest_map["Swish"] = &MLPPActivationOld::swish;
|
2023-02-07 17:36:03 +01:00
|
|
|
|
2023-04-22 14:11:07 +02:00
|
|
|
activation_map["Mish"] = &MLPPActivationOld::mish;
|
|
|
|
activationTest_map["Mish"] = &MLPPActivationOld::mish;
|
2023-02-07 17:36:03 +01:00
|
|
|
|
2023-04-22 14:11:07 +02:00
|
|
|
activation_map["SinC"] = &MLPPActivationOld::sinc;
|
|
|
|
activationTest_map["SinC"] = &MLPPActivationOld::sinc;
|
2023-02-07 17:36:03 +01:00
|
|
|
|
2023-04-22 14:11:07 +02:00
|
|
|
activation_map["Softplus"] = &MLPPActivationOld::softplus;
|
|
|
|
activationTest_map["Softplus"] = &MLPPActivationOld::softplus;
|
2023-02-07 17:36:03 +01:00
|
|
|
|
2023-04-22 14:11:07 +02:00
|
|
|
activation_map["Softsign"] = &MLPPActivationOld::softsign;
|
|
|
|
activationTest_map["Softsign"] = &MLPPActivationOld::softsign;
|
2023-02-07 17:36:03 +01:00
|
|
|
|
2023-04-22 14:11:07 +02:00
|
|
|
activation_map["CLogLog"] = &MLPPActivationOld::cloglog;
|
|
|
|
activationTest_map["CLogLog"] = &MLPPActivationOld::cloglog;
|
2023-02-07 17:36:03 +01:00
|
|
|
|
2023-04-22 14:11:07 +02:00
|
|
|
activation_map["Logit"] = &MLPPActivationOld::logit;
|
|
|
|
activationTest_map["Logit"] = &MLPPActivationOld::logit;
|
2023-02-07 17:36:03 +01:00
|
|
|
|
2023-04-22 14:11:07 +02:00
|
|
|
activation_map["GaussianCDF"] = &MLPPActivationOld::gaussianCDF;
|
|
|
|
activationTest_map["GaussianCDF"] = &MLPPActivationOld::gaussianCDF;
|
2023-02-07 17:36:03 +01:00
|
|
|
|
2023-04-22 14:11:07 +02:00
|
|
|
activation_map["RELU"] = &MLPPActivationOld::RELU;
|
|
|
|
activationTest_map["RELU"] = &MLPPActivationOld::RELU;
|
2023-02-07 17:36:03 +01:00
|
|
|
|
2023-04-22 14:11:07 +02:00
|
|
|
activation_map["GELU"] = &MLPPActivationOld::GELU;
|
|
|
|
activationTest_map["GELU"] = &MLPPActivationOld::GELU;
|
2023-02-07 17:36:03 +01:00
|
|
|
|
2023-04-22 14:11:07 +02:00
|
|
|
activation_map["Sign"] = &MLPPActivationOld::sign;
|
|
|
|
activationTest_map["Sign"] = &MLPPActivationOld::sign;
|
2023-02-07 17:36:03 +01:00
|
|
|
|
2023-04-22 14:11:07 +02:00
|
|
|
activation_map["UnitStep"] = &MLPPActivationOld::unitStep;
|
|
|
|
activationTest_map["UnitStep"] = &MLPPActivationOld::unitStep;
|
2023-02-07 17:36:03 +01:00
|
|
|
|
2023-04-22 14:11:07 +02:00
|
|
|
activation_map["Sinh"] = &MLPPActivationOld::sinh;
|
|
|
|
activationTest_map["Sinh"] = &MLPPActivationOld::sinh;
|
2023-02-07 17:36:03 +01:00
|
|
|
|
2023-04-22 14:11:07 +02:00
|
|
|
activation_map["Cosh"] = &MLPPActivationOld::cosh;
|
|
|
|
activationTest_map["Cosh"] = &MLPPActivationOld::cosh;
|
2023-02-07 17:36:03 +01:00
|
|
|
|
2023-04-22 14:11:07 +02:00
|
|
|
activation_map["Tanh"] = &MLPPActivationOld::tanh;
|
|
|
|
activationTest_map["Tanh"] = &MLPPActivationOld::tanh;
|
2023-02-07 17:36:03 +01:00
|
|
|
|
2023-04-22 14:11:07 +02:00
|
|
|
activation_map["Csch"] = &MLPPActivationOld::csch;
|
|
|
|
activationTest_map["Csch"] = &MLPPActivationOld::csch;
|
2023-02-07 17:36:03 +01:00
|
|
|
|
2023-04-22 14:11:07 +02:00
|
|
|
activation_map["Sech"] = &MLPPActivationOld::sech;
|
|
|
|
activationTest_map["Sech"] = &MLPPActivationOld::sech;
|
2023-02-07 17:36:03 +01:00
|
|
|
|
2023-04-22 14:11:07 +02:00
|
|
|
activation_map["Coth"] = &MLPPActivationOld::coth;
|
|
|
|
activationTest_map["Coth"] = &MLPPActivationOld::coth;
|
2023-02-07 17:36:03 +01:00
|
|
|
|
2023-04-22 14:11:07 +02:00
|
|
|
activation_map["Arsinh"] = &MLPPActivationOld::arsinh;
|
|
|
|
activationTest_map["Arsinh"] = &MLPPActivationOld::arsinh;
|
2023-02-07 17:36:03 +01:00
|
|
|
|
2023-04-22 14:11:07 +02:00
|
|
|
activation_map["Arcosh"] = &MLPPActivationOld::arcosh;
|
|
|
|
activationTest_map["Arcosh"] = &MLPPActivationOld::arcosh;
|
2023-02-07 17:36:03 +01:00
|
|
|
|
2023-04-22 14:11:07 +02:00
|
|
|
activation_map["Artanh"] = &MLPPActivationOld::artanh;
|
|
|
|
activationTest_map["Artanh"] = &MLPPActivationOld::artanh;
|
2023-02-07 17:36:03 +01:00
|
|
|
|
2023-04-22 14:11:07 +02:00
|
|
|
activation_map["Arcsch"] = &MLPPActivationOld::arcsch;
|
|
|
|
activationTest_map["Arcsch"] = &MLPPActivationOld::arcsch;
|
2023-02-07 17:36:03 +01:00
|
|
|
|
2023-04-22 14:11:07 +02:00
|
|
|
activation_map["Arsech"] = &MLPPActivationOld::arsech;
|
|
|
|
activationTest_map["Arsech"] = &MLPPActivationOld::arsech;
|
2023-02-07 17:36:03 +01:00
|
|
|
|
2023-04-22 14:11:07 +02:00
|
|
|
activation_map["Arcoth"] = &MLPPActivationOld::arcoth;
|
|
|
|
activationTest_map["Arcoth"] = &MLPPActivationOld::arcoth;
|
2023-02-07 17:36:03 +01:00
|
|
|
|
2023-04-22 17:17:58 +02:00
|
|
|
costDeriv_map["MSE"] = &MLPPCostOld::MSEDeriv;
|
|
|
|
cost_map["MSE"] = &MLPPCostOld::MSE;
|
|
|
|
costDeriv_map["RMSE"] = &MLPPCostOld::RMSEDeriv;
|
|
|
|
cost_map["RMSE"] = &MLPPCostOld::RMSE;
|
|
|
|
costDeriv_map["MAE"] = &MLPPCostOld::MAEDeriv;
|
|
|
|
cost_map["MAE"] = &MLPPCostOld::MAE;
|
|
|
|
costDeriv_map["MBE"] = &MLPPCostOld::MBEDeriv;
|
|
|
|
cost_map["MBE"] = &MLPPCostOld::MBE;
|
|
|
|
costDeriv_map["LogLoss"] = &MLPPCostOld::LogLossDeriv;
|
|
|
|
cost_map["LogLoss"] = &MLPPCostOld::LogLoss;
|
|
|
|
costDeriv_map["CrossEntropy"] = &MLPPCostOld::CrossEntropyDeriv;
|
|
|
|
cost_map["CrossEntropy"] = &MLPPCostOld::CrossEntropy;
|
|
|
|
costDeriv_map["HingeLoss"] = &MLPPCostOld::HingeLossDeriv;
|
|
|
|
cost_map["HingeLoss"] = &MLPPCostOld::HingeLoss;
|
|
|
|
costDeriv_map["WassersteinLoss"] = &MLPPCostOld::HingeLossDeriv;
|
|
|
|
cost_map["WassersteinLoss"] = &MLPPCostOld::HingeLoss;
|
2023-02-07 17:36:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MLPPOldOutputLayer::forwardPass() {
|
2023-04-22 17:17:58 +02:00
|
|
|
MLPPLinAlgOld alg;
|
2023-04-22 14:11:07 +02:00
|
|
|
MLPPActivationOld avn;
|
2023-02-07 17:36:03 +01:00
|
|
|
z = alg.scalarAdd(bias, alg.mat_vec_mult(input, weights));
|
|
|
|
a = (avn.*activation_map[activation])(z, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MLPPOldOutputLayer::Test(std::vector<real_t> x) {
|
2023-04-22 17:17:58 +02:00
|
|
|
MLPPLinAlgOld alg;
|
2023-04-22 14:11:07 +02:00
|
|
|
MLPPActivationOld avn;
|
2023-02-07 17:36:03 +01:00
|
|
|
z_test = alg.dot(weights, x) + bias;
|
|
|
|
a_test = (avn.*activationTest_map[activation])(z_test, false);
|
|
|
|
}
|