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
0a7a4080
Commit
0a7a4080
authored
Dec 12, 2017
by
Guolin Ke
Browse files
change kZeroThreshold to 1e-35f
parent
0481762e
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
17 additions
and
17 deletions
+17
-17
include/LightGBM/meta.h
include/LightGBM/meta.h
+1
-1
include/LightGBM/tree.h
include/LightGBM/tree.h
+1
-1
src/c_api.cpp
src/c_api.cpp
+5
-5
src/io/bin.cpp
src/io/bin.cpp
+6
-6
src/io/dataset_loader.cpp
src/io/dataset_loader.cpp
+1
-1
src/io/parser.hpp
src/io/parser.hpp
+2
-2
src/io/tree.cpp
src/io/tree.cpp
+1
-1
No files found.
include/LightGBM/meta.h
View file @
0a7a4080
...
...
@@ -19,7 +19,7 @@ const score_t kMinScore = -std::numeric_limits<score_t>::infinity();
const
score_t
kEpsilon
=
1e-15
f
;
const
double
kZero
AsMissingValueRange
=
1e-
20
f
;
const
double
kZero
Threshold
=
1e-
35
f
;
using
ReduceFunction
=
std
::
function
<
void
(
const
char
*
,
char
*
,
int
)
>
;
...
...
include/LightGBM/tree.h
View file @
0a7a4080
...
...
@@ -171,7 +171,7 @@ public:
std
::
string
ToIfElse
(
int
index
,
bool
is_predict_leaf_index
)
const
;
inline
static
bool
IsZero
(
double
fval
)
{
if
(
fval
>
-
kZero
AsMissingValueRange
&&
fval
<=
kZeroAsMissingValueRange
)
{
if
(
fval
>
-
kZero
Threshold
&&
fval
<=
kZeroThreshold
)
{
return
true
;
}
else
{
return
false
;
...
...
src/c_api.cpp
View file @
0a7a4080
...
...
@@ -496,7 +496,7 @@ int LGBM_DatasetCreateFromMat(const void* data,
auto
idx
=
sample_indices
[
i
];
auto
row
=
get_row_fun
(
static_cast
<
int
>
(
idx
));
for
(
size_t
j
=
0
;
j
<
row
.
size
();
++
j
)
{
if
(
std
::
fabs
(
row
[
j
])
>
k
Epsilon
||
std
::
isnan
(
row
[
j
]))
{
if
(
std
::
fabs
(
row
[
j
])
>
k
ZeroThreshold
||
std
::
isnan
(
row
[
j
]))
{
sample_values
[
j
].
emplace_back
(
row
[
j
]);
sample_idx
[
j
].
emplace_back
(
static_cast
<
int
>
(
i
));
}
...
...
@@ -565,7 +565,7 @@ int LGBM_DatasetCreateFromCSR(const void* indptr,
sample_values
.
resize
(
inner_data
.
first
+
1
);
sample_idx
.
resize
(
inner_data
.
first
+
1
);
}
if
(
std
::
fabs
(
inner_data
.
second
)
>
k
Epsilon
||
std
::
isnan
(
inner_data
.
second
))
{
if
(
std
::
fabs
(
inner_data
.
second
)
>
k
ZeroThreshold
||
std
::
isnan
(
inner_data
.
second
))
{
sample_values
[
inner_data
.
first
].
emplace_back
(
inner_data
.
second
);
sample_idx
[
inner_data
.
first
].
emplace_back
(
static_cast
<
int
>
(
i
));
}
...
...
@@ -633,7 +633,7 @@ int LGBM_DatasetCreateFromCSC(const void* col_ptr,
CSC_RowIterator
col_it
(
col_ptr
,
col_ptr_type
,
indices
,
data
,
data_type
,
ncol_ptr
,
nelem
,
i
);
for
(
int
j
=
0
;
j
<
sample_cnt
;
j
++
)
{
auto
val
=
col_it
.
Get
(
sample_indices
[
j
]);
if
(
std
::
fabs
(
val
)
>
k
Epsilon
||
std
::
isnan
(
val
))
{
if
(
std
::
fabs
(
val
)
>
k
ZeroThreshold
||
std
::
isnan
(
val
))
{
sample_values
[
i
].
emplace_back
(
val
);
sample_idx
[
i
].
emplace_back
(
j
);
}
...
...
@@ -1090,7 +1090,7 @@ int LGBM_BoosterPredictForCSC(BoosterHandle handle,
const
int
tid
=
omp_get_thread_num
();
for
(
int
j
=
0
;
j
<
ncol
;
++
j
)
{
auto
val
=
iterators
[
tid
][
j
].
Get
(
i
);
if
(
std
::
fabs
(
val
)
>
k
Epsilon
||
std
::
isnan
(
val
))
{
if
(
std
::
fabs
(
val
)
>
k
ZeroThreshold
||
std
::
isnan
(
val
))
{
one_row
.
emplace_back
(
j
,
val
);
}
}
...
...
@@ -1302,7 +1302,7 @@ RowPairFunctionFromDenseMatric(const void* data, int num_row, int num_col, int d
auto
raw_values
=
inner_function
(
row_idx
);
std
::
vector
<
std
::
pair
<
int
,
double
>>
ret
;
for
(
int
i
=
0
;
i
<
static_cast
<
int
>
(
raw_values
.
size
());
++
i
)
{
if
(
std
::
fabs
(
raw_values
[
i
])
>
k
Epsilon
||
std
::
isnan
(
raw_values
[
i
]))
{
if
(
std
::
fabs
(
raw_values
[
i
])
>
k
ZeroThreshold
||
std
::
isnan
(
raw_values
[
i
]))
{
ret
.
emplace_back
(
i
,
raw_values
[
i
]);
}
}
...
...
src/io/bin.cpp
View file @
0a7a4080
...
...
@@ -154,9 +154,9 @@ namespace LightGBM {
int
cnt_zero
=
0
;
int
right_cnt_data
=
0
;
for
(
int
i
=
0
;
i
<
num_distinct_values
;
++
i
)
{
if
(
distinct_values
[
i
]
<=
-
kZero
AsMissingValueRange
)
{
if
(
distinct_values
[
i
]
<=
-
kZero
Threshold
)
{
left_cnt_data
+=
counts
[
i
];
}
else
if
(
distinct_values
[
i
]
>
kZero
AsMissingValueRange
)
{
}
else
if
(
distinct_values
[
i
]
>
kZero
Threshold
)
{
right_cnt_data
+=
counts
[
i
];
}
else
{
cnt_zero
+=
counts
[
i
];
...
...
@@ -165,7 +165,7 @@ namespace LightGBM {
int
left_cnt
=
-
1
;
for
(
int
i
=
0
;
i
<
num_distinct_values
;
++
i
)
{
if
(
distinct_values
[
i
]
>
-
kZero
AsMissingValueRange
)
{
if
(
distinct_values
[
i
]
>
-
kZero
Threshold
)
{
left_cnt
=
i
;
break
;
}
...
...
@@ -179,12 +179,12 @@ namespace LightGBM {
int
left_max_bin
=
static_cast
<
int
>
(
static_cast
<
double
>
(
left_cnt_data
)
/
(
total_sample_cnt
-
cnt_zero
)
*
(
max_bin
-
1
));
left_max_bin
=
std
::
max
(
1
,
left_max_bin
);
bin_upper_bound
=
GreedyFindBin
(
distinct_values
,
counts
,
left_cnt
,
left_max_bin
,
left_cnt_data
,
min_data_in_bin
);
bin_upper_bound
.
back
()
=
-
kZero
AsMissingValueRange
;
bin_upper_bound
.
back
()
=
-
kZero
Threshold
;
}
int
right_start
=
-
1
;
for
(
int
i
=
left_cnt
;
i
<
num_distinct_values
;
++
i
)
{
if
(
distinct_values
[
i
]
>
kZero
AsMissingValueRange
)
{
if
(
distinct_values
[
i
]
>
kZero
Threshold
)
{
right_start
=
i
;
break
;
}
...
...
@@ -195,7 +195,7 @@ namespace LightGBM {
CHECK
(
right_max_bin
>
0
);
auto
right_bounds
=
GreedyFindBin
(
distinct_values
+
right_start
,
counts
+
right_start
,
num_distinct_values
-
right_start
,
right_max_bin
,
right_cnt_data
,
min_data_in_bin
);
bin_upper_bound
.
push_back
(
kZero
AsMissingValueRange
);
bin_upper_bound
.
push_back
(
kZero
Threshold
);
bin_upper_bound
.
insert
(
bin_upper_bound
.
end
(),
right_bounds
.
begin
(),
right_bounds
.
end
());
}
else
{
bin_upper_bound
.
push_back
(
std
::
numeric_limits
<
double
>::
infinity
());
...
...
src/io/dataset_loader.cpp
View file @
0a7a4080
...
...
@@ -760,7 +760,7 @@ void DatasetLoader::ConstructBinMappersFromTextData(int rank, int num_machines,
sample_values
.
resize
(
inner_data
.
first
+
1
);
sample_indices
.
resize
(
inner_data
.
first
+
1
);
}
if
(
std
::
fabs
(
inner_data
.
second
)
>
k
Epsilon
||
std
::
isnan
(
inner_data
.
second
))
{
if
(
std
::
fabs
(
inner_data
.
second
)
>
k
ZeroThreshold
||
std
::
isnan
(
inner_data
.
second
))
{
sample_values
[
inner_data
.
first
].
emplace_back
(
inner_data
.
second
);
sample_indices
[
inner_data
.
first
].
emplace_back
(
i
);
}
...
...
src/io/parser.hpp
View file @
0a7a4080
...
...
@@ -29,7 +29,7 @@ public:
*
out_label
=
val
;
bias
=
-
1
;
}
else
if
(
std
::
fabs
(
val
)
>
k
Epsilon
||
std
::
isnan
(
val
))
{
else
if
(
std
::
fabs
(
val
)
>
k
ZeroThreshold
||
std
::
isnan
(
val
))
{
out_features
->
emplace_back
(
idx
+
bias
,
val
);
}
++
idx
;
...
...
@@ -59,7 +59,7 @@ public:
if
(
idx
==
label_idx_
)
{
*
out_label
=
val
;
bias
=
-
1
;
}
else
if
(
std
::
fabs
(
val
)
>
k
Epsilon
||
std
::
isnan
(
val
))
{
}
else
if
(
std
::
fabs
(
val
)
>
k
ZeroThreshold
||
std
::
isnan
(
val
))
{
out_features
->
emplace_back
(
idx
+
bias
,
val
);
}
++
idx
;
...
...
src/io/tree.cpp
View file @
0a7a4080
...
...
@@ -317,7 +317,7 @@ std::string Tree::NumericalDecisionIfElse(int node) const {
std
::
stringstream
str_buf
;
uint8_t
missing_type
=
GetMissingType
(
decision_type_
[
node
]);
bool
default_left
=
GetDecisionType
(
decision_type_
[
node
],
kDefaultLeftMask
);
if
(
missing_type
==
0
||
(
missing_type
==
1
&&
default_left
&&
kZero
AsMissingValueRange
<
threshold_
[
node
]))
{
if
(
missing_type
==
0
||
(
missing_type
==
1
&&
default_left
&&
kZero
Threshold
<
threshold_
[
node
]))
{
str_buf
<<
"if (fval <= "
<<
threshold_
[
node
]
<<
") {"
;
}
else
if
(
missing_type
==
1
)
{
if
(
default_left
)
{
...
...
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