Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] Provide factory setup for creating models #1527

Merged
merged 2 commits into from
Oct 13, 2020

Conversation

edsavage
Copy link
Contributor

@edsavage edsavage commented Oct 8, 2020

Move boilerplate code for creating models to a base class method.

This goes some way to reducing duplicated code and standardising how models are created.

Relates to #1477

Move boilerplate code for creating models to a base class method.

This goes some way to reducing duplicated code and standardizing how models are created.
this->makeModel(params, features, startTime);
CCountingModel* modelNoGap = dynamic_cast<CCountingModel*>(m_Model.get());
BOOST_TEST_REQUIRE(modelNoGap);
BOOST_REQUIRE_EQUAL(std::size_t(0), this->addPerson("p", m_Gatherer));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
BOOST_REQUIRE_EQUAL(std::size_t(0), this->addPerson("p", m_Gatherer));
BOOST_REQUIRE_EQUAL(0, this->addPerson("p", m_Gatherer));

There's no need to cast expected types with Boost.Test. The places where we do this in existing code are a hangover from CppUnit.

this->makeModel(params, features, startTime);
CCountingModel* modelNoGap = dynamic_cast<CCountingModel*>(m_Model.get());
BOOST_TEST_REQUIRE(modelNoGap);
BOOST_REQUIRE_EQUAL(std::size_t(0), this->addPerson("p", m_Gatherer));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
BOOST_REQUIRE_EQUAL(std::size_t(0), this->addPerson("p", m_Gatherer));
BOOST_REQUIRE_EQUAL(0, this->addPerson("p", m_Gatherer));

Comment on lines 227 to 228
BOOST_REQUIRE_EQUAL(std::size_t(0), this->addPerson("p1", m_Gatherer));
BOOST_REQUIRE_EQUAL(std::size_t(1), this->addPerson("p2", m_Gatherer));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
BOOST_REQUIRE_EQUAL(std::size_t(0), this->addPerson("p1", m_Gatherer));
BOOST_REQUIRE_EQUAL(std::size_t(1), this->addPerson("p2", m_Gatherer));
BOOST_REQUIRE_EQUAL(0, this->addPerson("p1", m_Gatherer));
BOOST_REQUIRE_EQUAL(1, this->addPerson("p2", m_Gatherer));

CEventRateModel* modelNoGap = dynamic_cast<CEventRateModel*>(modelNoGap_.get());
for (std::size_t i = 0u; i < 2; ++i) {
BOOST_REQUIRE_EQUAL(
std::size_t(i),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::size_t(i),
i,

model.reset(m_Factory->makeModel({gatherer}));
BOOST_TEST_REQUIRE(model);
BOOST_REQUIRE_EQUAL(model_t::E_EventRateOnline, model->category());
BOOST_REQUIRE_EQUAL(params.s_BucketLength, model->bucketLength());
for (std::size_t i = 0u; i < numberPeople; ++i) {
BOOST_REQUIRE_EQUAL(
std::size_t(i),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::size_t(i),
i,

CEventRateModel* modelWithGap = dynamic_cast<CEventRateModel*>(modelWithGap_.get());
for (std::size_t i = 0u; i < 2; ++i) {
BOOST_REQUIRE_EQUAL(
std::size_t(i),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::size_t(i),
i,


protected:
using TInterimBucketCorrectorPtr = std::shared_ptr<ml::model::CInterimBucketCorrector>;
using TModelFactoryPtr = boost::shared_ptr<ml::model::CModelFactory>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this using boost::shared_ptr? If there's a good reason, e.g. it's used with some other Boost library that has boost::shared_ptr in its interface, please add a comment.

* remove unnecessary type conversions from
* replace boost constructs with standard library equivalents
Copy link
Contributor

@droberts195 droberts195 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@tveasey tveasey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM2

@edsavage edsavage merged commit 20dcdbc into elastic:master Oct 13, 2020
edsavage added a commit to edsavage/ml-cpp that referenced this pull request Oct 13, 2020
Move boilerplate code for creating models to a base class method.

This goes some way to reducing duplicated code and standardizing how models are created in the tests.
edsavage added a commit that referenced this pull request Oct 13, 2020
Move boilerplate code for creating models to a base class method.

This goes some way to reducing duplicated code and standardizing how models are created in the tests.

Backports #1527
@edsavage edsavage deleted the refactor_model_tests_model_setup branch October 13, 2020 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants