Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tianlh
LightGBM-DCU
Commits
9558417a
Unverified
Commit
9558417a
authored
Aug 14, 2019
by
Guolin Ke
Committed by
GitHub
Aug 14, 2019
Browse files
fix nan in tree model (#2303)
* fix nan in tree model * fix
parent
578a8c8a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
5 deletions
+9
-5
include/LightGBM/tree.h
include/LightGBM/tree.h
+1
-1
include/LightGBM/utils/common.h
include/LightGBM/utils/common.h
+6
-2
src/io/tree.cpp
src/io/tree.cpp
+2
-2
No files found.
include/LightGBM/tree.h
View file @
9558417a
...
@@ -422,7 +422,7 @@ inline void Tree::Split(int leaf, int feature, int real_feature,
...
@@ -422,7 +422,7 @@ inline void Tree::Split(int leaf, int feature, int real_feature,
split_feature_inner_
[
new_node_idx
]
=
feature
;
split_feature_inner_
[
new_node_idx
]
=
feature
;
split_feature_
[
new_node_idx
]
=
real_feature
;
split_feature_
[
new_node_idx
]
=
real_feature
;
split_gain_
[
new_node_idx
]
=
Common
::
AvoidInf
(
gain
)
;
split_gain_
[
new_node_idx
]
=
gain
;
// add two new leaves
// add two new leaves
left_child_
[
new_node_idx
]
=
~
leaf
;
left_child_
[
new_node_idx
]
=
~
leaf
;
right_child_
[
new_node_idx
]
=
~
num_leaves_
;
right_child_
[
new_node_idx
]
=
~
num_leaves_
;
...
...
include/LightGBM/utils/common.h
View file @
9558417a
...
@@ -663,7 +663,9 @@ inline static std::vector<int> VectorSize(const std::vector<std::vector<T>>& dat
...
@@ -663,7 +663,9 @@ inline static std::vector<int> VectorSize(const std::vector<std::vector<T>>& dat
}
}
inline
static
double
AvoidInf
(
double
x
)
{
inline
static
double
AvoidInf
(
double
x
)
{
if
(
x
>=
1e300
)
{
if
(
std
::
isnan
(
x
))
{
return
0.0
;
}
else
if
(
x
>=
1e300
)
{
return
1e300
;
return
1e300
;
}
else
if
(
x
<=
-
1e300
)
{
}
else
if
(
x
<=
-
1e300
)
{
return
-
1e300
;
return
-
1e300
;
...
@@ -673,7 +675,9 @@ inline static double AvoidInf(double x) {
...
@@ -673,7 +675,9 @@ inline static double AvoidInf(double x) {
}
}
inline
static
float
AvoidInf
(
float
x
)
{
inline
static
float
AvoidInf
(
float
x
)
{
if
(
x
>=
1e38
)
{
if
(
std
::
isnan
(
x
)){
return
0.0
f
;
}
else
if
(
x
>=
1e38
)
{
return
1e38
f
;
return
1e38
f
;
}
else
if
(
x
<=
-
1e38
)
{
}
else
if
(
x
<=
-
1e38
)
{
return
-
1e38
f
;
return
-
1e38
f
;
...
...
src/io/tree.cpp
View file @
9558417a
...
@@ -64,7 +64,7 @@ int Tree::Split(int leaf, int feature, int real_feature, uint32_t threshold_bin,
...
@@ -64,7 +64,7 @@ int Tree::Split(int leaf, int feature, int real_feature, uint32_t threshold_bin,
SetMissingType
(
&
decision_type_
[
new_node_idx
],
2
);
SetMissingType
(
&
decision_type_
[
new_node_idx
],
2
);
}
}
threshold_in_bin_
[
new_node_idx
]
=
threshold_bin
;
threshold_in_bin_
[
new_node_idx
]
=
threshold_bin
;
threshold_
[
new_node_idx
]
=
Common
::
AvoidInf
(
threshold_double
)
;
threshold_
[
new_node_idx
]
=
threshold_double
;
++
num_leaves_
;
++
num_leaves_
;
return
num_leaves_
-
1
;
return
num_leaves_
-
1
;
}
}
...
@@ -268,7 +268,7 @@ std::string Tree::NodeToJSON(int index) const {
...
@@ -268,7 +268,7 @@ std::string Tree::NodeToJSON(int index) const {
str_buf
<<
"{"
<<
'\n'
;
str_buf
<<
"{"
<<
'\n'
;
str_buf
<<
"
\"
split_index
\"
:"
<<
index
<<
","
<<
'\n'
;
str_buf
<<
"
\"
split_index
\"
:"
<<
index
<<
","
<<
'\n'
;
str_buf
<<
"
\"
split_feature
\"
:"
<<
split_feature_
[
index
]
<<
","
<<
'\n'
;
str_buf
<<
"
\"
split_feature
\"
:"
<<
split_feature_
[
index
]
<<
","
<<
'\n'
;
str_buf
<<
"
\"
split_gain
\"
:"
<<
split_gain_
[
index
]
<<
","
<<
'\n'
;
str_buf
<<
"
\"
split_gain
\"
:"
<<
Common
::
AvoidInf
(
split_gain_
[
index
]
)
<<
","
<<
'\n'
;
if
(
GetDecisionType
(
decision_type_
[
index
],
kCategoricalMask
))
{
if
(
GetDecisionType
(
decision_type_
[
index
],
kCategoricalMask
))
{
int
cat_idx
=
static_cast
<
int
>
(
threshold_
[
index
]);
int
cat_idx
=
static_cast
<
int
>
(
threshold_
[
index
]);
std
::
vector
<
int
>
cats
;
std
::
vector
<
int
>
cats
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment