// // DualSVC.hpp // // Created by Marc Melikyan on 10/2/20. // // http://disp.ee.ntu.edu.tw/~pujols/Support%20Vector%20Machine.pdf // http://ciml.info/dl/v0_99/ciml-v0_99-ch11.pdf // Were excellent for the practical intution behind the dual formulation. #ifndef DualSVC_hpp #define DualSVC_hpp #include #include namespace MLPP { class DualSVC{ public: DualSVC(std::vector> inputSet, std::vector outputSet, double C, std::string kernel = "Linear"); DualSVC(std::vector> inputSet, std::vector outputSet, double C, std::string kernel, double p, double c); std::vector modelSetTest(std::vector> X); double modelTest(std::vector x); void gradientDescent(double learning_rate, int max_epoch, bool UI = 1); void SGD(double learning_rate, int max_epoch, bool UI = 1); void MBGD(double learning_rate, int max_epoch, int mini_batch_size, bool UI = 1); double score(); void save(std::string fileName); private: void init(); double Cost(std::vector alpha, std::vector> X, std::vector y); std::vector Evaluate(std::vector> X); std::vector propagate(std::vector> X); double Evaluate(std::vector x); double propagate(std::vector x); void forwardPass(); void alphaProjection(); double kernelFunction(std::vector v, std::vector u, std::string kernel); std::vector> kernelFunction(std::vector> U, std::vector> V, std::string kernel); std::vector> inputSet; std::vector outputSet; std::vector z; std::vector y_hat; double bias; std::vector alpha; std::vector> K; double C; int n; int k; std::string kernel; double p; // Poly double c; // Poly // UI Portion void UI(int epoch, double cost_prev); }; } #endif /* DualSVC_hpp */