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
6f7669df
Commit
6f7669df
authored
Dec 06, 2016
by
Guolin Ke
Browse files
fix bug in save model
parent
53bae396
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
12 deletions
+26
-12
include/LightGBM/utils/common.h
include/LightGBM/utils/common.h
+15
-1
src/io/tree.cpp
src/io/tree.cpp
+11
-11
No files found.
include/LightGBM/utils/common.h
View file @
6f7669df
...
...
@@ -254,11 +254,25 @@ inline static std::string ArrayToString(const std::vector<T>& arr, char delimite
return
str_buf
.
str
();
}
template
<
typename
T
>
inline
static
std
::
string
ArrayToString
(
const
std
::
vector
<
T
>&
arr
,
size_t
n
,
char
delimiter
)
{
if
(
arr
.
empty
()
||
n
==
0
)
{
return
std
::
string
(
""
);
}
std
::
stringstream
str_buf
;
str_buf
<<
arr
[
0
];
for
(
size_t
i
=
1
;
i
<
std
::
min
(
n
,
arr
.
size
());
++
i
)
{
str_buf
<<
delimiter
;
str_buf
<<
arr
[
i
];
}
return
str_buf
.
str
();
}
template
<
typename
T
>
inline
static
std
::
vector
<
T
>
StringToArray
(
const
std
::
string
&
str
,
char
delimiter
,
size_t
n
)
{
std
::
vector
<
std
::
string
>
strs
=
Split
(
str
.
c_str
(),
delimiter
);
if
(
strs
.
size
()
!=
n
)
{
Log
::
Fatal
(
"StringTo
Int
Array error, size doesn't match."
);
Log
::
Fatal
(
"StringToArray error, size doesn't match."
);
}
std
::
vector
<
T
>
ret
(
n
);
if
(
std
::
is_same
<
T
,
float
>::
value
||
std
::
is_same
<
T
,
double
>::
value
)
{
...
...
src/io/tree.cpp
View file @
6f7669df
...
...
@@ -124,27 +124,27 @@ std::string Tree::ToString() {
std
::
stringstream
ss
;
ss
<<
"num_leaves="
<<
num_leaves_
<<
std
::
endl
;
ss
<<
"split_feature="
<<
Common
::
ArrayToString
<
int
>
(
split_feature_real_
,
' '
)
<<
std
::
endl
;
<<
Common
::
ArrayToString
<
int
>
(
split_feature_real_
,
num_leaves_
-
1
,
' '
)
<<
std
::
endl
;
ss
<<
"split_gain="
<<
Common
::
ArrayToString
<
double
>
(
split_gain_
,
' '
)
<<
std
::
endl
;
<<
Common
::
ArrayToString
<
double
>
(
split_gain_
,
num_leaves_
-
1
,
' '
)
<<
std
::
endl
;
ss
<<
"threshold="
<<
Common
::
ArrayToString
<
double
>
(
threshold_
,
' '
)
<<
std
::
endl
;
<<
Common
::
ArrayToString
<
double
>
(
threshold_
,
num_leaves_
-
1
,
' '
)
<<
std
::
endl
;
ss
<<
"decision_type="
<<
Common
::
ArrayToString
<
int
>
(
Common
::
ArrayCast
<
int8_t
,
int
>
(
decision_type_
),
' '
)
<<
std
::
endl
;
<<
Common
::
ArrayToString
<
int
>
(
Common
::
ArrayCast
<
int8_t
,
int
>
(
decision_type_
),
num_leaves_
-
1
,
' '
)
<<
std
::
endl
;
ss
<<
"left_child="
<<
Common
::
ArrayToString
<
int
>
(
left_child_
,
' '
)
<<
std
::
endl
;
<<
Common
::
ArrayToString
<
int
>
(
left_child_
,
num_leaves_
-
1
,
' '
)
<<
std
::
endl
;
ss
<<
"right_child="
<<
Common
::
ArrayToString
<
int
>
(
right_child_
,
' '
)
<<
std
::
endl
;
<<
Common
::
ArrayToString
<
int
>
(
right_child_
,
num_leaves_
-
1
,
' '
)
<<
std
::
endl
;
ss
<<
"leaf_parent="
<<
Common
::
ArrayToString
<
int
>
(
leaf_parent_
,
' '
)
<<
std
::
endl
;
<<
Common
::
ArrayToString
<
int
>
(
leaf_parent_
,
num_leaves_
,
' '
)
<<
std
::
endl
;
ss
<<
"leaf_value="
<<
Common
::
ArrayToString
<
double
>
(
leaf_value_
,
' '
)
<<
std
::
endl
;
<<
Common
::
ArrayToString
<
double
>
(
leaf_value_
,
num_leaves_
,
' '
)
<<
std
::
endl
;
ss
<<
"leaf_count="
<<
Common
::
ArrayToString
<
data_size_t
>
(
leaf_count_
,
' '
)
<<
std
::
endl
;
<<
Common
::
ArrayToString
<
data_size_t
>
(
leaf_count_
,
num_leaves_
,
' '
)
<<
std
::
endl
;
ss
<<
"internal_value="
<<
Common
::
ArrayToString
<
double
>
(
internal_value_
,
' '
)
<<
std
::
endl
;
<<
Common
::
ArrayToString
<
double
>
(
internal_value_
,
num_leaves_
-
1
,
' '
)
<<
std
::
endl
;
ss
<<
"internal_count="
<<
Common
::
ArrayToString
<
data_size_t
>
(
internal_count_
,
' '
)
<<
std
::
endl
;
<<
Common
::
ArrayToString
<
data_size_t
>
(
internal_count_
,
num_leaves_
-
1
,
' '
)
<<
std
::
endl
;
ss
<<
std
::
endl
;
return
ss
.
str
();
}
...
...
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