-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathtest_abstract_parameter_dist.cpp
More file actions
138 lines (133 loc) · 5.61 KB
/
test_abstract_parameter_dist.cpp
File metadata and controls
138 lines (133 loc) · 5.61 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* Copyright (C) 2020-2026 MEmilio
*
* Authors: Julia Bicker
*
* Contact: Martin J. Kuehn <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "abm/personal_rng.h"
#include "memilio/utils/abstract_parameter_distribution.h"
#include "memilio/utils/parameter_distributions.h"
#include "memilio/utils/random_number_generator.h"
#include "models/abm/personal_rng.h"
#include <gtest/gtest.h>
#include <vector>
TEST(AbstractParameterDist, test_abstract_normal_distribution)
{
mio::AbstractParameterDistribution p1(mio::ParameterDistributionNormal(10., 0.5));
mio::AbstractParameterDistribution p2(mio::ParameterDistributionNormal(20., 0.3));
auto params1 = std::vector<double>{10., 0.5};
auto params2 = std::vector<double>{20., 0.3};
//Check parameters
EXPECT_EQ(p1.params(), params1);
EXPECT_EQ(p2.params(), params2);
//check sampling function
auto counter = mio::Counter<uint32_t>{0};
auto prng = mio::abm::PersonalRandomNumberGenerator(mio::thread_local_rng().get_key(), 0, counter);
EXPECT_GE(p2.get(mio::thread_local_rng()), 0.);
EXPECT_GE(p2.get(prng), 0.);
//check smaller impl
mio::AbstractParameterDistribution p3(mio::ParameterDistributionUniform(0., 1.));
bool smaller = (p1 < p2);
bool not_smaller = (p1 < p3);
EXPECT_EQ(smaller, true);
EXPECT_EQ(not_smaller, false);
}
TEST(AbstractParameterDist, test_abstract_uniform_distribution)
{
mio::AbstractParameterDistribution p1(mio::ParameterDistributionUniform(0., 1.));
mio::AbstractParameterDistribution p2(mio::ParameterDistributionUniform(2., 3.));
auto params1 = std::vector<double>{0., 1.};
auto params2 = std::vector<double>{2., 3.};
//Check parameters
EXPECT_EQ(p1.params(), params1);
EXPECT_EQ(p2.params(), params2);
//check sampling function
auto counter = mio::Counter<uint32_t>{0};
auto prng = mio::abm::PersonalRandomNumberGenerator(mio::thread_local_rng().get_key(), 0, counter);
EXPECT_GE(p1.get(mio::thread_local_rng()), 0.);
EXPECT_GE(p1.get(prng), 0.);
EXPECT_LE(p1.get(mio::thread_local_rng()), 1.);
EXPECT_LE(p1.get(prng), 1.);
//check smaller impl
mio::AbstractParameterDistribution p3(mio::ParameterDistributionNormal(0., 1.));
bool smaller = (p1 < p2);
bool not_smaller = (p1 < p3);
EXPECT_EQ(smaller, true);
EXPECT_EQ(not_smaller, false);
}
TEST(AbstractParameterDist, test_abstract_lognormal_distribution)
{
mio::AbstractParameterDistribution p1(mio::ParameterDistributionLogNormal(1., 0.25));
mio::AbstractParameterDistribution p2(mio::ParameterDistributionLogNormal(2., 0.1));
auto params1 = std::vector<double>{1., 0.25};
auto params2 = std::vector<double>{2., 0.1};
//Check parameters
EXPECT_EQ(p1.params(), params1);
EXPECT_EQ(p2.params(), params2);
//check sampling function
auto counter = mio::Counter<uint32_t>{0};
auto prng = mio::abm::PersonalRandomNumberGenerator(mio::thread_local_rng().get_key(), 0, counter);
EXPECT_GE(p1.get(mio::thread_local_rng()), 0.);
EXPECT_GE(p1.get(prng), 0.);
//check smaller impl
mio::AbstractParameterDistribution p3(mio::ParameterDistributionNormal(0., 1.));
bool smaller = (p1 < p2);
bool not_smaller = (p1 < p3);
EXPECT_EQ(smaller, true);
EXPECT_EQ(not_smaller, false);
}
TEST(AbstractParameterDist, test_abstract_exponential_distribution)
{
mio::AbstractParameterDistribution p1(mio::ParameterDistributionExponential(1.));
mio::AbstractParameterDistribution p2(mio::ParameterDistributionExponential(2.));
auto params1 = std::vector<double>{1.};
auto params2 = std::vector<double>{2.};
//Check parameters
EXPECT_EQ(p1.params(), params1);
EXPECT_EQ(p2.params(), params2);
//check sampling function
auto counter = mio::Counter<uint32_t>{0};
auto prng = mio::abm::PersonalRandomNumberGenerator(mio::thread_local_rng().get_key(), 0, counter);
EXPECT_GE(p1.get(mio::thread_local_rng()), 0.);
EXPECT_GE(p1.get(prng), 0.);
//check smaller impl
mio::AbstractParameterDistribution p3(mio::ParameterDistributionNormal(0., 1.));
bool smaller = (p1 < p2);
bool not_smaller = (p1 < p3);
EXPECT_EQ(smaller, true);
EXPECT_EQ(not_smaller, false);
}
TEST(AbstractParameterDist, test_abstract_constant_distribution)
{
mio::AbstractParameterDistribution p1(mio::ParameterDistributionConstant(1.));
mio::AbstractParameterDistribution p2(mio::ParameterDistributionConstant(2.));
auto params1 = std::vector<double>{1.};
auto params2 = std::vector<double>{2.};
//Check parameters
EXPECT_EQ(p1.params(), params1);
EXPECT_EQ(p2.params(), params2);
//check sampling function
auto counter = mio::Counter<uint32_t>{0};
auto prng = mio::abm::PersonalRandomNumberGenerator(mio::thread_local_rng().get_key(), 0, counter);
EXPECT_EQ(p1.get(mio::thread_local_rng()), 1.);
EXPECT_EQ(p1.get(prng), 1.);
//check smaller impl
mio::AbstractParameterDistribution p3(mio::ParameterDistributionNormal(0., 1.));
bool smaller = (p1 < p2);
bool not_smaller = (p1 < p3);
EXPECT_EQ(smaller, true);
EXPECT_EQ(not_smaller, false);
}