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
4228bb78
Commit
4228bb78
authored
Feb 26, 2017
by
Guolin Ke
Browse files
output shrinkage for trees (#320)
parent
f4722910
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
3 deletions
+7
-3
include/LightGBM/tree.h
include/LightGBM/tree.h
+2
-0
src/io/tree.cpp
src/io/tree.cpp
+5
-3
No files found.
include/LightGBM/tree.h
View file @
4228bb78
...
...
@@ -104,6 +104,7 @@ public:
for
(
int
i
=
0
;
i
<
num_leaves_
;
++
i
)
{
leaf_value_
[
i
]
*=
rate
;
}
shrinkage_
*=
rate
;
}
/*! \brief Serialize this object to string*/
...
...
@@ -171,6 +172,7 @@ private:
std
::
vector
<
data_size_t
>
internal_count_
;
/*! \brief Depth for leaves */
std
::
vector
<
int
>
leaf_depth_
;
double
shrinkage_
;
};
...
...
src/io/tree.cpp
View file @
4228bb78
...
...
@@ -36,6 +36,7 @@ Tree::Tree(int max_leaves)
leaf_depth_
[
0
]
=
0
;
num_leaves_
=
1
;
leaf_parent_
[
0
]
=
-
1
;
shrinkage_
=
1.0
f
;
}
Tree
::~
Tree
()
{
...
...
@@ -165,6 +166,7 @@ std::string Tree::ToString() {
<<
Common
::
ArrayToString
<
double
>
(
internal_value_
,
num_leaves_
-
1
,
' '
)
<<
std
::
endl
;
str_buf
<<
"internal_count="
<<
Common
::
ArrayToString
<
data_size_t
>
(
internal_count_
,
num_leaves_
-
1
,
' '
)
<<
std
::
endl
;
str_buf
<<
"shrinkage="
<<
shrinkage_
<<
std
::
endl
;
str_buf
<<
std
::
endl
;
return
str_buf
.
str
();
}
...
...
@@ -173,7 +175,7 @@ std::string Tree::ToJSON() {
std
::
stringstream
str_buf
;
str_buf
<<
std
::
setprecision
(
std
::
numeric_limits
<
double
>::
digits10
+
2
);
str_buf
<<
"
\"
num_leaves
\"
:"
<<
num_leaves_
<<
","
<<
std
::
endl
;
str_buf
<<
"
\"
shrinkage
\"
:"
<<
shrinkage_
<<
","
<<
std
::
endl
;
str_buf
<<
"
\"
tree_structure
\"
:"
<<
NodeToJSON
(
0
)
<<
std
::
endl
;
return
str_buf
.
str
();
...
...
@@ -226,7 +228,7 @@ Tree::Tree(const std::string& str) {
||
key_vals
.
count
(
"left_child"
)
<=
0
||
key_vals
.
count
(
"right_child"
)
<=
0
||
key_vals
.
count
(
"leaf_parent"
)
<=
0
||
key_vals
.
count
(
"leaf_value"
)
<=
0
||
key_vals
.
count
(
"internal_value"
)
<=
0
||
key_vals
.
count
(
"internal_count"
)
<=
0
||
key_vals
.
count
(
"leaf_count"
)
<=
0
||
key_vals
.
count
(
"leaf_count"
)
<=
0
||
key_vals
.
count
(
"shrinkage"
)
<=
0
)
{
Log
::
Fatal
(
"Tree model string format error"
);
}
...
...
@@ -244,7 +246,7 @@ Tree::Tree(const std::string& str) {
leaf_count_
=
Common
::
StringToArray
<
data_size_t
>
(
key_vals
[
"leaf_count"
],
' '
,
num_leaves_
);
leaf_parent_
=
Common
::
StringToArray
<
int
>
(
key_vals
[
"leaf_parent"
],
' '
,
num_leaves_
);
leaf_value_
=
Common
::
StringToArray
<
double
>
(
key_vals
[
"leaf_value"
],
' '
,
num_leaves_
);
Common
::
Atof
(
key_vals
[
"shrinkage"
].
c_str
(),
&
shrinkage_
);
}
}
// namespace LightGBM
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