Skylark (Sketching Library)  0.1
/var/lib/jenkins/jobs/Skylark/workspace/sketch/RFT.hpp
Go to the documentation of this file.
00001 #ifndef SKYLARK_RFT_HPP
00002 #define SKYLARK_RFT_HPP
00003 
00004 #ifndef SKYLARK_SKETCH_HPP
00005 #error "Include top-level sketch.hpp instead of including individuals headers"
00006 #endif
00007 
00008 namespace skylark { namespace sketch {
00009 
00010 namespace bstrand = boost::random;
00011 
00023 template < typename InputMatrixType,
00024            typename OutputMatrixType,
00025            template <typename> class KernelDistribution>
00026 class RFT_t {
00027     // To be specilized and derived.
00028     typedef InputMatrixType matrix_type;
00029     typedef OutputMatrixType output_matrix_type;
00030     typedef RFT_data_t<KernelDistribution> data_type;
00031 
00032     RFT_t(int N, int S, base::context_t& context) 
00033         : data_type(N, S, context) {
00034         SKYLARK_THROW_EXCEPTION (
00035           base::sketch_exception()
00036               << base::error_msg(
00037                  "This combination has not yet been implemented for RLT"));
00038     }
00039 
00040     RFT_t(const data_type& other_data)
00041         : data_type(other_data) {
00042         SKYLARK_THROW_EXCEPTION (
00043           base::sketch_exception()
00044               << base::error_msg(
00045                  "This combination has not yet been implemented for RFT"));
00046     }
00047 
00048     RFT_t(const boost::property_tree::ptree &pt)
00049         : data_type(pt) {
00050         SKYLARK_THROW_EXCEPTION (
00051           base::sketch_exception()
00052               << base::error_msg(
00053                  "This combination has not yet been implemented for RFT"));
00054     }
00055 
00056     void apply (const matrix_type& A,
00057                 output_matrix_type& sketch_of_A,
00058                 columnwise_tag dimension) const {
00059         SKYLARK_THROW_EXCEPTION (
00060           base::sketch_exception()
00061               << base::error_msg(
00062                  "This combination has not yet been implemented for RFT"));
00063     }
00064 
00065     void apply (const matrix_type& A,
00066                 output_matrix_type& sketch_of_A,
00067                 rowwise_tag dimension) const {
00068         SKYLARK_THROW_EXCEPTION (
00069           base::sketch_exception()
00070               << base::error_msg(
00071                  "This combination has not yet been implemented for RFT"));
00072     }
00073 };
00074 
00078 template< typename InputMatrixType,
00079           typename OutputMatrixType = InputMatrixType>
00080 struct GaussianRFT_t :
00081     public GaussianRFT_data_t,
00082     virtual public sketch_transform_t<InputMatrixType, OutputMatrixType > {
00083 
00084     // We use composition to defer calls to RFT_t
00085     typedef RFT_t<InputMatrixType, OutputMatrixType,
00086                   bstrand::normal_distribution > transform_t;
00087 
00088     typedef GaussianRFT_data_t data_type;
00089     typedef data_type::params_t params_t;
00090 
00091     GaussianRFT_t(int N, int S, double sigma, base::context_t& context)
00092         : data_type(N, S, sigma, context), _transform(*this) {
00093 
00094     }
00095 
00096     GaussianRFT_t(int N, int S, const params_t& params, base::context_t& context)
00097         : data_type(N, S, params, context), _transform(*this) {
00098 
00099     }
00100 
00101     GaussianRFT_t(const boost::property_tree::ptree &pt)
00102         : data_type(pt), _transform(*this) {
00103 
00104     }
00105 
00106     template <typename OtherInputMatrixType,
00107               typename OtherOutputMatrixType>
00108     GaussianRFT_t(
00109         const GaussianRFT_t<OtherInputMatrixType, OtherOutputMatrixType>& other)
00110         : data_type(other), _transform(*this) {
00111 
00112     }
00113 
00114     GaussianRFT_t (const data_type& other)
00115         : data_type(other), _transform(*this) {
00116 
00117     }
00118 
00123     void apply (const typename transform_t::matrix_type& A,
00124                 typename transform_t::output_matrix_type& sketch_of_A,
00125                 columnwise_tag dimension) const {
00126         _transform.apply(A, sketch_of_A, dimension);
00127     }
00128 
00133     void apply (const typename transform_t::matrix_type& A,
00134                 typename transform_t::output_matrix_type& sketch_of_A,
00135                 rowwise_tag dimension) const {
00136         _transform.apply(A, sketch_of_A, dimension);
00137     }
00138 
00139     int get_N() const { return this->_N; } 
00140     int get_S() const { return this->_S; } 
00142     const sketch_transform_data_t* get_data() const { return this; }
00143 
00144 private:
00145     transform_t _transform;
00146 
00147 };
00148 
00152 template< typename InputMatrixType,
00153           typename OutputMatrixType = InputMatrixType>
00154 struct LaplacianRFT_t :
00155     public LaplacianRFT_data_t,
00156     virtual public sketch_transform_t<InputMatrixType, OutputMatrixType > {
00157 
00158     // We use composition to defer calls to RFT_t
00159     typedef RFT_t<InputMatrixType, OutputMatrixType,
00160                   bstrand::cauchy_distribution > transform_t;
00161 
00162     typedef LaplacianRFT_data_t data_type;
00163     typedef data_type::params_t params_t;
00164 
00165     LaplacianRFT_t(int N, int S, double sigma, base::context_t& context)
00166         : data_type(N, S, sigma, context), _transform(*this) {
00167 
00168     }
00169 
00170     LaplacianRFT_t(int N, int S, const params_t& params, base::context_t& context)
00171         : data_type(N, S, params, context), _transform(*this) {
00172 
00173     }
00174 
00175     LaplacianRFT_t(const boost::property_tree::ptree &pt)
00176         : data_type(pt), _transform(*this) {
00177 
00178     }
00179 
00180     template <typename OtherInputMatrixType,
00181               typename OtherOutputMatrixType>
00182     LaplacianRFT_t(
00183         const LaplacianRFT_t<OtherInputMatrixType, OtherOutputMatrixType>& other)
00184         : data_type(other), _transform(*this) {
00185 
00186     }
00187 
00188     LaplacianRFT_t (const data_type& other)
00189         : data_type(other), _transform(*this) {
00190 
00191     }
00192 
00197     void apply (const typename transform_t::matrix_type& A,
00198                 typename transform_t::output_matrix_type& sketch_of_A,
00199                 columnwise_tag dimension) const {
00200         _transform.apply(A, sketch_of_A, dimension);
00201     }
00202 
00207     void apply (const typename transform_t::matrix_type& A,
00208                 typename transform_t::output_matrix_type& sketch_of_A,
00209                 rowwise_tag dimension) const {
00210         _transform.apply(A, sketch_of_A, dimension);
00211     }
00212 
00213     int get_N() const { return this->_N; } 
00214     int get_S() const { return this->_S; } 
00216     const sketch_transform_data_t* get_data() const { return this; }
00217 
00218 private:
00219     transform_t _transform;
00220 
00221 };
00222 
00223 } } 
00226 #if SKYLARK_HAVE_ELEMENTAL
00227 #include "RFT_Elemental.hpp"
00228 #endif
00229 
00230 #endif // SKYLARK_RFT_HPP