Skylark (Sketching Library)  0.1
/var/lib/jenkins/jobs/Skylark/workspace/sketch/PPT_data.hpp
Go to the documentation of this file.
00001 #ifndef SKYLARK_PPT_DATA_HPP
00002 #define SKYLARK_PPT_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/distributions.hpp"
00011 
00012 namespace skylark { namespace sketch {
00013 
00024 struct PPT_data_t : public sketch_transform_data_t {
00025 
00026     typedef sketch_transform_data_t base_t;
00027 
00029     struct params_t : public sketch_params_t {
00030 
00031         params_t(int q = 3, double c = 1.0, double gamma = 1.0) :
00032             q(q), c(c), gamma(gamma) {
00033 
00034         }
00035         const int q;
00036         const double c;
00037         const double gamma;
00038     };
00039 
00040     PPT_data_t (int N, int S, int q, double c, double gamma,
00041                 base::context_t& context)
00042         : base_t(N, S, context, "PPT"), _q(q), _c(c), _gamma(gamma) {
00043 
00044         context = build();
00045     }
00046 
00047     PPT_data_t (int N, int S, const params_t& params,
00048                 base::context_t& context)
00049         : base_t(N, S, context, "PPT"), _q(params.q), _c(params.c),
00050           _gamma(params.gamma) {
00051 
00052         context = build();
00053     }
00054 
00055     PPT_data_t (const boost::property_tree::ptree &pt) :
00056         base_t(pt.get<int>("N"), pt.get<int>("S"),
00057             base::context_t(pt.get_child("creation_context")), "PPT"),
00058         _q(pt.get<int>("q")),
00059         _c(pt.get<double>("c")),
00060         _gamma(pt.get<double>("gamma")) {
00061 
00062     }
00063 
00069     virtual
00070     boost::property_tree::ptree to_ptree() const {
00071         boost::property_tree::ptree pt;
00072         sketch_transform_data_t::add_common(pt);
00073         pt.put("q", _q);
00074         pt.put("c", _c);
00075         pt.put("gamma", _gamma);
00076         return pt;
00077     }
00078 
00079 protected:
00080 
00081     PPT_data_t (int N, int S, int q, double c, double gamma,
00082         const base::context_t& context, std::string type)
00083         : base_t(N, S, context, type), _q(q), _c(c), _gamma(gamma) {
00084 
00085 
00086     }
00087 
00088     base::context_t build() {
00089 
00090         base::context_t ctx = base_t::build();
00091 
00092         for(int i = 0; i < _q; i++)
00093             _cwts_data.push_back(
00094                  CWT_data_t(base_t::_N, base_t::_S, ctx));
00095 
00096         boost::random::uniform_int_distribution<size_t>
00097             distidx(0, base_t::_S - 1);
00098         _hash_idx = ctx.generate_random_samples_array(_q, distidx);
00099 
00100         utility::rademacher_distribution_t<double> distval;
00101         _hash_val = ctx.generate_random_samples_array(_q, distval);
00102 
00103         return ctx;
00104     }
00105 
00106     const int _q;         
00107     const double _c;
00108     const double _gamma;
00109 
00110     // Hashing info for the homogenity parameter c
00111     std::vector<size_t> _hash_idx;
00112     std::vector<double> _hash_val;
00113 
00114     std::list< CWT_data_t > _cwts_data;
00115 };
00116 
00117 } } 
00119 #endif