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
1c558a54
"include/LightGBM/vscode:/vscode.git/clone" did not exist on "da3b4c19dc76ed76a191d7d70098f7080495000c"
Unverified
Commit
1c558a54
authored
Oct 07, 2021
by
James Lamb
Committed by
GitHub
Oct 08, 2021
Browse files
fix possible precision loss in xentropy and fair loss objectives (#4651)
parent
29857c8a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
6 deletions
+6
-6
src/metric/regression_metric.hpp
src/metric/regression_metric.hpp
+1
-1
src/metric/xentropy_metric.hpp
src/metric/xentropy_metric.hpp
+2
-2
src/objective/xentropy_objective.hpp
src/objective/xentropy_objective.hpp
+3
-3
No files found.
src/metric/regression_metric.hpp
View file @
1c558a54
...
...
@@ -212,7 +212,7 @@ class FairLossMetric: public RegressionMetric<FairLossMetric> {
inline
static
double
LossOnPoint
(
label_t
label
,
double
score
,
const
Config
&
config
)
{
const
double
x
=
std
::
fabs
(
score
-
label
);
const
double
c
=
config
.
fair_c
;
return
c
*
x
-
c
*
c
*
std
::
log
(
1.0
f
+
x
/
c
);
return
c
*
x
-
c
*
c
*
std
::
log
1p
(
x
/
c
);
}
inline
static
const
char
*
Name
()
{
...
...
src/metric/xentropy_metric.hpp
View file @
1c558a54
...
...
@@ -194,13 +194,13 @@ class CrossEntropyLambdaMetric : public Metric {
if
(
weights_
==
nullptr
)
{
#pragma omp parallel for schedule(static) reduction(+:sum_loss)
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
double
hhat
=
std
::
log
(
1.0
f
+
std
::
exp
(
score
[
i
]));
// auto-convert
double
hhat
=
std
::
log
1p
(
std
::
exp
(
score
[
i
]));
// auto-convert
sum_loss
+=
XentLambdaLoss
(
label_
[
i
],
1.0
f
,
hhat
);
}
}
else
{
#pragma omp parallel for schedule(static) reduction(+:sum_loss)
for
(
data_size_t
i
=
0
;
i
<
num_data_
;
++
i
)
{
double
hhat
=
std
::
log
(
1.0
f
+
std
::
exp
(
score
[
i
]));
// auto-convert
double
hhat
=
std
::
log
1p
(
std
::
exp
(
score
[
i
]));
// auto-convert
sum_loss
+=
XentLambdaLoss
(
label_
[
i
],
weights_
[
i
],
hhat
);
}
}
...
...
src/objective/xentropy_objective.hpp
View file @
1c558a54
...
...
@@ -203,7 +203,7 @@ class CrossEntropyLambda: public ObjectiveFunction {
const
double
w
=
weights_
[
i
];
const
double
y
=
label_
[
i
];
const
double
epf
=
std
::
exp
(
score
[
i
]);
const
double
hhat
=
std
::
log
(
1.0
f
+
epf
);
const
double
hhat
=
std
::
log
1p
(
epf
);
const
double
z
=
1.0
f
-
std
::
exp
(
-
w
*
hhat
);
const
double
enf
=
1.0
f
/
epf
;
// = std::exp(-score[i]);
gradients
[
i
]
=
static_cast
<
score_t
>
((
1.0
f
-
y
/
z
)
*
w
/
(
1.0
f
+
enf
));
...
...
@@ -231,7 +231,7 @@ class CrossEntropyLambda: public ObjectiveFunction {
//
void
ConvertOutput
(
const
double
*
input
,
double
*
output
)
const
override
{
output
[
0
]
=
std
::
log
(
1.0
f
+
std
::
exp
(
input
[
0
]));
output
[
0
]
=
std
::
log
1p
(
std
::
exp
(
input
[
0
]));
}
std
::
string
ToString
()
const
override
{
...
...
@@ -259,7 +259,7 @@ class CrossEntropyLambda: public ObjectiveFunction {
}
}
double
havg
=
suml
/
sumw
;
double
initscore
=
std
::
log
(
std
::
exp
(
havg
)
-
1.0
f
);
double
initscore
=
std
::
log
(
std
::
exp
m1
(
havg
));
Log
::
Info
(
"[%s:%s]: havg = %f -> initscore = %f"
,
GetName
(),
__func__
,
havg
,
initscore
);
return
initscore
;
}
...
...
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