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

Update deprecated functions in RF and GBT Examples #2878

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,6 @@ class DAAL_EXPORT ModelBuilder
return resId;
}

/**
* \DAAL_DEPRECATED
*/
DAAL_DEPRECATED NodeId addLeafNode(const TreeId treeId, const NodeId parentId, const size_t position, const size_t classLabel)
{
return addLeafNode(treeId, parentId, position, classLabel, 0);
}
Comment on lines -124 to -127
Copy link
Contributor

Choose a reason for hiding this comment

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

Major binary version of library should be increased since ABI would change and I'm unsure if it's feasible for next major release as some additional work related to versioned shared libraries is needed.
I'm OK with other non-deletion changes, but you should verify binary backward compatibility on both of Linux and Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you suggest not deleting for now?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, postpone PR merge until next major release and then bump major binary version.


/**
* Create Leaf node and add it to certain tree
* \param[in] treeId Tree to which new node is added
Expand All @@ -143,14 +135,6 @@ class DAAL_EXPORT ModelBuilder
return resId;
}

/**
* \DAAL_DEPRECATED
*/
DAAL_DEPRECATED NodeId addLeafNodeByProba(const TreeId treeId, const NodeId parentId, const size_t position, const double * const proba)
{
return addLeafNodeByProba(treeId, parentId, position, proba, 0);
}

/**
* Create Split node and add it to certain tree
* \param[in] treeId Tree to which new node is added
Expand All @@ -171,15 +155,6 @@ class DAAL_EXPORT ModelBuilder
return resId;
}

/**
* \DAAL_DEPRECATED
*/
DAAL_DEPRECATED NodeId addSplitNode(const TreeId treeId, const NodeId parentId, const size_t position, const size_t featureIndex,
const double featureValue)
{
return addSplitNode(treeId, parentId, position, featureIndex, featureValue, 0, 0);
}

void setNFeatures(size_t nFeatures)
{
if (!_model.get())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,6 @@ class DAAL_EXPORT ModelBuilder
return resId;
}

/**
* \DAAL_DEPRECATED
*/
DAAL_DEPRECATED NodeId addLeafNode(TreeId treeId, NodeId parentId, size_t position, double response)
{
return addLeafNode(treeId, parentId, position, response, 0);
}

/**
* Create Split node and add it to certain tree
* \param[in] treeId Tree to which new node is added
Expand All @@ -147,14 +139,6 @@ class DAAL_EXPORT ModelBuilder
return resId;
}

/**
* \DAAL_DEPRECATED
*/
DAAL_DEPRECATED NodeId addSplitNode(TreeId treeId, NodeId parentId, size_t position, size_t featureIndex, double featureValue)
{
return addSplitNode(treeId, parentId, position, featureIndex, featureValue, 0, 0);
}

/**
* Get built model
* \return Model pointer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,6 @@ class DAAL_EXPORT ModelBuilder
return resId;
}

/**
* \DAAL_DEPRECATED
*/
DAAL_DEPRECATED NodeId addLeafNode(TreeId treeId, NodeId parentId, size_t position, double response)
{
return addLeafNode(treeId, parentId, position, response, 0);
}

/**
* Create Split node and add it to certain tree
* \param[in] treeId Tree to which new node is added
Expand All @@ -145,14 +137,6 @@ class DAAL_EXPORT ModelBuilder
return resId;
}

/**
* \DAAL_DEPRECATED
*/
DAAL_DEPRECATED NodeId addSplitNode(TreeId treeId, NodeId parentId, size_t position, size_t featureIndex, double featureValue)
{
return addSplitNode(treeId, parentId, position, featureIndex, featureValue, 0, 0);
}

/**
* Get built model
* \return Model pointer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,40 @@ int main(int argc, char* argv[]) {

decision_forest::classification::ModelPtr buildModel() {
const size_t nNodes = 3;
const int defaultLeft = 0;
const double cover = 0.0;

ModelBuilder modelBuilder(nClasses, nTrees);
ModelBuilder::TreeId tree1 = modelBuilder.createTree(nNodes);
ModelBuilder::NodeId root1 =
modelBuilder.addSplitNode(tree1, ModelBuilder::noParent, 0, 0, 0.174108);
/* ModelBuilder::NodeId child12 = */ modelBuilder.addLeafNode(tree1, root1, 1, 4);
modelBuilder
.addSplitNode(tree1, ModelBuilder::noParent, 0, 0, 0.174108, defaultLeft, cover);
/* ModelBuilder::NodeId child12 = */ modelBuilder.addLeafNode(tree1, root1, 1, 4, cover);
double proba11[] = { 0.8, 0.1, 0.0, 0.1, 0.0 };
/* ModelBuilder::NodeId child11 = */ modelBuilder.addLeafNodeByProba(tree1, root1, 0, proba11);
/* ModelBuilder::NodeId child11 = */ modelBuilder.addLeafNodeByProba(tree1,
root1,
0,
proba11,
cover);

ModelBuilder::TreeId tree2 = modelBuilder.createTree(nNodes);
ModelBuilder::NodeId root2 =
modelBuilder.addSplitNode(tree2, ModelBuilder::noParent, 0, 1, 0.571184);
/* ModelBuilder::NodeId child22 = */ modelBuilder.addLeafNode(tree2, root2, 1, 4);
/* ModelBuilder::NodeId child21 = */ modelBuilder.addLeafNode(tree2, root2, 0, 2);
modelBuilder
.addSplitNode(tree2, ModelBuilder::noParent, 0, 1, 0.571184, defaultLeft, cover);
/* ModelBuilder::NodeId child22 = */ modelBuilder.addLeafNode(tree2, root2, 1, 4, cover);
/* ModelBuilder::NodeId child21 = */ modelBuilder.addLeafNode(tree2, root2, 0, 2, cover);

