#ifndef MLPP_COST_H #define MLPP_COST_H // // Cost.hpp // // Created by Marc Melikyan on 1/16/21. // #include "core/math/math_defs.h" #include "core/object/reference.h" #include #include "../lin_alg/mlpp_matrix.h" #include "../lin_alg/mlpp_vector.h" //void set_weights(const Ref &val); //void set_bias(const Ref &val); class MLPPCost : public Reference { GDCLASS(MLPPCost, Reference); public: enum CostTypes { COST_TYPE_MSE = 0, COST_TYPE_RMSE, COST_TYPE_MAE, COST_TYPE_MBE, COST_TYPE_LOGISTIC_LOSS, COST_TYPE_CROSS_ENTROPY, COST_TYPE_HINGE_LOSS, COST_TYPE_WASSERSTEIN_LOSS, }; public: real_t msev(const Ref &y_hat, const Ref &y); real_t msem(const Ref &y_hat, const Ref &y); Ref mse_derivv(const Ref &y_hat, const Ref &y); Ref mse_derivm(const Ref &y_hat, const Ref &y); real_t rmsev(const Ref &y_hat, const Ref &y); real_t rmsem(const Ref &y_hat, const Ref &y); Ref rmse_derivv(const Ref &y_hat, const Ref &y); Ref rmse_derivm(const Ref &y_hat, const Ref &y); real_t maev(const Ref &y_hat, const Ref &y); real_t maem(const Ref &y_hat, const Ref &y); Ref mae_derivv(const Ref &y_hat, const Ref &y); Ref mae_derivm(const Ref &y_hat, const Ref &y); real_t mbev(const Ref &y_hat, const Ref &y); real_t mbem(const Ref &y_hat, const Ref &y); Ref mbe_derivv(const Ref &y_hat, const Ref &y); Ref mbe_derivm(const Ref &y_hat, const Ref &y); // Classification Costs real_t log_lossv(const Ref &y_hat, const Ref &y); real_t log_lossm(const Ref &y_hat, const Ref &y); Ref log_loss_derivv(const Ref &y_hat, const Ref &y); Ref log_loss_derivm(const Ref &y_hat, const Ref &y); real_t cross_entropyv(const Ref &y_hat, const Ref &y); real_t cross_entropym(const Ref &y_hat, const Ref &y); Ref cross_entropy_derivv(const Ref &y_hat, const Ref &y); Ref cross_entropy_derivm(const Ref &y_hat, const Ref &y); real_t huber_lossv(const Ref &y_hat, const Ref &y, real_t delta); real_t huber_lossm(const Ref &y_hat, const Ref &y, real_t delta); Ref huber_loss_derivv(const Ref &y_hat, const Ref &y, real_t delta); Ref huber_loss_derivm(const Ref &y_hat, const Ref &y, real_t delta); real_t hinge_lossv(const Ref &y_hat, const Ref &y); real_t hinge_lossm(const Ref &y_hat, const Ref &y); Ref hinge_loss_derivv(const Ref &y_hat, const Ref &y); Ref hinge_loss_derivm(const Ref &y_hat, const Ref &y); real_t hinge_losswv(const Ref &y_hat, const Ref &y, const Ref &weights, real_t C); real_t hinge_losswm(const Ref &y_hat, const Ref &y, const Ref &weights, real_t C); Ref hinge_loss_derivwv(const Ref &y_hat, const Ref &y, real_t C); Ref hinge_loss_derivwm(const Ref &y_hat, const Ref &y, real_t C); real_t wasserstein_lossv(const Ref &y_hat, const Ref &y); real_t wasserstein_lossm(const Ref &y_hat, const Ref &y); Ref wasserstein_loss_derivv(const Ref &y_hat, const Ref &y); Ref wasserstein_loss_derivm(const Ref &y_hat, const Ref &y); real_t dual_form_svm(const Ref &alpha, const Ref &X, const Ref &y); // TO DO: DON'T forget to add non-linear kernelizations. Ref dual_form_svm_deriv(const Ref &alpha, const Ref &X, const Ref &y); typedef real_t (MLPPCost::*VectorCostFunctionPointer)(const Ref &, const Ref &); typedef real_t (MLPPCost::*MatrixCostFunctionPointer)(const Ref &, const Ref &); typedef Ref (MLPPCost::*VectorDerivCostFunctionPointer)(const Ref &, const Ref &); typedef Ref (MLPPCost::*MatrixDerivCostFunctionPointer)(const Ref &, const Ref &); VectorCostFunctionPointer get_cost_function_ptr_normal_vector(const CostTypes cost); MatrixCostFunctionPointer get_cost_function_ptr_normal_matrix(const CostTypes cost); VectorDerivCostFunctionPointer get_cost_function_ptr_deriv_vector(const CostTypes cost); MatrixDerivCostFunctionPointer get_cost_function_ptr_deriv_matrix(const CostTypes cost); real_t run_cost_norm_vector(const CostTypes cost, const Ref &y_hat, const Ref &y); real_t run_cost_norm_matrix(const CostTypes cost, const Ref &y_hat, const Ref &y); Ref run_cost_deriv_vector(const CostTypes cost, const Ref &y_hat, const Ref &y); Ref run_cost_deriv_matrix(const CostTypes cost, const Ref &y_hat, const Ref &y); protected: static void _bind_methods(); }; VARIANT_ENUM_CAST(MLPPCost::CostTypes); #endif /* Cost_hpp */