Skip to content

Commit f1251fa

Browse files
committed
V 0.9.1: Patch for bugs on SOLARIS and with UBSAN
1 parent 6ed4a7b commit f1251fa

File tree

3 files changed

+43
-17
lines changed

3 files changed

+43
-17
lines changed

R-package/NEWS.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ agtboost 0.9.0 (2020-08-12)
55
- Initial release.
66

77
------------------------------------------------------------------------
8-
agtboost 0.9.1 (2020-09-06)
8+
agtboost 0.9.1 (2020-10-04)
99
------------------------------------------------------------------------
1010

11-
- Patch fixing error from log(<int>) on Solaris. Fixed by casting problematic type to double.
11+
- Patch fixing error from log(<int>) on Solaris. Fixed by casting problematic type to double.
12+
- Fixing error on UBSAN: Undefined behaviour (method call from NULL pointer)
13+
- Checked with rhub::check_with_sanitizers() and rhub::check_on_solaris()
14+

R-package/inst/include/node.hpp

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ class node
3131
node* left;
3232
node* right;
3333

34-
node* createLeaf(double node_prediction, double node_tr_loss, double local_optimism, double CRt,
34+
//node(double node_prediction, double node_tr_loss, double local_optimism, double CRt,
35+
// int obs_in_node, int obs_in_parent, int obs_tot);
36+
37+
void createLeaf(double node_prediction, double node_tr_loss, double local_optimism, double CRt,
3538
int obs_in_node, int obs_in_parent, int obs_tot);
3639

3740
node* getLeft();
@@ -55,6 +58,22 @@ class node
5558
bool deSerialize(node *nptr, std::ifstream& f, int& lineNum);
5659
};
5760

61+
/*
62+
// Constructor
63+
node::node(double node_prediction, double node_tr_loss, double local_optimism, double CRt,
64+
int obs_in_node, int obs_in_parent, int obs_tot)
65+
{
66+
this->node_prediction = node_prediction;
67+
this->node_tr_loss = node_tr_loss;
68+
this->local_optimism = local_optimism;
69+
this->prob_node = (double)obs_in_node / obs_tot; // prob_node;
70+
double prob_split_complement = 1.0 - (double)obs_in_node / obs_in_parent; // if left: p(right, not left), oposite for right
71+
this->p_split_CRt = prob_split_complement * CRt;
72+
this->obs_in_node = obs_in_node;
73+
this->left = NULL;
74+
this->right = NULL;
75+
}
76+
*/
5877

5978
// METHODS
6079

@@ -151,21 +170,21 @@ bool node::deSerialize(node *nptr, std::ifstream& f, int& lineNum)
151170
return true;
152171
}
153172

154-
node* node::createLeaf(double node_prediction, double node_tr_loss, double local_optimism, double CRt,
173+
void node::createLeaf(double node_prediction, double node_tr_loss, double local_optimism, double CRt,
155174
int obs_in_node, int obs_in_parent, int obs_tot)
156175
{
157-
node* n = new node;
158-
n->node_prediction = node_prediction;
159-
n->node_tr_loss = node_tr_loss;
160-
n->local_optimism = local_optimism;
161-
n->prob_node = (double)obs_in_node / obs_tot; // prob_node;
176+
//node* n = new node;
177+
this->node_prediction = node_prediction;
178+
this->node_tr_loss = node_tr_loss;
179+
this->local_optimism = local_optimism;
180+
this->prob_node = (double)obs_in_node / obs_tot; // prob_node;
162181
double prob_split_complement = 1.0 - (double)obs_in_node / obs_in_parent; // if left: p(right, not left), oposite for right
163-
n->p_split_CRt = prob_split_complement * CRt;
164-
n->obs_in_node = obs_in_node;
165-
n->left = NULL;
166-
n->right = NULL;
182+
this->p_split_CRt = prob_split_complement * CRt;
183+
this->obs_in_node = obs_in_node;
184+
this->left = NULL;
185+
this->right = NULL;
167186

168-
return n;
187+
//return n;
169188
}
170189

171190

@@ -387,8 +406,8 @@ bool node::split_information(const Tvec<double> &g, const Tvec<double> &h, const
387406

388407

389408
// 6. Update split information in child nodes
390-
left = createLeaf(w_l, tr_loss_l, local_opt_l, this->CRt, n_left, n_left+n_right, n); // Update createLeaf()
391-
right = createLeaf(w_r, tr_loss_r, local_opt_r, this->CRt, n_right, n_left+n_right, n);
409+
left->createLeaf(w_l, tr_loss_l, local_opt_l, this->CRt, n_left, n_left+n_right, n); // Update createLeaf()
410+
right->createLeaf(w_r, tr_loss_r, local_opt_r, this->CRt, n_right, n_left+n_right, n);
392411
//Rcpp::Rcout << "p_left_CRt: " << left->p_split_CRt << "\n" << "p_right_CRt:" << right->p_split_CRt << std::endl;
393412

394413
// 7. update childs to left right

R-package/inst/include/tree.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ void GBTREE::train(Tvec<double> &g, Tvec<double> &h, Tmat<double> &X, Tmat<doubl
124124
gxh += g[i]*h[i];
125125
}
126126
double local_optimism = (G2 - 2.0*gxh*(G/H) + G*G*H2/(H*H)) / (H*n);
127-
root = root->createLeaf(-G/H, -G*G/(2*H*n), local_optimism, local_optimism, n, n, n);
127+
128+
node* root_ptr = new node;
129+
root_ptr->createLeaf(-G/H, -G*G/(2*H*n), local_optimism, local_optimism, n, n, n);
130+
root = root_ptr;
131+
//root = root->createLeaf(-G/H, -G*G/(2*H*n), local_optimism, local_optimism, n, n, n);
128132
}
129133

130134
// Root-node indices

0 commit comments

Comments
 (0)