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
52859744
Unverified
Commit
52859744
authored
Nov 23, 2020
by
Guolin Ke
Committed by
GitHub
Nov 23, 2020
Browse files
fix deterministic, part2 (#3578)
* fix deterministic, part2 * Apply suggestions from code review
parent
d6f20e37
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
18 deletions
+33
-18
src/objective/binary_objective.hpp
src/objective/binary_objective.hpp
+8
-4
src/objective/regression_objective.hpp
src/objective/regression_objective.hpp
+7
-4
src/objective/xentropy_objective.hpp
src/objective/xentropy_objective.hpp
+18
-10
No files found.
src/objective/binary_objective.hpp
View file @
52859744
...
...
@@ -20,7 +20,9 @@ namespace LightGBM {
*/
class
BinaryLogloss
:
public
ObjectiveFunction
{
public:
explicit
BinaryLogloss
(
const
Config
&
config
,
std
::
function
<
bool
(
label_t
)
>
is_pos
=
nullptr
)
{
explicit
BinaryLogloss
(
const
Config
&
config
,
std
::
function
<
bool
(
label_t
)
>
is_pos
=
nullptr
)
:
deterministic_
(
config
.
deterministic
)
{
sigmoid_
=
static_cast
<
double
>
(
config
.
sigmoid
);
if
(
sigmoid_
<=
0.0
)
{
Log
::
Fatal
(
"Sigmoid parameter %f should be greater than zero"
,
sigmoid_
);
...
...
@@ -36,7 +38,8 @@ class BinaryLogloss: public ObjectiveFunction {
}
}
explicit
BinaryLogloss
(
const
std
::
vector
<
std
::
string
>&
strs
)
{
explicit
BinaryLogloss
(
const
std
::
vector
<
std
::
string
>&
strs
)
:
deterministic_
(
false
)
{
sigmoid_
=
-
1
;
for
(
auto
str
:
strs
)
{
auto
tokens
=
Common
::
Split
(
str
.
c_str
(),
':'
);
...
...
@@ -137,14 +140,14 @@ class BinaryLogloss: public ObjectiveFunction {
double
suml
=
0.0
f
;
double
sumw
=
0.0
f
;
if
(
weights_
!=
nullptr
)
{
#pragma omp parallel for schedule(static) reduction(+:suml, sumw)
#pragma omp parallel for schedule(static) reduction(+:suml, sumw)
if (!deterministic_)
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
suml
+=
is_pos_
(
label_
[
i
])
*
weights_
[
i
];
sumw
+=
weights_
[
i
];
}
}
else
{
sumw
=
static_cast
<
double
>
(
num_data_
);
#pragma omp parallel for schedule(static) reduction(+:suml)
#pragma omp parallel for schedule(static) reduction(+:suml)
if (!deterministic_)
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
suml
+=
is_pos_
(
label_
[
i
]);
}
...
...
@@ -202,6 +205,7 @@ class BinaryLogloss: public ObjectiveFunction {
double
scale_pos_weight_
;
std
::
function
<
bool
(
label_t
)
>
is_pos_
;
bool
need_train_
;
const
bool
deterministic_
;
};
}
// namespace LightGBM
...
...
src/objective/regression_objective.hpp
View file @
52859744
...
...
@@ -92,11 +92,13 @@ namespace LightGBM {
*/
class
RegressionL2loss
:
public
ObjectiveFunction
{
public:
explicit
RegressionL2loss
(
const
Config
&
config
)
{
explicit
RegressionL2loss
(
const
Config
&
config
)
:
deterministic_
(
config
.
deterministic
)
{
sqrt_
=
config
.
reg_sqrt
;
}
explicit
RegressionL2loss
(
const
std
::
vector
<
std
::
string
>&
strs
)
{
explicit
RegressionL2loss
(
const
std
::
vector
<
std
::
string
>&
strs
)
:
deterministic_
(
false
)
{
sqrt_
=
false
;
for
(
auto
str
:
strs
)
{
if
(
str
==
std
::
string
(
"sqrt"
))
{
...
...
@@ -172,14 +174,14 @@ class RegressionL2loss: public ObjectiveFunction {
double
suml
=
0.0
f
;
double
sumw
=
0.0
f
;
if
(
weights_
!=
nullptr
)
{
#pragma omp parallel for schedule(static) reduction(+:suml, sumw)
#pragma omp parallel for schedule(static) reduction(+:suml, sumw)
if (!deterministic_)
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
suml
+=
label_
[
i
]
*
weights_
[
i
];
sumw
+=
weights_
[
i
];
}
}
else
{
sumw
=
static_cast
<
double
>
(
num_data_
);
#pragma omp parallel for schedule(static) reduction(+:suml)
#pragma omp parallel for schedule(static) reduction(+:suml)
if (!deterministic_)
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
suml
+=
label_
[
i
];
}
...
...
@@ -196,6 +198,7 @@ class RegressionL2loss: public ObjectiveFunction {
/*! \brief Pointer of weights */
const
label_t
*
weights_
;
std
::
vector
<
label_t
>
trans_label_
;
const
bool
deterministic_
;
};
/*!
...
...
src/objective/xentropy_objective.hpp
View file @
52859744
...
...
@@ -43,10 +43,11 @@ namespace LightGBM {
*/
class
CrossEntropy
:
public
ObjectiveFunction
{
public:
explicit
CrossEntropy
(
const
Config
&
)
{
}
explicit
CrossEntropy
(
const
Config
&
config
)
:
deterministic_
(
config
.
deterministic
)
{
}
explicit
CrossEntropy
(
const
std
::
vector
<
std
::
string
>&
)
{
explicit
CrossEntropy
(
const
std
::
vector
<
std
::
string
>&
)
:
deterministic_
(
false
)
{
}
~
CrossEntropy
()
{}
...
...
@@ -113,14 +114,16 @@ class CrossEntropy: public ObjectiveFunction {
double
suml
=
0.0
f
;
double
sumw
=
0.0
f
;
if
(
weights_
!=
nullptr
)
{
#pragma omp parallel for schedule(static) reduction(+:suml, sumw)
#pragma omp parallel for schedule(static) reduction(+:suml, sumw) if (!deterministic_)
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
suml
+=
label_
[
i
]
*
weights_
[
i
];
sumw
+=
weights_
[
i
];
}
}
else
{
sumw
=
static_cast
<
double
>
(
num_data_
);
#pragma omp parallel for schedule(static) reduction(+:suml)
#pragma omp parallel for schedule(static) reduction(+:suml) if (!deterministic_)
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
suml
+=
label_
[
i
];
}
...
...
@@ -140,6 +143,7 @@ class CrossEntropy: public ObjectiveFunction {
const
label_t
*
label_
;
/*! \brief Weights for data */
const
label_t
*
weights_
;
const
bool
deterministic_
;
};
/*!
...
...
@@ -147,12 +151,13 @@ class CrossEntropy: public ObjectiveFunction {
*/
class
CrossEntropyLambda
:
public
ObjectiveFunction
{
public:
explicit
CrossEntropyLambda
(
const
Config
&
)
{
explicit
CrossEntropyLambda
(
const
Config
&
config
)
:
deterministic_
(
config
.
deterministic
)
{
min_weight_
=
max_weight_
=
0.0
f
;
}
explicit
CrossEntropyLambda
(
const
std
::
vector
<
std
::
string
>&
)
{
}
explicit
CrossEntropyLambda
(
const
std
::
vector
<
std
::
string
>&
)
:
deterministic_
(
false
)
{
}
~
CrossEntropyLambda
()
{}
...
...
@@ -239,14 +244,16 @@ class CrossEntropyLambda: public ObjectiveFunction {
double
suml
=
0.0
f
;
double
sumw
=
0.0
f
;
if
(
weights_
!=
nullptr
)
{
#pragma omp parallel for schedule(static) reduction(+:suml, sumw)
#pragma omp parallel for schedule(static) reduction(+:suml, sumw) if (!deterministic_)
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
suml
+=
label_
[
i
]
*
weights_
[
i
];
sumw
+=
weights_
[
i
];
}
}
else
{
sumw
=
static_cast
<
double
>
(
num_data_
);
#pragma omp parallel for schedule(static) reduction(+:suml)
#pragma omp parallel for schedule(static) reduction(+:suml) if (!deterministic_)
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
suml
+=
label_
[
i
];
}
...
...
@@ -268,6 +275,7 @@ class CrossEntropyLambda: public ObjectiveFunction {
label_t
min_weight_
;
/*! \brief Maximum weight found during init */
label_t
max_weight_
;
const
bool
deterministic_
;
};
}
// end 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