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
3d65d065
"tests/git@developer.sourcefind.cn:tianlh/lightgbm-dcu.git" did not exist on "f85dfa2c402cc42e3ecf1a960d84a9ceeac908c7"
Commit
3d65d065
authored
Nov 15, 2017
by
Guolin Ke
Browse files
fix some formats
parent
ba5c7459
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
67 additions
and
70 deletions
+67
-70
include/LightGBM/boosting.h
include/LightGBM/boosting.h
+5
-5
include/LightGBM/tree.h
include/LightGBM/tree.h
+4
-4
src/application/predictor.hpp
src/application/predictor.hpp
+13
-14
src/boosting/gbdt.cpp
src/boosting/gbdt.cpp
+11
-11
src/boosting/gbdt.h
src/boosting/gbdt.h
+6
-6
src/boosting/gbdt_model_text.cpp
src/boosting/gbdt_model_text.cpp
+8
-8
src/io/tree.cpp
src/io/tree.cpp
+20
-22
No files found.
include/LightGBM/boosting.h
View file @
3d65d065
include/LightGBM/tree.h
View file @
3d65d065
...
@@ -478,8 +478,8 @@ inline void Tree::PredictContrib(const double* feature_values, int num_features,
...
@@ -478,8 +478,8 @@ inline void Tree::PredictContrib(const double* feature_values, int num_features,
output
[
num_features
]
+=
ExpectedValue
();
output
[
num_features
]
+=
ExpectedValue
();
// Run the recursion with preallocated space for the unique path data
// Run the recursion with preallocated space for the unique path data
if
(
num_leaves_
>
1
)
{
if
(
num_leaves_
>
1
)
{
const
int
max_path_len
=
MaxDepth
()
+
1
;
const
int
max_path_len
=
MaxDepth
()
+
1
;
PathElement
*
unique_path_data
=
new
PathElement
[(
max_path_len
*
(
max_path_len
+
1
))
/
2
];
PathElement
*
unique_path_data
=
new
PathElement
[(
max_path_len
*
(
max_path_len
+
1
))
/
2
];
TreeSHAP
(
feature_values
,
output
,
0
,
0
,
unique_path_data
,
1
,
1
,
-
1
);
TreeSHAP
(
feature_values
,
output
,
0
,
0
,
unique_path_data
,
1
,
1
,
-
1
);
delete
[]
unique_path_data
;
delete
[]
unique_path_data
;
}
}
...
@@ -490,8 +490,8 @@ inline void Tree::RecomputeLeafDepths(int node, int depth) {
...
@@ -490,8 +490,8 @@ inline void Tree::RecomputeLeafDepths(int node, int depth) {
if
(
node
<
0
)
{
if
(
node
<
0
)
{
leaf_depth_
[
~
node
]
=
depth
;
leaf_depth_
[
~
node
]
=
depth
;
}
else
{
}
else
{
RecomputeLeafDepths
(
left_child_
[
node
],
depth
+
1
);
RecomputeLeafDepths
(
left_child_
[
node
],
depth
+
1
);
RecomputeLeafDepths
(
right_child_
[
node
],
depth
+
1
);
RecomputeLeafDepths
(
right_child_
[
node
],
depth
+
1
);
}
}
}
}
...
...
src/application/predictor.hpp
View file @
3d65d065
...
@@ -65,7 +65,7 @@ public:
...
@@ -65,7 +65,7 @@ public:
if
(
is_predict_leaf_index
)
{
if
(
is_predict_leaf_index
)
{
predict_fun_
=
[
this
](
const
std
::
vector
<
std
::
pair
<
int
,
double
>>&
features
,
double
*
output
)
{
predict_fun_
=
[
this
](
const
std
::
vector
<
std
::
pair
<
int
,
double
>>&
features
,
double
*
output
)
{
int
tid
=
omp_get_thread_num
();
int
tid
=
omp_get_thread_num
();
if
(
num_feature_
>
MAX_FEATURE
&&
num_feature_
/
static_cast
<
int
>
(
features
.
size
())
>
SPARSITY
)
{
if
(
num_feature_
>
MAX_FEATURE
&&
num_feature_
/
static_cast
<
int
>
(
features
.
size
())
>
SPARSITY
)
{
CopyToPredictMap
(
tid
,
features
);
CopyToPredictMap
(
tid
,
features
);
boosting_
->
PredictLeafIndexByMap
(
predict_buf_map_
[
tid
],
output
);
boosting_
->
PredictLeafIndexByMap
(
predict_buf_map_
[
tid
],
output
);
ClearPredictMap
(
tid
);
ClearPredictMap
(
tid
);
...
@@ -88,7 +88,7 @@ public:
...
@@ -88,7 +88,7 @@ public:
if
(
is_raw_score
)
{
if
(
is_raw_score
)
{
predict_fun_
=
[
this
](
const
std
::
vector
<
std
::
pair
<
int
,
double
>>&
features
,
double
*
output
)
{
predict_fun_
=
[
this
](
const
std
::
vector
<
std
::
pair
<
int
,
double
>>&
features
,
double
*
output
)
{
int
tid
=
omp_get_thread_num
();
int
tid
=
omp_get_thread_num
();
if
(
num_feature_
>
MAX_FEATURE
&&
num_feature_
/
static_cast
<
int
>
(
features
.
size
())
>
SPARSITY
)
{
if
(
num_feature_
>
MAX_FEATURE
&&
num_feature_
/
static_cast
<
int
>
(
features
.
size
())
>
SPARSITY
)
{
CopyToPredictMap
(
tid
,
features
);
CopyToPredictMap
(
tid
,
features
);
boosting_
->
PredictRawByMap
(
predict_buf_map_
[
tid
],
output
,
&
early_stop_
);
boosting_
->
PredictRawByMap
(
predict_buf_map_
[
tid
],
output
,
&
early_stop_
);
ClearPredictMap
(
tid
);
ClearPredictMap
(
tid
);
...
@@ -101,7 +101,7 @@ public:
...
@@ -101,7 +101,7 @@ public:
}
else
{
}
else
{
predict_fun_
=
[
this
](
const
std
::
vector
<
std
::
pair
<
int
,
double
>>&
features
,
double
*
output
)
{
predict_fun_
=
[
this
](
const
std
::
vector
<
std
::
pair
<
int
,
double
>>&
features
,
double
*
output
)
{
int
tid
=
omp_get_thread_num
();
int
tid
=
omp_get_thread_num
();
if
(
num_feature_
>
MAX_FEATURE
&&
num_feature_
/
static_cast
<
int
>
(
features
.
size
())
>
SPARSITY
)
{
if
(
num_feature_
>
MAX_FEATURE
&&
num_feature_
/
static_cast
<
int
>
(
features
.
size
())
>
SPARSITY
)
{
CopyToPredictMap
(
tid
,
features
);
CopyToPredictMap
(
tid
,
features
);
boosting_
->
PredictByMap
(
predict_buf_map_
[
tid
],
output
,
&
early_stop_
);
boosting_
->
PredictByMap
(
predict_buf_map_
[
tid
],
output
,
&
early_stop_
);
ClearPredictMap
(
tid
);
ClearPredictMap
(
tid
);
...
@@ -151,20 +151,20 @@ public:
...
@@ -151,20 +151,20 @@ public:
TextReader
<
data_size_t
>
predict_data_reader
(
data_filename
,
has_header
);
TextReader
<
data_size_t
>
predict_data_reader
(
data_filename
,
has_header
);
std
::
unordered_map
<
int
,
int
>
feature_names_map_
;
std
::
unordered_map
<
int
,
int
>
feature_names_map_
;
bool
need_adjust
=
false
;
bool
need_adjust
=
false
;
if
(
has_header
)
{
if
(
has_header
)
{
std
::
string
first_line
=
predict_data_reader
.
first_line
();
std
::
string
first_line
=
predict_data_reader
.
first_line
();
std
::
vector
<
std
::
string
>
header
=
Common
::
Split
(
first_line
.
c_str
(),
"
\t
,"
);
std
::
vector
<
std
::
string
>
header
=
Common
::
Split
(
first_line
.
c_str
(),
"
\t
,"
);
header
.
erase
(
header
.
begin
()
+
boosting_
->
LabelIdx
());
header
.
erase
(
header
.
begin
()
+
boosting_
->
LabelIdx
());
for
(
int
i
=
0
;
i
<
static_cast
<
int
>
(
header
.
size
());
++
i
)
{
for
(
int
i
=
0
;
i
<
static_cast
<
int
>
(
header
.
size
());
++
i
)
{
for
(
int
j
=
0
;
j
<
static_cast
<
int
>
(
boosting_
->
FeatureNames
().
size
());
++
j
)
{
for
(
int
j
=
0
;
j
<
static_cast
<
int
>
(
boosting_
->
FeatureNames
().
size
());
++
j
)
{
if
(
header
[
i
]
==
boosting_
->
FeatureNames
()[
j
])
{
if
(
header
[
i
]
==
boosting_
->
FeatureNames
()[
j
])
{
feature_names_map_
[
i
]
=
j
;
feature_names_map_
[
i
]
=
j
;
break
;
break
;
}
}
}
}
}
}
for
(
auto
s
:
feature_names_map_
)
{
for
(
auto
s
:
feature_names_map_
)
{
if
(
s
.
first
!=
s
.
second
)
{
if
(
s
.
first
!=
s
.
second
)
{
need_adjust
=
true
;
need_adjust
=
true
;
break
;
break
;
}
}
...
@@ -176,14 +176,13 @@ public:
...
@@ -176,14 +176,13 @@ public:
parser_fun
=
[
this
,
&
parser
,
&
tmp_label
,
&
need_adjust
,
&
feature_names_map_
]
parser_fun
=
[
this
,
&
parser
,
&
tmp_label
,
&
need_adjust
,
&
feature_names_map_
]
(
const
char
*
buffer
,
std
::
vector
<
std
::
pair
<
int
,
double
>>*
feature
)
{
(
const
char
*
buffer
,
std
::
vector
<
std
::
pair
<
int
,
double
>>*
feature
)
{
parser
->
ParseOneLine
(
buffer
,
feature
,
&
tmp_label
);
parser
->
ParseOneLine
(
buffer
,
feature
,
&
tmp_label
);
if
(
need_adjust
)
{
if
(
need_adjust
)
{
int
i
=
0
,
j
=
static_cast
<
int
>
(
feature
->
size
());
int
i
=
0
,
j
=
static_cast
<
int
>
(
feature
->
size
());
while
(
i
<
j
)
{
while
(
i
<
j
)
{
if
(
feature_names_map_
.
find
((
*
feature
)[
i
].
first
)
!=
feature_names_map_
.
end
())
{
if
(
feature_names_map_
.
find
((
*
feature
)[
i
].
first
)
!=
feature_names_map_
.
end
())
{
(
*
feature
)[
i
].
first
=
feature_names_map_
[(
*
feature
)[
i
].
first
];
(
*
feature
)[
i
].
first
=
feature_names_map_
[(
*
feature
)[
i
].
first
];
++
i
;
++
i
;
}
}
else
{
else
{
//move the non-used features to the end of the feature vector
//move the non-used features to the end of the feature vector
std
::
swap
((
*
feature
)[
i
],
(
*
feature
)[
--
j
]);
std
::
swap
((
*
feature
)[
i
],
(
*
feature
)[
--
j
]);
}
}
...
...
src/boosting/gbdt.cpp
View file @
3d65d065
...
@@ -30,16 +30,16 @@ std::chrono::duration<double, std::milli> tree_time;
...
@@ -30,16 +30,16 @@ std::chrono::duration<double, std::milli> tree_time;
#endif // TIMETAG
#endif // TIMETAG
GBDT
::
GBDT
()
:
iter_
(
0
),
GBDT
::
GBDT
()
:
iter_
(
0
),
train_data_
(
nullptr
),
train_data_
(
nullptr
),
objective_function_
(
nullptr
),
objective_function_
(
nullptr
),
early_stopping_round_
(
0
),
early_stopping_round_
(
0
),
max_feature_idx_
(
0
),
max_feature_idx_
(
0
),
num_tree_per_iteration_
(
1
),
num_tree_per_iteration_
(
1
),
num_class_
(
1
),
num_class_
(
1
),
num_iteration_for_pred_
(
0
),
num_iteration_for_pred_
(
0
),
shrinkage_rate_
(
0.1
f
),
shrinkage_rate_
(
0.1
f
),
num_init_iteration_
(
0
),
num_init_iteration_
(
0
),
need_re_bagging_
(
false
)
{
need_re_bagging_
(
false
)
{
#pragma omp parallel
#pragma omp parallel
#pragma omp master
#pragma omp master
...
...
src/boosting/gbdt.h
View file @
3d65d065
...
@@ -20,7 +20,7 @@ namespace LightGBM {
...
@@ -20,7 +20,7 @@ namespace LightGBM {
/*!
/*!
* \brief GBDT algorithm implementation. including Training, prediction, bagging.
* \brief GBDT algorithm implementation. including Training, prediction, bagging.
*/
*/
class
GBDT
:
public
GBDTBase
{
class
GBDT
:
public
GBDTBase
{
public:
public:
/*!
/*!
...
...
src/boosting/gbdt_model_text.cpp
View file @
3d65d065
src/io/tree.cpp
View file @
3d65d065
...
@@ -382,15 +382,13 @@ std::string Tree::ToIfElse(int index, bool is_predict_leaf_index) const {
...
@@ -382,15 +382,13 @@ std::string Tree::ToIfElse(int index, bool is_predict_leaf_index) const {
str_buf
<<
"double PredictTree"
<<
index
;
str_buf
<<
"double PredictTree"
<<
index
;
if
(
is_predict_leaf_index
)
{
if
(
is_predict_leaf_index
)
{
str_buf
<<
"LeafByMap"
;
str_buf
<<
"LeafByMap"
;
}
}
else
{
else
{
str_buf
<<
"ByMap"
;
str_buf
<<
"ByMap"
;
}
}
str_buf
<<
"(const std::unordered_map<int, double>& arr) { "
;
str_buf
<<
"(const std::unordered_map<int, double>& arr) { "
;
if
(
num_leaves_
<=
1
)
{
if
(
num_leaves_
<=
1
)
{
str_buf
<<
"return "
<<
leaf_value_
[
0
]
<<
";"
;
str_buf
<<
"return "
<<
leaf_value_
[
0
]
<<
";"
;
}
}
else
{
else
{
str_buf
<<
"const std::vector<uint32_t> cat_threshold = {"
;
str_buf
<<
"const std::vector<uint32_t> cat_threshold = {"
;
for
(
size_t
i
=
0
;
i
<
cat_threshold_
.
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
cat_threshold_
.
size
();
++
i
)
{
if
(
i
!=
0
)
{
if
(
i
!=
0
)
{
...
@@ -696,7 +694,7 @@ double Tree::ExpectedValue() const {
...
@@ -696,7 +694,7 @@ double Tree::ExpectedValue() const {
const
double
total_count
=
internal_count_
[
0
];
const
double
total_count
=
internal_count_
[
0
];
double
exp_value
=
0.0
;
double
exp_value
=
0.0
;
for
(
int
i
=
0
;
i
<
num_leaves
();
++
i
)
{
for
(
int
i
=
0
;
i
<
num_leaves
();
++
i
)
{
exp_value
+=
(
leaf_count_
[
i
]
/
total_count
)
*
LeafOutput
(
i
);
exp_value
+=
(
leaf_count_
[
i
]
/
total_count
)
*
LeafOutput
(
i
);
}
}
return
exp_value
;
return
exp_value
;
}
}
...
...
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