jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
classifier_test_util.hpp
Go to the documentation of this file.
1 // Jubatus: Online machine learning framework for distributed environment
2 // Copyright (C) 2011 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_CLASSIFIER_CLASSIFIER_TEST_UTIL_HPP_
18 #define JUBATUS_CORE_CLASSIFIER_CLASSIFIER_TEST_UTIL_HPP_
19 
20 #include <algorithm>
21 #include <cstdlib>
22 #include <cmath>
23 #include <cfloat>
24 #include <string>
25 #include <utility>
26 #include <vector>
27 
28 #include "jubatus/util/math/random.h"
29 
31  jubatus::util::math::random::mtrand& rand,
32  float mu,
33  float sigma,
34  size_t dim,
35  std::vector<double>& v) {
36  for (size_t i = 0; i < dim; i++) {
37  float value = rand.next_gaussian(mu, sigma);
38  v.push_back(value);
39  }
40 }
41 
43  jubatus::util::math::random::mtrand& rand,
44  const std::vector<float>& mus,
45  float sigma,
46  size_t dim,
47  std::vector<double>& v) {
48  for (size_t i = 0; i < dim; i++) {
49  float value = rand.next_gaussian(mus[i % mus.size()], sigma);
50  v.push_back(value);
51  }
52 }
53 
54 std::pair<std::string, std::vector<double> > gen_random_data(
55  jubatus::util::math::random::mtrand& rand) {
56  const float mu_pos = 1.0;
57  const float mu_neg = -1.0;
58  const float sigma = 1.5;
59  const size_t dim = 10;
60 
61  float mu;
62  std::pair<std::string, std::vector<double> > p;
63  if (rand() % 2 == 0) {
64  p.first = "OK";
65  mu = mu_pos;
66  } else {
67  p.first = "NG";
68  mu = mu_neg;
69  }
70  make_random(rand, mu, sigma, dim, p.second);
71  return p;
72 }
73 
74 std::pair<std::string, std::vector<double> > gen_random_data3(
75  jubatus::util::math::random::mtrand& rand) {
76  const char* labels[] = { "1", "2", "3" };
77  std::vector<float> mus;
78  mus.push_back(3);
79  mus.push_back(0);
80  mus.push_back(-3);
81 
82  const float sigma = 1.0;
83  const size_t dim = 10;
84 
85  std::pair<std::string, std::vector<double> > p;
86  size_t l = rand() % 3;
87  p.first = labels[l];
88  std::rotate(mus.begin(), mus.begin() + l, mus.end());
89  make_random(rand, mus, sigma, dim, p.second);
90  return p;
91 }
92 
93 #endif // JUBATUS_CORE_CLASSIFIER_CLASSIFIER_TEST_UTIL_HPP_
std::pair< std::string, std::vector< double > > gen_random_data3(jubatus::util::math::random::mtrand &rand)
std::pair< std::string, std::vector< double > > gen_random_data(jubatus::util::math::random::mtrand &rand)
std::vector< T > v(size)
void make_random(jubatus::util::math::random::mtrand &rand, float mu, float sigma, size_t dim, std::vector< double > &v)