jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
testutil.hpp
Go to the documentation of this file.
1 // Jubatus: Online machine learning framework for distributed environment
2 // Copyright (C) 2013 Preferred Networks and Nippon Telegraph and Telephone Corporation.
3 //
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License version 2.1 as published by the Free Software Foundation.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 
17 #ifndef JUBATUS_CORE_CLUSTERING_TESTUTIL_HPP_
18 #define JUBATUS_CORE_CLUSTERING_TESTUTIL_HPP_
19 
20 #include <string>
21 #include <vector>
22 #include <ctime>
23 #include "jubatus/util/lang/cast.h"
24 #include "jubatus/util/math/random.h"
25 #include "../common/type.hpp"
26 #include "clustering.hpp"
27 #include "types.hpp"
28 
29 using jubatus::util::lang::lexical_cast;
30 using jubatus::util::math::random::mtrand;
31 using std::make_pair;
32 using std::string;
33 
34 namespace jubatus {
35 namespace core {
36 namespace clustering {
37 
38 inline weighted_point get_point(size_t d) {
39  static mtrand r_(0);
40  weighted_point ret;
41  for (size_t i = 0; i < d; ++i) {
42  ret.data.push_back(make_pair(
43  lexical_cast<string, int>(i), r_.next_gaussian(0, 10)));
44  }
45  ret.weight = 1;
46  return ret;
47 }
48 
49 inline weighted_point get_point(size_t d, const std::vector<double>& c) {
50  static mtrand r_(0);
51  weighted_point ret;
52  for (size_t i = 0; i < d; ++i) {
53  ret.data.push_back(std::make_pair(
54  "#test_" + lexical_cast<string, int>(i),
55  c[i] + r_.next_gaussian(0, 10)));
56  }
57  ret.weight = 1;
58  return ret;
59 }
60 
61 inline std::vector<weighted_point> get_points(size_t n, size_t d) {
62  std::vector<weighted_point> ret;
63  for (size_t i = 0; i < n; ++i) {
64  ret.push_back(get_point(d));
65  }
66  return ret;
67 }
68 
69 inline std::vector<weighted_point> get_points(size_t n, size_t d,
70  const std::vector<double>& c) {
71  std::vector<weighted_point> ret;
72  for (size_t i = 0; i < n; ++i) {
73  ret.push_back(get_point(d, c));
74  }
75  return ret;
76 }
77 
78 } // namespace clustering
79 } // namespace core
80 } // namespace jubatus
81 
82 #endif // JUBATUS_CORE_CLUSTERING_TESTUTIL_HPP_
std::vector< weighted_point > get_points(size_t n, size_t d)
Definition: testutil.hpp:61
weighted_point get_point(size_t d)
Definition: testutil.hpp:38