jubatus_core
0.1.2
Jubatus: Online machine learning framework for distributed environment
Main Page
Namespaces
Classes
Files
File List
File Members
jubatus
core
clustering
discrete_distribution.cpp
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
#include "
discrete_distribution.hpp
"
18
19
#include <vector>
20
21
using
std::vector;
22
23
namespace
jubatus
{
24
namespace
core {
25
namespace
clustering {
26
27
discrete_distribution::discrete_distribution
(
28
vector<double>::iterator begin,
29
vector<double>::iterator end)
30
: r_(),
31
whist_() {
32
sum_
= 0;
33
for
(vector<double>::iterator it = begin; it != end; ++it) {
34
sum_
+= *it;
35
whist_
.push_back(
sum_
);
36
}
37
}
38
39
size_t
discrete_distribution::operator()
() {
40
double
d =
r_
.next_double() *
sum_
;
41
return
convert
(d);
42
}
43
44
size_t
discrete_distribution::convert
(
double
d) {
45
size_t
low = 0;
46
size_t
high =
whist_
.size() - 1;
47
size_t
mid = 0;
48
while
(low < high) {
49
mid = (low + high) / 2;
50
if
(
whist_
[mid] < d) {
51
if
(low == mid) {
52
break
;
53
}
54
low = mid;
55
}
else
{
56
if
(high == mid) {
57
break
;
58
}
59
high = mid;
60
}
61
}
62
return
high;
63
}
64
65
}
// namespace clustering
66
}
// namespace core
67
}
// namespace jubatus
jubatus
Definition:
anomaly_base.cpp:29
jubatus::core::clustering::discrete_distribution::r_
jubatus::util::math::random::mtrand r_
Definition:
discrete_distribution.hpp:37
jubatus::core::clustering::discrete_distribution::sum_
double sum_
Definition:
discrete_distribution.hpp:39
jubatus::core::clustering::discrete_distribution::operator()
size_t operator()()
Definition:
discrete_distribution.cpp:39
jubatus::core::clustering::discrete_distribution::discrete_distribution
discrete_distribution(std::vector< double >::iterator begin, std::vector< double >::iterator end)
Definition:
discrete_distribution.cpp:27
jubatus::core::clustering::discrete_distribution::convert
size_t convert(double d)
Definition:
discrete_distribution.cpp:44
jubatus::core::clustering::discrete_distribution::whist_
std::vector< double > whist_
Definition:
discrete_distribution.hpp:38
discrete_distribution.hpp
Generated on Tue Apr 28 2015 13:23:02 for jubatus_core by
1.8.9.1