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
|
#include "OptimizerFactory.h"
#include "Optimizer.h"
#define BOOST_TEST_MODULE MertOptimizerFactory
#include <boost/test/unit_test.hpp>
#include <boost/scoped_ptr.hpp>
namespace {
inline bool CheckBuildOptimizer(unsigned dim,
const std::vector<unsigned>& to_optimize,
const std::vector<bool>& positive,
const std::vector<parameter_t>& start,
const std::string& type,
unsigned int num_random) {
boost::scoped_ptr<Optimizer> optimizer(OptimizerFactory::BuildOptimizer(dim, to_optimize, positive, start, type, num_random));
return optimizer.get() != NULL;
}
} // namespace
BOOST_AUTO_TEST_CASE(optimizer_type) {
BOOST_CHECK_EQUAL(OptimizerFactory::GetOptimizerType("powell"),
OptimizerFactory::POWELL);
BOOST_CHECK_EQUAL(OptimizerFactory::GetOptimizerType("random"),
OptimizerFactory::RANDOM);
BOOST_CHECK_EQUAL(OptimizerFactory::GetOptimizerType("random-direction"),
OptimizerFactory::RANDOM_DIRECTION);
}
BOOST_AUTO_TEST_CASE(optimizer_build) {
const unsigned dim = 3;
std::vector<unsigned> to_optimize;
to_optimize.push_back(1);
to_optimize.push_back(2);
to_optimize.push_back(3);
std::vector<parameter_t> start;
start.push_back(0.3);
start.push_back(0.1);
start.push_back(0.2);
const unsigned int num_random = 1;
std::vector<bool> positive(dim);
for (unsigned int k = 0; k < dim; k++)
positive[k] = false;
BOOST_CHECK(CheckBuildOptimizer(dim, to_optimize, positive, start, "powell", num_random));
BOOST_CHECK(CheckBuildOptimizer(dim, to_optimize, positive, start, "random", num_random));
BOOST_CHECK(CheckBuildOptimizer(dim, to_optimize, positive, start, "random-direction", num_random));
}
|