jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
regression_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_REGRESSION_REGRESSION_TEST_UTIL_HPP_
18 #define JUBATUS_CORE_REGRESSION_REGRESSION_TEST_UTIL_HPP_
19 
20 #include <cstdlib>
21 #include <cmath>
22 #include <cfloat>
23 #include <utility>
24 #include <vector>
25 #include <string>
26 #include <algorithm>
27 #include "jubatus/util/math/random.h"
28 
30  float mu,
31  float sigma,
32  size_t dim,
33  std::vector<double>& v) {
34  jubatus::util::math::random::mtrand rand(0);
35  for (size_t i = 0; i < dim; i++) {
36  float value = rand.next_gaussian(mu, sigma);
37  v.push_back(value);
38  }
39 }
40 
41 void make_random(size_t dim, std::vector<double>& v) {
42  jubatus::util::math::random::mtrand rand(0);
43  for (size_t i = 0; i < dim; i++) {
44  double value = rand.next_double();
45  v.push_back(value);
46  }
47 }
48 
49 std::pair<float, std::vector<double> > gen_random_data(
50  float mu,
51  float sigma,
52  size_t dim) {
53  std::pair<float, std::vector<double> > p;
54 
55  std::vector<double> coef;
56  make_random(dim, coef);
57  make_gaussian_random(mu, sigma, dim , p.second);
58  for (size_t i = 0; i < dim; i++) {
59  p.first += p.second[i] * coef[i];
60  }
61  return p;
62 }
63 
64 #endif // JUBATUS_CORE_REGRESSION_REGRESSION_TEST_UTIL_HPP_
std::pair< float, std::vector< double > > gen_random_data(float mu, float sigma, size_t dim)
void make_random(size_t dim, std::vector< double > &v)
void make_gaussian_random(float mu, float sigma, size_t dim, std::vector< double > &v)
std::vector< T > v(size)