Skylark (Sketching Library)  0.1
/var/lib/jenkins/jobs/Skylark/workspace/sketch/RLT_data.hpp
Go to the documentation of this file.
00001 #ifndef SKYLARK_RLT_DATA_HPP
00002 #define SKYLARK_RLT_DATA_HPP
00003 
00004 #ifndef SKYLARK_SKETCH_HPP
00005 #error "Include top-level sketch.hpp instead of including individuals headers"
00006 #endif
00007 
00008 #include <vector>
00009 
00010 #include "../utility/randgen.hpp"
00011 
00012 namespace skylark { namespace sketch {
00013 
00014 
00026 template <template <typename> class KernelDistribution>
00027 struct RLT_data_t : public sketch_transform_data_t {
00028 
00029     typedef dense_transform_data_t<KernelDistribution> underlying_data_type;
00030     typedef sketch_transform_data_t base_t;
00031 
00032     RLT_data_t (int N, int S, double inscale, double outscale, 
00033         skylark::base::context_t& context)
00034         : base_t(N, S, context, "RLT"), _inscale(inscale), 
00035           _outscale(outscale) {
00036 
00037         context = build();
00038     }
00039 
00045     virtual
00046     boost::property_tree::ptree to_ptree() const {
00047         SKYLARK_THROW_EXCEPTION (
00048           base::sketch_exception()
00049               << base::error_msg(
00050                  "Do not yet support serialization of generic RLT transform"));
00051 
00052         return boost::property_tree::ptree();
00053     }
00054 
00055 protected:
00056     RLT_data_t (int N, int S, double inscale, double outscale, 
00057         const skylark::base::context_t& context,
00058         std::string type)
00059         : base_t(N, S, context, type), _inscale(inscale),
00060           _outscale(outscale) {
00061 
00062     }
00063 
00064    base::context_t build() {
00065        base::context_t ctx = base_t::build();
00066        _underlying_data = boost::shared_ptr<underlying_data_type>(new
00067            underlying_data_type(base_t::_N, base_t::_S, _inscale, ctx));
00068        return ctx;
00069    }
00070 
00071     double _inscale; 
00072     double _outscale; 
00073     boost::shared_ptr<underlying_data_type> _underlying_data;
00076 };
00077 
00081 struct ExpSemigroupRLT_data_t :
00082         public RLT_data_t<utility::standard_levy_distribution_t> {
00083 
00084     typedef RLT_data_t<utility::standard_levy_distribution_t > base_t;
00085 
00087     struct params_t : public sketch_params_t {
00088 
00089         params_t(double beta) : beta(beta) {
00090 
00091         }
00092 
00093         const double beta;
00094     };
00095 
00096     ExpSemigroupRLT_data_t(int N, int S, double beta,
00097         skylark::base::context_t& context)
00098         : base_t(N, S, beta * beta / 2, std::sqrt(1.0 / S), 
00099             context, "ExpSemigroupRLT"), _beta(beta) {
00100 
00101         context = base_t::build();
00102     }
00103 
00104     ExpSemigroupRLT_data_t(int N, int S, const params_t& params,
00105         skylark::base::context_t& context)
00106         : base_t(N, S, params.beta * params.beta / 2, std::sqrt(1.0 / S), 
00107             context, "ExpSemigroupRLT"), _beta(params.beta) {
00108 
00109         context = base_t::build();
00110     }
00111 
00112     ExpSemigroupRLT_data_t(const boost::property_tree::ptree &pt) :
00113         base_t(pt.get<int>("N"), pt.get<int>("S"),
00114             pt.get<double>("beta") * pt.get<double>("beta") / 2,
00115             std::sqrt(1.0 / pt.get<double>("S")),
00116             base::context_t(pt.get_child("creation_context")), "ExpSemiGroupRLT"),
00117         _beta(pt.get<double>("beta")) {
00118 
00119         base_t::build();
00120     }
00121 
00127     virtual
00128     boost::property_tree::ptree to_ptree() const {
00129         boost::property_tree::ptree pt;
00130         sketch_transform_data_t::add_common(pt);
00131         pt.put("beta", _beta);
00132         return pt;
00133     }
00134 
00135 protected:
00136     ExpSemigroupRLT_data_t(int N, int S, double beta,
00137         const skylark::base::context_t& context, std::string type)
00138         : base_t(N, S,  beta * beta / 2, std::sqrt(1.0 / S), context, type), 
00139           _beta(beta) {
00140 
00141     }
00142 
00143 
00144 private:
00145     const double _beta;
00146 };
00147 
00148 } } 
00150 #endif