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
39eb041f
Unverified
Commit
39eb041f
authored
Aug 25, 2022
by
José Morales
Committed by
GitHub
Aug 25, 2022
Browse files
update tree to if-else (#5422)
* update tree to if-else * add missing ) * fix case * trigger ci
parent
504ff50d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
15 deletions
+12
-15
src/io/tree.cpp
src/io/tree.cpp
+12
-15
No files found.
src/io/tree.cpp
View file @
39eb041f
...
@@ -523,35 +523,32 @@ std::string Tree::NumericalDecisionIfElse(int node) const {
...
@@ -523,35 +523,32 @@ std::string Tree::NumericalDecisionIfElse(int node) const {
str_buf
<<
std
::
setprecision
(
std
::
numeric_limits
<
double
>::
digits10
+
2
);
str_buf
<<
std
::
setprecision
(
std
::
numeric_limits
<
double
>::
digits10
+
2
);
uint8_t
missing_type
=
GetMissingType
(
decision_type_
[
node
]);
uint8_t
missing_type
=
GetMissingType
(
decision_type_
[
node
]);
bool
default_left
=
GetDecisionType
(
decision_type_
[
node
],
kDefaultLeftMask
);
bool
default_left
=
GetDecisionType
(
decision_type_
[
node
],
kDefaultLeftMask
);
if
(
missing_type
=
=
MissingType
::
N
one
if
(
missing_type
!
=
MissingType
::
N
aN
)
{
||
(
missing_type
==
MissingType
::
Zero
&&
default_left
&&
kZeroThreshold
<
threshold_
[
node
]))
{
str_buf
<<
"if (std::isnan(fval)) fval = 0.0;"
;
str_buf
<<
"if (fval <= "
<<
threshold_
[
node
]
<<
") {"
;
}
}
else
if
(
missing_type
==
MissingType
::
Zero
)
{
if
(
missing_type
==
MissingType
::
Zero
)
{
if
(
default_left
)
{
if
(
default_left
)
{
str_buf
<<
"if (
fval <= "
<<
threshold_
[
node
]
<<
" || Tree::IsZero(fval)"
<<
" || std::isnan
(fval)) {"
;
str_buf
<<
"if (
Tree::IsZero
(fval)) {"
;
}
else
{
}
else
{
str_buf
<<
"if (
fval <= "
<<
threshold_
[
node
]
<<
" && !Tree::IsZero(fval)"
<<
" && !std::isnan
(fval)) {"
;
str_buf
<<
"if (
!Tree::IsZero
(fval)) {"
;
}
}
}
else
{
}
else
if
(
missing_type
==
MissingType
::
NaN
)
{
if
(
default_left
)
{
if
(
default_left
)
{
str_buf
<<
"if (
fval <= "
<<
threshold_
[
node
]
<<
" ||
std::isnan(fval)) {"
;
str_buf
<<
"if (std::isnan(fval)) {"
;
}
else
{
}
else
{
str_buf
<<
"if (
fval <= "
<<
threshold_
[
node
]
<<
" &&
!std::isnan(fval)) {"
;
str_buf
<<
"if (!std::isnan(fval)) {"
;
}
}
}
else
{
str_buf
<<
"if (fval <= "
<<
threshold_
[
node
]
<<
") {"
;
}
}
return
str_buf
.
str
();
return
str_buf
.
str
();
}
}
std
::
string
Tree
::
CategoricalDecisionIfElse
(
int
node
)
const
{
std
::
string
Tree
::
CategoricalDecisionIfElse
(
int
node
)
const
{
uint8_t
missing_type
=
GetMissingType
(
decision_type_
[
node
]);
std
::
stringstream
str_buf
;
std
::
stringstream
str_buf
;
Common
::
C_stringstream
(
str_buf
);
Common
::
C_stringstream
(
str_buf
);
if
(
missing_type
==
MissingType
::
NaN
)
{
str_buf
<<
"if (std::isnan(fval)) { int_fval = -1; } else { int_fval = static_cast<int>(fval); }"
;
}
else
{
str_buf
<<
"if (std::isnan(fval)) { int_fval = 0; } else { int_fval = static_cast<int>(fval); }"
;
}
int
cat_idx
=
static_cast
<
int
>
(
threshold_
[
node
]);
int
cat_idx
=
static_cast
<
int
>
(
threshold_
[
node
]);
str_buf
<<
"if (std::isnan(fval)) { int_fval = -1; } else { int_fval = static_cast<int>(fval); }"
;
str_buf
<<
"if (int_fval >= 0 && int_fval < 32 * ("
;
str_buf
<<
"if (int_fval >= 0 && int_fval < 32 * ("
;
str_buf
<<
cat_boundaries_
[
cat_idx
+
1
]
-
cat_boundaries_
[
cat_idx
];
str_buf
<<
cat_boundaries_
[
cat_idx
+
1
]
-
cat_boundaries_
[
cat_idx
];
str_buf
<<
") && (((cat_threshold["
<<
cat_boundaries_
[
cat_idx
];
str_buf
<<
") && (((cat_threshold["
<<
cat_boundaries_
[
cat_idx
];
...
...
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