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
3af7f006
Unverified
Commit
3af7f006
authored
Feb 08, 2020
by
jpkoponen
Committed by
GitHub
Feb 08, 2020
Browse files
Preventing denormal leaf values. (#2724)
parent
87b6396d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
3 deletions
+20
-3
include/LightGBM/tree.h
include/LightGBM/tree.h
+20
-3
No files found.
include/LightGBM/tree.h
View file @
3af7f006
...
@@ -89,8 +89,13 @@ class Tree {
...
@@ -89,8 +89,13 @@ class Tree {
/*! \brief Set the output of one leaf */
/*! \brief Set the output of one leaf */
inline
void
SetLeafOutput
(
int
leaf
,
double
output
)
{
inline
void
SetLeafOutput
(
int
leaf
,
double
output
)
{
// Prevent denormal values because they can cause std::out_of_range exception when converting strings to doubles
if
(
IsZero
(
output
))
{
leaf_value_
[
leaf
]
=
0
;
}
else
{
leaf_value_
[
leaf
]
=
output
;
leaf_value_
[
leaf
]
=
output
;
}
}
}
/*!
/*!
* \brief Adding prediction value of this tree model to scores
* \brief Adding prediction value of this tree model to scores
...
@@ -149,7 +154,13 @@ class Tree {
...
@@ -149,7 +154,13 @@ class Tree {
inline
void
Shrinkage
(
double
rate
)
{
inline
void
Shrinkage
(
double
rate
)
{
#pragma omp parallel for schedule(static, 1024) if (num_leaves_ >= 2048)
#pragma omp parallel for schedule(static, 1024) if (num_leaves_ >= 2048)
for
(
int
i
=
0
;
i
<
num_leaves_
;
++
i
)
{
for
(
int
i
=
0
;
i
<
num_leaves_
;
++
i
)
{
leaf_value_
[
i
]
*=
rate
;
double
new_leaf_value
=
leaf_value_
[
i
]
*
rate
;
// Prevent denormal values because they can cause std::out_of_range exception when converting strings to doubles
if
(
IsZero
(
new_leaf_value
))
{
leaf_value_
[
i
]
=
0
;
}
else
{
leaf_value_
[
i
]
=
new_leaf_value
;
}
}
}
shrinkage_
*=
rate
;
shrinkage_
*=
rate
;
}
}
...
@@ -161,7 +172,13 @@ class Tree {
...
@@ -161,7 +172,13 @@ class Tree {
inline
void
AddBias
(
double
val
)
{
inline
void
AddBias
(
double
val
)
{
#pragma omp parallel for schedule(static, 1024) if (num_leaves_ >= 2048)
#pragma omp parallel for schedule(static, 1024) if (num_leaves_ >= 2048)
for
(
int
i
=
0
;
i
<
num_leaves_
;
++
i
)
{
for
(
int
i
=
0
;
i
<
num_leaves_
;
++
i
)
{
leaf_value_
[
i
]
=
val
+
leaf_value_
[
i
];
double
new_leaf_value
=
val
+
leaf_value_
[
i
];
// Prevent denormal values because they can cause std::out_of_range exception when converting strings to doubles
if
(
IsZero
(
new_leaf_value
))
{
leaf_value_
[
i
]
=
0
;
}
else
{
leaf_value_
[
i
]
=
new_leaf_value
;
}
}
}
// force to 1.0
// force to 1.0
shrinkage_
=
1.0
f
;
shrinkage_
=
1.0
f
;
...
...
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