YPC  0.2.0
model.h
1 #include "ypc/stbox/stx_common.h"
2 #ifdef YPC_SGX
3 #include "ypc/core_t/analyzer/data_source.h"
4 #include "ypc/core_t/analyzer/to_type.h"
5 #include "ypc/stbox/ebyte.h"
6 #include "ypc/stbox/tsgx/log.h"
7 #else
8 #include <glog/logging.h>
9 #endif
10 
11 #include "user_type.h"
12 
13 namespace hpda {
14 template <typename T1, typename T2> struct euclidean;
15 
16 template <> struct euclidean<iris_data_t, double> {
17  static double distance_square(const iris_data_t &p1, const iris_data_t &p2) {
18  double ret = 0;
19  auto v1 = p1.get<sepal_len>() - p2.get<sepal_len>();
20  auto v2 = p1.get<sepal_wid>() - p2.get<sepal_wid>();
21  auto v3 = p1.get<petal_len>() - p2.get<petal_len>();
22  auto v4 = p1.get<petal_wid>() - p2.get<petal_wid>();
23 
24  ret += v1 * v1;
25  ret += v2 * v2;
26  ret += v3 * v3;
27  ret += v4 * v4;
28  return ret;
29  }
30 };
31 } // namespace hpda
32 
33 iris_data_t operator+(const iris_data_t &p1, const iris_data_t &p2) {
34  iris_data_t d;
35  d.set<sepal_len>(p1.get<sepal_len>() + p2.get<sepal_len>());
36  d.set<sepal_wid>(p1.get<sepal_wid>() + p2.get<sepal_wid>());
37  d.set<petal_len>(p1.get<petal_len>() + p2.get<petal_len>());
38  d.set<petal_wid>(p1.get<petal_wid>() + p2.get<petal_wid>());
39  return d;
40 }
41 
42 iris_data_t operator/(const iris_data_t &p1, size_t v) {
43  iris_data_t d;
44  d.set<sepal_len>(p1.get<sepal_len>() / v);
45  d.set<sepal_wid>(p1.get<sepal_wid>() / v);
46  d.set<petal_len>(p1.get<petal_len>() / v);
47  d.set<petal_wid>(p1.get<petal_wid>() / v);
48  return d;
49 }
50 #include <hpda/algorithm/kmeans.h>
51 define_nt(iid, int);
52 define_nt(cid, std::string);
53 
55  hpda::ntobject<iris_data, species>, iris_data, double, iid>
56  kmeans_t;
57 typedef kmeans_t::average_distance average_distance_t;
58 typedef ff::util::ntobject<cid, iris_data, average_distance_t> mean_t;
59 define_nt(mean, std::vector<mean_t>);
60 
61 typedef ff::util::ntobject<mean> means_t;
hpda::algorithm::kmeans::internal::loyd_kmeans_impl
Definition: kmeans.h:54