1 #include "ypc/core_t/analyzer/data_source.h"
2 #include "ypc/stbox/ebyte.h"
3 #include "ypc/stbox/stx_common.h"
5 #include "ypc/stbox/tsgx/log.h"
7 #include <glog/logging.h>
11 #include "ypc/corecommon/to_type.h"
12 #include <hpda/extractor/raw_data.h>
13 #include <hpda/output/memory_output.h>
14 #include <hpda/processor/processor_base.h>
15 #include <hpda/processor/transform/concat.h>
18 template <
typename T1,
typename T2>
struct euclidean;
21 static double distance_square(
const iris_data_t &p1,
const iris_data_t &p2) {
23 auto v1 = p1.get<sepal_len>() - p2.get<sepal_len>();
24 auto v2 = p1.get<sepal_wid>() - p2.get<sepal_wid>();
25 auto v3 = p1.get<petal_len>() - p2.get<petal_len>();
26 auto v4 = p1.get<petal_wid>() - p2.get<petal_wid>();
37 iris_data_t operator+(
const iris_data_t &p1,
const iris_data_t &p2) {
39 d.set<sepal_len>(p1.get<sepal_len>() + p2.get<sepal_len>());
40 d.set<sepal_wid>(p1.get<sepal_wid>() + p2.get<sepal_wid>());
41 d.set<petal_len>(p1.get<petal_len>() + p2.get<petal_len>());
42 d.set<petal_wid>(p1.get<petal_wid>() + p2.get<petal_wid>());
46 iris_data_t operator/(
const iris_data_t &p1,
size_t v) {
48 d.set<sepal_len>(p1.get<sepal_len>() / v);
49 d.set<sepal_wid>(p1.get<sepal_wid>() / v);
50 d.set<petal_len>(p1.get<petal_len>() / v);
51 d.set<petal_wid>(p1.get<petal_wid>() / v);
54 #include <hpda/algorithm/kmeans.h>
57 typedef ff::util::ntobject<sepal_len, sepal_wid, petal_len, petal_wid, species>
65 virtual bool process() {
66 if (!has_input_value()) {
70 auto t = base::input_value();
71 m_data.get<iris_data>().set<sepal_len, sepal_wid, petal_len, petal_wid>(
72 t.get<sepal_len>(), t.get<sepal_wid>(), t.get<petal_len>(),
74 m_data.set<species>(t.get<species>());
75 base::consume_input_value();
78 virtual user_item_t output_value() {
return m_data; }
89 inline stbox::bytes do_parse(
const stbox::bytes ¶m) {
94 hpda::ntobject<iris_data, species>, iris_data, double, iid>
98 km.data_with_cluster_stream());
100 mo.get_engine()->run();
103 for (
auto it : mo.values()) {
104 result += it.get<species>();
106 result += std::to_string(it.get<iid>());
122 : m_source(source){};
124 inline stbox::bytes do_parse(
const stbox::bytes ¶m) {
129 hpda::ntobject<iris_data, species>, iris_data, double, iid>
134 kmeans_t::average_distance>
135 mo(km.means_stream());
137 mo.get_engine()->run();
140 for (
auto it : mo.values()) {
141 result += std::to_string(it.get<iid>());
143 auto id = it.get<kmeans_t::mean_point>();
144 result +=
" (" + std::to_string(
id.
template get<sepal_len>());
145 result +=
" ," + std::to_string(
id.get<sepal_wid>());
146 result +=
" ," + std::to_string(
id.get<petal_len>());
147 result +=
" ," + std::to_string(
id.get<petal_wid>());