31 namespace clustering {
34 dst.insert(dst.end(), src.begin(), src.end());
37 char digit(
int num,
int r,
int n) {
41 for (
int i = 0; i < r; ++i) {
49 for (common::sfv_t::const_iterator it = p.begin(); it != p.end(); ++it) {
56 for (common::sfv_t::const_iterator it = p.begin(); it != p.end(); ++it) {
57 s += std::pow((*it).second, 2);
66 common::sfv_t::const_iterator l = left.begin();
67 common::sfv_t::iterator r = right.begin();
68 while (l != left.end() && r != right.end()) {
69 if (l->first < r->first) {
70 std::pair<std::string, float> p = *l;
72 r = right.insert(r, p);
74 }
else if (l->first > r->first) {
77 r->second += l->second * s;
82 for (; l != left.end(); ++l) {
83 std::pair<std::string, float> p = *l;
91 common::sfv_t::const_iterator it1 = p1.begin();
92 common::sfv_t::const_iterator it2 = p2.begin();
93 while (it1 != p1.end() && it2 != p2.end()) {
94 if ((*it1).first < (*it2).first) {
95 ret.push_back((*it1));
97 }
else if ((*it1).first > (*it2).first) {
98 ret.push_back((*it2));
101 ret.push_back(make_pair((*it1).first, (*it1).second + (*it2).second));
106 for (; it1 != p1.end(); ++it1) {
107 ret.push_back((*it1));
109 for (; it2 != p2.end(); ++it2) {
110 ret.push_back((*it2));
118 common::sfv_t::const_iterator it1 = p1.begin();
119 common::sfv_t::const_iterator it2 = p2.begin();
120 while (it1 != p1.end() && it2 != p2.end()) {
121 if ((*it1).first < (*it2).first) {
122 ret.push_back((*it1));
124 }
else if ((*it1).first > (*it2).first) {
125 ret.push_back(make_pair((*it2).first, -(*it2).second));
128 ret.push_back(make_pair((*it1).first, (*it1).second - (*it2).second));
133 for (; it1 != p1.end(); ++it1) {
134 ret.push_back((*it1));
136 for (; it2 != p2.end(); ++it2) {
137 ret.push_back(make_pair((*it2).first, -(*it2).second));
145 for (common::sfv_t::const_iterator it = p.begin(); it != p.end(); ++it) {
146 ret.push_back(make_pair((*it).first, (*it).second*s));
153 common::sfv_t::const_iterator it1 = p1.begin();
154 common::sfv_t::const_iterator it2 = p2.begin();
155 while (it1 != p1.end() && it2 != p2.end()) {
156 int cmp = strcmp(it1->first.c_str(), it2->first.c_str());
158 ret += it1->second * it1->second;
160 }
else if (cmp > 0) {
161 ret += it2->second * it2->second;
164 ret += (it1->second - it2->second) * (it1->second - it2->second);
169 for (; it1 != p1.end(); ++it1) {
170 ret += std::pow(it1->second, 2);
172 for (; it2 != p2.end(); ++it2) {
173 ret += std::pow(it2->second, 2);
175 return std::sqrt(ret);
184 const vector<common::sfv_t>& P) {
186 double mindist = DBL_MAX;
187 for (vector<common::sfv_t>::const_iterator it = P.begin();
188 it != P.end(); ++it) {
189 double d =
dist(p, *it);
191 idx = it - P.begin();
195 return std::make_pair(idx, mindist);
201 for (wplist::const_iterator it = P.begin(); it != P.end(); ++it) {
202 double d =
dist((*it), d1);
204 midx = it - P.begin();
208 return std::make_pair(midx, md);
void scalar_mul_and_add(const common::sfv_t &left, float s, common::sfv_t &right)
common::sfv_t scalar_dot(const common::sfv_t &p, double s)
char digit(int num, int r, int n)
double dist(const common::sfv_t &p1, const common::sfv_t &p2)
void concat(const wplist &src, wplist &dst)
pair< size_t, double > min_dist(const common::sfv_t &p, const vector< common::sfv_t > &P)
common::sfv_t sub(const common::sfv_t &p1, const common::sfv_t &p2)
double sum(const common::sfv_t &p)
std::vector< std::pair< std::string, float > > sfv_t
double sum2(const common::sfv_t &p)
std::vector< weighted_point > wplist
common::sfv_t add(const common::sfv_t &p1, const common::sfv_t &p2)