/
mixable_stat_test.cpp
52 lines (41 loc) · 1.53 KB
/
mixable_stat_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Jubatus: Online machine learning framework for distributed environment
// Copyright (C) 2012 Preferred Infrastructure and Nippon Telegraph and Telephone Corporation.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License version 2.1 as published by the Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include <cmath>
#include <utility>
#include <gtest/gtest.h>
#include "mixable_stat.hpp"
using std::pair;
namespace jubatus {
TEST(mixable_stat_test, mixed_entropy) {
stat::mixable_stat p(1024);
p.push("test", 1.0);
p.push("test", 2.0);
p.push("test", 3.0);
double e_d = 3 * log(3);
double e_e = - e_d / 3 + log(3);
std::pair<double, size_t> d = p.get_diff();
ASSERT_DOUBLE_EQ(e_d, d.first);
ASSERT_EQ(3u, d.second);
p.put_diff(d);
ASSERT_DOUBLE_EQ(e_e, p.mixed_entropy());
ASSERT_DOUBLE_EQ(p.entropy(), p.mixed_entropy());
p.clear();
d = p.get_diff();
ASSERT_DOUBLE_EQ(0.0, d.first);
ASSERT_EQ(0u, d.second);
ASSERT_DOUBLE_EQ(0.0, p.mixed_entropy());
}
} // namespace jubatus