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
664175b3
Commit
664175b3
authored
Nov 04, 2016
by
Guolin Ke
Browse files
merged from master.
parents
eb05bfc1
5172b533
Changes
33
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
50 additions
and
50 deletions
+50
-50
src/io/sparse_bin.hpp
src/io/sparse_bin.hpp
+3
-3
src/io/tree.cpp
src/io/tree.cpp
+8
-8
src/metric/binary_metric.hpp
src/metric/binary_metric.hpp
+1
-1
src/metric/dcg_calculator.cpp
src/metric/dcg_calculator.cpp
+1
-1
src/metric/rank_metric.hpp
src/metric/rank_metric.hpp
+1
-1
src/network/linkers_socket.cpp
src/network/linkers_socket.cpp
+11
-11
src/network/network.cpp
src/network/network.cpp
+1
-1
src/network/socket_wrapper.hpp
src/network/socket_wrapper.hpp
+6
-6
src/objective/binary_objective.hpp
src/objective/binary_objective.hpp
+3
-3
src/objective/multiclass_objective.hpp
src/objective/multiclass_objective.hpp
+8
-8
src/objective/rank_objective.hpp
src/objective/rank_objective.hpp
+2
-2
src/treelearner/serial_tree_learner.cpp
src/treelearner/serial_tree_learner.cpp
+3
-3
src/treelearner/split_info.hpp
src/treelearner/split_info.hpp
+2
-2
No files found.
src/io/sparse_bin.hpp
View file @
664175b3
...
...
@@ -28,7 +28,7 @@ public:
:
num_data_
(
num_data
)
{
default_bin_
=
static_cast
<
VAL_T
>
(
default_bin
);
if
(
default_bin_
!=
0
)
{
Log
::
Info
(
"Warning:
Having
sparse feature with negative values
. Will let
negative values
equal zero as well
"
);
Log
::
Info
(
"Warning: sparse feature with negative values
, treating
negative values
as zero
"
);
}
#pragma omp parallel
#pragma omp master
...
...
@@ -54,7 +54,7 @@ public:
void
ConstructHistogram
(
data_size_t
*
,
data_size_t
,
const
score_t
*
,
const
score_t
*
,
HistogramBinEntry
*
)
const
override
{
// Will use OrderedSparseBin->ConstructHistogram() instead
Log
::
Fatal
(
"
Should use
OrderedSparseBin->ConstructHistogram() instead"
);
Log
::
Fatal
(
"
Using
OrderedSparseBin->ConstructHistogram() instead"
);
}
data_size_t
Split
(
unsigned
int
threshold
,
data_size_t
*
data_indices
,
data_size_t
num_data
,
...
...
@@ -261,7 +261,7 @@ public:
++
i_delta_
;
cur_pos_
+=
bin_data_
->
delta_
[
i_delta_
];
}
if
(
idx
==
cur_pos_
&&
i_delta_
>=
0
if
(
idx
==
cur_pos_
&&
i_delta_
>=
0
&&
i_delta_
<
bin_data_
->
vals_
.
size
())
{
return
bin_data_
->
vals_
[
i_delta_
];
}
else
{
return
0
;
}
...
...
src/io/tree.cpp
View file @
664175b3
...
...
@@ -146,7 +146,7 @@ Tree::Tree(const std::string& str) {
||
key_vals
.
count
(
"split_gain"
)
<=
0
||
key_vals
.
count
(
"threshold"
)
<=
0
||
key_vals
.
count
(
"left_child"
)
<=
0
||
key_vals
.
count
(
"right_child"
)
<=
0
||
key_vals
.
count
(
"leaf_parent"
)
<=
0
||
key_vals
.
count
(
"leaf_value"
)
<=
0
)
{
Log
::
Fatal
(
"
t
ree model string format error"
);
Log
::
Fatal
(
"
T
ree model string format error"
);
}
Common
::
Atoi
(
key_vals
[
"num_leaves"
].
c_str
(),
&
num_leaves_
);
...
...
@@ -164,19 +164,19 @@ Tree::Tree(const std::string& str) {
leaf_depth_
=
nullptr
;
Common
::
StringToIntArray
(
key_vals
[
"split_feature"
],
' '
,
num_leaves_
-
1
,
split_feature_real_
);
num_leaves_
-
1
,
split_feature_real_
);
Common
::
StringToDoubleArray
(
key_vals
[
"split_gain"
],
' '
,
num_leaves_
-
1
,
split_gain_
);
num_leaves_
-
1
,
split_gain_
);
Common
::
StringToDoubleArray
(
key_vals
[
"threshold"
],
' '
,
num_leaves_
-
1
,
threshold_
);
num_leaves_
-
1
,
threshold_
);
Common
::
StringToIntArray
(
key_vals
[
"left_child"
],
' '
,
num_leaves_
-
1
,
left_child_
);
num_leaves_
-
1
,
left_child_
);
Common
::
StringToIntArray
(
key_vals
[
"right_child"
],
' '
,
num_leaves_
-
1
,
right_child_
);
num_leaves_
-
1
,
right_child_
);
Common
::
StringToIntArray
(
key_vals
[
"leaf_parent"
],
' '
,
num_leaves_
,
leaf_parent_
);
num_leaves_
,
leaf_parent_
);
Common
::
StringToDoubleArray
(
key_vals
[
"leaf_value"
],
' '
,
num_leaves_
,
leaf_value_
);
num_leaves_
,
leaf_value_
);
}
}
// namespace LightGBM
src/metric/binary_metric.hpp
View file @
664175b3
...
...
@@ -21,7 +21,7 @@ public:
explicit
BinaryMetric
(
const
MetricConfig
&
config
)
{
sigmoid_
=
static_cast
<
score_t
>
(
config
.
sigmoid
);
if
(
sigmoid_
<=
0.0
f
)
{
Log
::
Fatal
(
"Sigmoid param %f should greater than zero"
,
sigmoid_
);
Log
::
Fatal
(
"Sigmoid param
eter
%f should greater than zero"
,
sigmoid_
);
}
}
...
...
src/metric/dcg_calculator.cpp
View file @
664175b3
...
...
@@ -60,7 +60,7 @@ void DCGCalculator::CalMaxDCG(const std::vector<data_size_t>& ks,
std
::
vector
<
data_size_t
>
label_cnt
(
label_gain_
.
size
(),
0
);
// counts for all labels
for
(
data_size_t
i
=
0
;
i
<
num_data
;
++
i
)
{
if
(
static_cast
<
size_t
>
(
label
[
i
])
>=
label_cnt
.
size
())
{
Log
::
Fatal
(
"
l
abel excel %d"
,
label
[
i
]);
}
if
(
static_cast
<
size_t
>
(
label
[
i
])
>=
label_cnt
.
size
())
{
Log
::
Fatal
(
"
L
abel excel %d"
,
label
[
i
]);
}
++
label_cnt
[
static_cast
<
int
>
(
label
[
i
])];
}
score_t
cur_result
=
0.0
f
;
...
...
src/metric/rank_metric.hpp
View file @
664175b3
...
...
@@ -45,7 +45,7 @@ public:
// get query boundaries
query_boundaries_
=
metadata
.
query_boundaries
();
if
(
query_boundaries_
==
nullptr
)
{
Log
::
Fatal
(
"
For
NDCG metric
, there should be
query information"
);
Log
::
Fatal
(
"
The
NDCG metric
requires
query information"
);
}
num_queries_
=
metadata
.
num_queries
();
// get query weights
...
...
src/network/linkers_socket.cpp
View file @
664175b3
...
...
@@ -44,7 +44,7 @@ Linkers::Linkers(NetworkConfig config) {
}
}
if
(
rank_
==
-
1
)
{
Log
::
Fatal
(
"Machine list file doesn't contain local machine"
);
Log
::
Fatal
(
"Machine list file doesn't contain
the
local machine"
);
}
// construct listener
listener_
=
new
TcpSocket
();
...
...
@@ -53,7 +53,7 @@ Linkers::Linkers(NetworkConfig config) {
for
(
int
i
=
0
;
i
<
num_machines_
;
++
i
)
{
linkers_
.
push_back
(
nullptr
);
}
// construct communication topo
bruck_map_
=
BruckMap
::
Construct
(
rank_
,
num_machines_
);
recursive_halving_map_
=
RecursiveHalvingMap
::
Construct
(
rank_
,
num_machines_
);
...
...
@@ -73,14 +73,14 @@ Linkers::~Linkers() {
}
}
TcpSocket
::
Finalize
();
Log
::
Info
(
"
N
etwork
us
in
g
%f seconds"
,
network_time_
*
1e-3
);
Log
::
Info
(
"
Finished linking n
etwork in %f seconds"
,
network_time_
*
1e-3
);
}
void
Linkers
::
ParseMachineList
(
const
char
*
filename
)
{
TextReader
<
size_t
>
machine_list_reader
(
filename
,
false
);
machine_list_reader
.
ReadAllLines
();
if
(
machine_list_reader
.
Lines
().
size
()
<=
0
)
{
Log
::
Fatal
(
"Machine list file
:
%s doesn't exist"
,
filename
);
Log
::
Fatal
(
"Machine list file
%s doesn't exist"
,
filename
);
}
for
(
auto
&
line
:
machine_list_reader
.
Lines
())
{
...
...
@@ -95,7 +95,7 @@ void Linkers::ParseMachineList(const char * filename) {
continue
;
}
if
(
client_ips_
.
size
()
>=
static_cast
<
size_t
>
(
num_machines_
))
{
Log
::
Warning
(
"
The #machine in
machine_list is larger than parameter num_machines,
the
redundant
will ignored
"
);
Log
::
Warning
(
"machine_list
size
is larger than
the
parameter num_machines,
ignoring
redundant
entries
"
);
break
;
}
str_after_split
[
0
]
=
Common
::
Trim
(
str_after_split
[
0
]);
...
...
@@ -104,17 +104,17 @@ void Linkers::ParseMachineList(const char * filename) {
client_ports_
.
push_back
(
atoi
(
str_after_split
[
1
].
c_str
()));
}
if
(
client_ips_
.
size
()
!=
static_cast
<
size_t
>
(
num_machines_
))
{
Log
::
Warning
(
"
The w
orld size is
big
ger th
e #machine in
machine
list, change world size to %d
.
"
,
client_ips_
.
size
());
Log
::
Warning
(
"
W
orld size is
lar
ger th
an the
machine
_
list
size
, change world size to %d"
,
client_ips_
.
size
());
num_machines_
=
static_cast
<
int
>
(
client_ips_
.
size
());
}
}
void
Linkers
::
TryBind
(
int
port
)
{
Log
::
Info
(
"
t
ry to bind port %d."
,
port
);
Log
::
Info
(
"
T
ry
ing
to bind port %d.
..
"
,
port
);
if
(
listener_
->
Bind
(
port
))
{
Log
::
Info
(
"Binding port %d succe
ss.
"
,
port
);
Log
::
Info
(
"Binding port %d succe
eded
"
,
port
);
}
else
{
Log
::
Fatal
(
"Binding port %d failed
.
"
,
port
);
Log
::
Fatal
(
"Binding port %d failed"
,
port
);
}
}
...
...
@@ -192,7 +192,7 @@ void Linkers::Construct() {
if
(
cur_socket
.
Connect
(
client_ips_
[
out_rank
].
c_str
(),
client_ports_
[
out_rank
]))
{
break
;
}
else
{
Log
::
Warning
(
"Connect to rank %d failed, wait for %d milliseconds"
,
out_rank
,
connect_fail_delay_time
);
Log
::
Warning
(
"Connect
ing
to rank %d failed, wait
ing
for %d milliseconds"
,
out_rank
,
connect_fail_delay_time
);
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
connect_fail_delay_time
));
}
}
...
...
@@ -217,7 +217,7 @@ bool Linkers::CheckLinker(int rank) {
void
Linkers
::
PrintLinkers
()
{
for
(
int
i
=
0
;
i
<
num_machines_
;
++
i
)
{
if
(
CheckLinker
(
i
))
{
Log
::
Info
(
"Connected to rank %d
.
"
,
i
);
Log
::
Info
(
"Connected to rank %d"
,
i
);
}
}
}
...
...
src/network/network.cpp
View file @
664175b3
...
...
@@ -30,7 +30,7 @@ void Network::Init(NetworkConfig config) {
block_len_
=
new
int
[
num_machines_
];
buffer_size_
=
1024
*
1024
;
buffer_
=
new
char
[
buffer_size_
];
Log
::
Info
(
"
l
ocal rank %d, total number of machines %d"
,
rank_
,
num_machines_
);
Log
::
Info
(
"
L
ocal rank
:
%d, total number of machines
:
%d"
,
rank_
,
num_machines_
);
}
void
Network
::
Dispose
()
{
...
...
src/network/socket_wrapper.hpp
View file @
664175b3
...
...
@@ -60,7 +60,7 @@ public:
TcpSocket
()
{
sockfd_
=
socket
(
AF_INET
,
SOCK_STREAM
,
IPPROTO_TCP
);
if
(
sockfd_
==
INVALID_SOCKET
)
{
Log
::
Fatal
(
"Socket construct error"
);
Log
::
Fatal
(
"Socket construct
ion
error"
);
return
;
}
ConfigSocket
();
...
...
@@ -97,7 +97,7 @@ public:
#if defined(_WIN32)
WSADATA
wsa_data
;
if
(
WSAStartup
(
MAKEWORD
(
2
,
2
),
&
wsa_data
)
==
-
1
)
{
Log
::
Fatal
(
"Socket error: WSAStart
up error"
);
Log
::
Fatal
(
"Socket error: WSAStartup error"
);
}
if
(
LOBYTE
(
wsa_data
.
wVersion
)
!=
2
||
HIBYTE
(
wsa_data
.
wVersion
)
!=
2
)
{
WSACleanup
();
...
...
@@ -128,7 +128,7 @@ public:
char
buffer
[
512
];
// get hostName
if
(
gethostname
(
buffer
,
sizeof
(
buffer
))
==
SOCKET_ERROR
)
{
Log
::
Fatal
(
"Error code
:
%d, when getting local host name
.
"
,
WSAGetLastError
());
Log
::
Fatal
(
"Error code %d, when getting local host name"
,
WSAGetLastError
());
}
// push local ip
PIP_ADAPTER_INFO
pAdapterInfo
;
...
...
@@ -137,7 +137,7 @@ public:
ULONG
ulOutBufLen
=
sizeof
(
IP_ADAPTER_INFO
);
pAdapterInfo
=
(
IP_ADAPTER_INFO
*
)
MALLOC
(
sizeof
(
IP_ADAPTER_INFO
));
if
(
pAdapterInfo
==
NULL
)
{
Log
::
Fatal
(
"GetAdaptersinfo error: allocating memory
"
);
Log
::
Fatal
(
"GetAdaptersinfo error: allocating memory"
);
}
// Make an initial call to GetAdaptersInfo to get
// the necessary size into the ulOutBufLen variable
...
...
@@ -145,7 +145,7 @@ public:
FREE
(
pAdapterInfo
);
pAdapterInfo
=
(
IP_ADAPTER_INFO
*
)
MALLOC
(
ulOutBufLen
);
if
(
pAdapterInfo
==
NULL
)
{
Log
::
Fatal
(
"GetAdaptersinfo error: allocating memory
"
);
Log
::
Fatal
(
"GetAdaptersinfo error: allocating memory"
);
}
}
if
((
dwRetVal
=
GetAdaptersInfo
(
pAdapterInfo
,
&
ulOutBufLen
))
==
NO_ERROR
)
{
...
...
@@ -155,7 +155,7 @@ public:
pAdapter
=
pAdapter
->
Next
;
}
}
else
{
Log
::
Fatal
(
"GetAdaptersinfo error: code %d
"
,
dwRetVal
);
Log
::
Fatal
(
"GetAdaptersinfo error: code %d"
,
dwRetVal
);
}
if
(
pAdapterInfo
)
FREE
(
pAdapterInfo
);
...
...
src/objective/binary_objective.hpp
View file @
664175b3
...
...
@@ -16,7 +16,7 @@ public:
is_unbalance_
=
config
.
is_unbalance
;
sigmoid_
=
static_cast
<
score_t
>
(
config
.
sigmoid
);
if
(
sigmoid_
<=
0.0
)
{
Log
::
Fatal
(
"Sigmoid parameter %f
:
should greater than zero"
,
sigmoid_
);
Log
::
Fatal
(
"Sigmoid parameter %f should
be
greater than zero"
,
sigmoid_
);
}
}
~
BinaryLogloss
()
{}
...
...
@@ -34,10 +34,10 @@ public:
++
cnt_negative
;
}
}
Log
::
Info
(
"Number of postive:%d,
number of negative:%d"
,
cnt_positive
,
cnt_negative
);
Log
::
Info
(
"Number of postive:
%d, number of negative:
%d"
,
cnt_positive
,
cnt_negative
);
// cannot continue if all sample are same class
if
(
cnt_positive
==
0
||
cnt_negative
==
0
)
{
Log
::
Fatal
(
"
Input t
raining data only contains one class"
);
Log
::
Fatal
(
"
T
raining data only contains one class"
);
}
// use -1 for negative class, and 1 for positive class
label_val_
[
0
]
=
-
1
;
...
...
src/objective/multiclass_objective.hpp
View file @
664175b3
...
...
@@ -16,20 +16,20 @@ public:
:
label_int_
(
nullptr
)
{
num_class_
=
config
.
num_class
;
}
~
MulticlassLogloss
()
{
if
(
label_int_
!=
nullptr
)
{
delete
[]
label_int_
;
}
if
(
label_int_
!=
nullptr
)
{
delete
[]
label_int_
;
}
}
void
Init
(
const
Metadata
&
metadata
,
data_size_t
num_data
)
override
{
num_data_
=
num_data
;
label_
=
metadata
.
label
();
weights_
=
metadata
.
weights
();
label_int_
=
new
int
[
num_data_
];
for
(
int
i
=
0
;
i
<
num_data_
;
++
i
){
label_int_
[
i
]
=
static_cast
<
int
>
(
label_
[
i
]);
label_int_
[
i
]
=
static_cast
<
int
>
(
label_
[
i
]);
if
(
label_int_
[
i
]
<
0
||
label_int_
[
i
]
>=
num_class_
)
{
Log
::
Fatal
(
"Label must be in [0, %d), but f
i
nd %d in label"
,
num_class_
,
label_int_
[
i
]);
Log
::
Fatal
(
"Label must be in [0, %d), but f
ou
nd %d in label"
,
num_class_
,
label_int_
[
i
]);
}
}
}
...
...
@@ -42,7 +42,7 @@ public:
for
(
int
k
=
0
;
k
<
num_class_
;
++
k
){
rec
[
k
]
=
static_cast
<
double
>
(
score
[
k
*
num_data_
+
i
]);
}
Common
::
Softmax
(
&
rec
);
Common
::
Softmax
(
&
rec
);
for
(
int
k
=
0
;
k
<
num_class_
;
++
k
)
{
score_t
p
=
static_cast
<
score_t
>
(
rec
[
k
]);
if
(
label_int_
[
i
]
==
k
)
{
...
...
@@ -51,7 +51,7 @@ public:
gradients
[
k
*
num_data_
+
i
]
=
p
;
}
hessians
[
k
*
num_data_
+
i
]
=
2.0
f
*
p
*
(
1.0
f
-
p
);
}
}
}
}
else
{
#pragma omp parallel for schedule(static)
...
...
@@ -59,7 +59,7 @@ public:
std
::
vector
<
double
>
rec
(
num_class_
);
for
(
int
k
=
0
;
k
<
num_class_
;
++
k
){
rec
[
k
]
=
static_cast
<
double
>
(
score
[
k
*
num_data_
+
i
]);
}
}
Common
::
Softmax
(
&
rec
);
for
(
int
k
=
0
;
k
<
num_class_
;
++
k
)
{
score_t
p
=
static_cast
<
score_t
>
(
rec
[
k
]);
...
...
src/objective/rank_objective.hpp
View file @
664175b3
...
...
@@ -31,7 +31,7 @@ public:
optimize_pos_at_
=
config
.
max_position
;
sigmoid_table_
=
nullptr
;
if
(
sigmoid_
<=
0.0
)
{
Log
::
Fatal
(
"
s
igmoid param %f should greater than zero"
,
sigmoid_
);
Log
::
Fatal
(
"
S
igmoid param %f should
be
greater than zero"
,
sigmoid_
);
}
}
~
LambdarankNDCG
()
{
...
...
@@ -47,7 +47,7 @@ public:
// get boundries
query_boundaries_
=
metadata
.
query_boundaries
();
if
(
query_boundaries_
==
nullptr
)
{
Log
::
Fatal
(
"
For l
ambdarank tasks
, should hav
e query information"
);
Log
::
Fatal
(
"
L
ambdarank tasks
requir
e query information"
);
}
num_queries_
=
metadata
.
num_queries
();
// cache inverse max DCG, avoid computation many times
...
...
src/treelearner/serial_tree_learner.cpp
View file @
664175b3
...
...
@@ -112,7 +112,7 @@ void SerialTreeLearner::Init(const Dataset* train_data) {
if
(
has_ordered_bin_
)
{
is_data_in_leaf_
=
new
char
[
num_data_
];
}
Log
::
Info
(
"Number of data:%d,
N
umber of features:%d"
,
num_data_
,
num_features_
);
Log
::
Info
(
"Number of data:
%d,
n
umber of features:
%d"
,
num_data_
,
num_features_
);
}
...
...
@@ -142,7 +142,7 @@ Tree* SerialTreeLearner::Train(const score_t* gradients, const score_t *hessians
const
SplitInfo
&
best_leaf_SplitInfo
=
best_split_per_leaf_
[
best_leaf
];
// cannot split, quit
if
(
best_leaf_SplitInfo
.
gain
<=
0.0
)
{
Log
::
Info
(
"
cannot find more
split with
gain =
%f
,
current #
leaves
=
%d"
,
Log
::
Info
(
"
No further
split
s
with
positive gain, best gain:
%f, leaves
:
%d"
,
best_leaf_SplitInfo
.
gain
,
split
+
1
);
break
;
}
...
...
@@ -266,7 +266,7 @@ bool SerialTreeLearner::BeforeFindBestSplit(int left_leaf, int right_leaf) {
if
(
right_leaf
<
0
)
{
histogram_pool_
.
Get
(
left_leaf
,
&
smaller_leaf_histogram_array_
);
larger_leaf_histogram_array_
=
nullptr
;
}
else
if
(
num_data_in_left_child
<
num_data_in_right_child
)
{
smaller_leaf
=
left_leaf
;
larger_leaf
=
right_leaf
;
...
...
src/treelearner/split_info.hpp
View file @
664175b3
...
...
@@ -40,13 +40,13 @@ public:
double
right_sum_hessian
;
SplitInfo
()
{
// initilize with -1 and -inf gain
// initi
a
lize with -1 and -inf gain
feature
=
-
1
;
gain
=
kMinScore
;
}
inline
void
Reset
()
{
// initilize with -1 and -inf gain
// initi
a
lize with -1 and -inf gain
feature
=
-
1
;
gain
=
kMinScore
;
}
...
...
Prev
1
2
Next
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