ModelBuilder::TreeId tree3 = modelBuilder.createTree(nNodes);
ModelBuilder::NodeId root3 =
modelBuilder.addSplitNode(tree3, ModelBuilder::noParent, 0, 0, 0.303995);
modelBuilder
.addSplitNode(tree3, ModelBuilder::noParent, 0, 0, 0.303995, defaultLeft, cover);
double proba32[] = { 0.05, 0.1, 0.0, 0.1, 0.75 };
/* ModelBuilder::NodeId child32 = */ modelBuilder.addLeafNodeByProba(tree3, root3, 1, proba32);
/* ModelBuilder::NodeId child31 = */ modelBuilder.addLeafNode(tree3, root3, 0, 2);
/* ModelBuilder::NodeId child32 = */ modelBuilder.addLeafNodeByProba(tree3,
root3,
1,
proba32,
cover);
/* ModelBuilder::NodeId child31 = */ modelBuilder.addLeafNode(tree3, root3, 0, 2, cover);
modelBuilder.setNFeatures(nFeatures);
return modelBuilder.getModel();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,17 @@ bool buildTree(size_t treeId,
bool &isRoot,
ModelBuilder &builder,
std::map<Node *, ParentPlace> &parentMap) {
const int defaultLeft = 0;
const double cover = 0.0;
if (node->left != NULL && node->right != NULL) {
if (isRoot) {
ModelBuilder::NodeId parent = builder.addSplitNode(treeId,
ModelBuilder::noParent,
0,
node->featureIndex,
node->featureValue);
node->featureValue,
defaultLeft,
cover);

parentMap[node->left] = ParentPlace(parent, 0);
;
Expand All @@ -158,7 +162,9 @@ bool buildTree(size_t treeId,
p.parentId,
p.place,
node->featureIndex,
node->featureValue);
node->featureValue,
defaultLeft,
cover);

parentMap[node->left] = ParentPlace(parent, 0);
;
Expand All @@ -168,12 +174,12 @@ bool buildTree(size_t treeId,
}
else {
if (isRoot) {
builder.addLeafNode(treeId, ModelBuilder::noParent, 0, node->classLabel);
builder.addLeafNode(treeId, ModelBuilder::noParent, 0, node->classLabel, cover);
isRoot = false;
}
else {
ParentPlace p = parentMap[node];
builder.addLeafNode(treeId, p.parentId, p.place, node->classLabel);
builder.addLeafNode(treeId, p.parentId, p.place, node->classLabel, cover);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,17 @@ bool buildTree(size_t treeId,
bool &isRoot,
ModelBuilder &builder,
const ParentPlace &parentPlace) {
const int defaultLeft = 0;
const double cover = 0.0;
if (node->left != NULL && node->right != NULL) {
if (isRoot) {
ModelBuilder::NodeId parent = builder.addSplitNode(treeId,
ModelBuilder::noParent,
0,
node->featureIndex,
node->featureValue);
node->featureValue,
defaultLeft,
cover);

isRoot = false;
buildTree(treeId, node->left, isRoot, builder, ParentPlace(parent, 0));
Expand All @@ -235,19 +239,25 @@ bool buildTree(size_t treeId,
parentPlace.parentId,
parentPlace.place,
node->featureIndex,
node->featureValue);
node->featureValue,
defaultLeft,
cover);

buildTree(treeId, node->left, isRoot, builder, ParentPlace(parent, 0));
buildTree(treeId, node->right, isRoot, builder, ParentPlace(parent, 1));
}
}
else {
if (isRoot) {
builder.addLeafNode(treeId, ModelBuilder::noParent, 0, node->response);
builder.addLeafNode(treeId, ModelBuilder::noParent, 0, node->response, cover);
isRoot = false;
}
else {
builder.addLeafNode(treeId, parentPlace.parentId, parentPlace.place, node->response);
builder.addLeafNode(treeId,
parentPlace.parentId,
parentPlace.place,
node->response,
cover);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,17 @@ bool buildTree(size_t treeId,
bool &isRoot,
ModelBuilder &builder,
const ParentPlace &parentPlace) {
const int defaultLeft = 0;
const double cover = 0.0;
if (node->left != NULL && node->right != NULL) {
if (isRoot) {
ModelBuilder::NodeId parent = builder.addSplitNode(treeId,
ModelBuilder::noParent,
0,
node->featureIndex,
node->featureValue);
node->featureValue,
defaultLeft,
cover);

isRoot = false;
buildTree(treeId, node->left, isRoot, builder, ParentPlace(parent, 0));
Expand All @@ -233,19 +237,25 @@ bool buildTree(size_t treeId,
parentPlace.parentId,
parentPlace.place,
node->featureIndex,
node->featureValue);
node->featureValue,
defaultLeft,
cover);

buildTree(treeId, node->left, isRoot, builder, ParentPlace(parent, 0));
buildTree(treeId, node->right, isRoot, builder, ParentPlace(parent, 1));
}
}
else {
if (isRoot) {
builder.addLeafNode(treeId, ModelBuilder::noParent, 0, node->response);
builder.addLeafNode(treeId, ModelBuilder::noParent, 0, node->response, cover);
isRoot = false;
}
else {
builder.addLeafNode(treeId, parentPlace.parentId, parentPlace.place, node->response);
builder.addLeafNode(treeId,
parentPlace.parentId,
parentPlace.place,
node->response,
cover);
}
}

Expand Down