2012-03-18 08:08:38 +04:00
|
|
|
#include "OptimizerFactory.h"
|
|
|
|
#include "Optimizer.h"
|
|
|
|
|
|
|
|
#define BOOST_TEST_MODULE MertOptimizerFactory
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
#include <boost/scoped_ptr.hpp>
|
|
|
|
|
2012-07-01 00:39:10 +04:00
|
|
|
using namespace MosesTuning;
|
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
namespace
|
|
|
|
{
|
2012-03-18 08:08:38 +04:00
|
|
|
|
2012-03-25 16:31:44 +04:00
|
|
|
inline bool CheckBuildOptimizer(unsigned dim,
|
2012-05-10 02:51:05 +04:00
|
|
|
const std::vector<unsigned>& to_optimize,
|
|
|
|
const std::vector<bool>& positive,
|
|
|
|
const std::vector<parameter_t>& start,
|
|
|
|
const std::string& type,
|
2013-05-29 21:16:15 +04:00
|
|
|
unsigned int num_random)
|
|
|
|
{
|
2012-03-30 13:50:23 +04:00
|
|
|
boost::scoped_ptr<Optimizer> optimizer(OptimizerFactory::BuildOptimizer(dim, to_optimize, positive, start, type, num_random));
|
2012-03-25 16:31:44 +04:00
|
|
|
return optimizer.get() != NULL;
|
2012-03-18 08:08:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
BOOST_AUTO_TEST_CASE(optimizer_type)
|
|
|
|
{
|
2012-03-18 08:08:38 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
BOOST_AUTO_TEST_CASE(optimizer_build)
|
|
|
|
{
|
2012-03-18 08:08:38 +04:00
|
|
|
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;
|
2012-03-30 13:50:23 +04:00
|
|
|
std::vector<bool> positive(dim);
|
2012-03-31 05:47:28 +04:00
|
|
|
for (unsigned int k = 0; k < dim; k++)
|
2012-03-30 13:50:23 +04:00
|
|
|
positive[k] = false;
|
2012-03-18 08:08:38 +04:00
|
|
|
|
2012-03-30 13:50:23 +04:00
|
|
|
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));
|
2012-03-18 08:08:38 +04:00
|
|
|
}
|