Skylark (Sketching Library)
0.1
|
00001 #ifndef SKYLARK_KERNELS_HPP 00002 #define SKYLARK_KERNELS_HPP 00003 00004 #include "../sketch/sketch.hpp" 00005 #include "feature_transform_tags.hpp" 00006 00007 namespace skylark { namespace ml { namespace kernels { 00008 00009 struct gaussian_t { 00010 00011 gaussian_t(int N, double sigma) : _N(N), _sigma(sigma) { 00012 00013 } 00014 00015 template<typename IT, typename OT> 00016 sketch::sketch_transform_t<IT, OT> *create_rft(int S, 00017 regular_feature_transform_tag, base::context_t& context) const { 00018 return 00019 new sketch::GaussianRFT_t<IT, OT>(_N, S, _sigma, context); 00020 } 00021 00022 template<typename IT, typename OT> 00023 sketch::sketch_transform_t<IT, OT> *create_rft(int S, 00024 fast_feature_transform_tag, base::context_t& context) const { 00025 return 00026 new sketch::FastGaussianRFT_t<IT, OT>(_N, S, _sigma, context); 00027 } 00028 00029 // TODO method for gram matrix ? 00030 00031 00032 private: 00033 const int _N; 00034 const double _sigma; 00035 }; 00036 00037 struct polynomial_t { 00038 00039 polynomial_t(int N, int q = 2, double c = 1.0, double gamma = 1.0) 00040 : _N(N), _q(q), _c(c), _gamma(gamma) { 00041 00042 } 00043 00044 template<typename IT, typename OT> 00045 sketch::sketch_transform_t<IT, OT> *create_rft(int S, 00046 regular_feature_transform_tag, base::context_t& context) const { 00047 return 00048 new sketch::PPT_t<IT, OT>(_N, S, _q, _c, _gamma, context); 00049 } 00050 00051 // TODO method for gram matrix ? 00052 00053 00054 private: 00055 const int _N; 00056 const int _q; 00057 const double _c; 00058 const double _gamma; 00059 }; 00060 00061 struct laplacian_t { 00062 00063 laplacian_t(int N, double sigma) : _N(N), _sigma(sigma) { 00064 00065 } 00066 00067 template<typename IT, typename OT> 00068 sketch::sketch_transform_t<IT, OT> *create_rft(int S, 00069 regular_feature_transform_tag, base::context_t& context) const { 00070 return 00071 new sketch::LaplacianRFT_t<IT, OT>(_N, S, _sigma, context); 00072 } 00073 00074 // TODO method for gram matrix ? 00075 00076 00077 private: 00078 const int _N; 00079 const double _sigma; 00080 }; 00081 00082 struct expsemigroup_t { 00083 00084 expsemigroup_t(int N, double beta) : _N(N), _beta(beta) { 00085 00086 } 00087 00088 template<typename IT, typename OT> 00089 sketch::sketch_transform_t<IT, OT> *create_rft(int S, 00090 regular_feature_transform_tag, base::context_t& context) const { 00091 return 00092 new sketch::ExpSemigroupRLT_t<IT, OT>(_N, S, _beta, context); 00093 } 00094 00095 // TODO method for gram matrix ? 00096 00097 00098 private: 00099 const int _N; 00100 const double _beta; 00101 }; 00102 00103 } } } 00104 00105 #endif // SKYLARK_KERNELS_HPP