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
f40e0d2e
"python-package/vscode:/vscode.git/clone" did not exist on "b60068c810cbcac9cf4e1a8e678d8d531c40eb72"
Commit
f40e0d2e
authored
Mar 30, 2017
by
Guolin Ke
Browse files
add weight decay in softmax loss.
parent
4398906d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
6 deletions
+10
-6
src/objective/multiclass_objective.hpp
src/objective/multiclass_objective.hpp
+10
-6
No files found.
src/objective/multiclass_objective.hpp
View file @
f40e0d2e
...
@@ -17,6 +17,7 @@ class MulticlassSoftmax: public ObjectiveFunction {
...
@@ -17,6 +17,7 @@ class MulticlassSoftmax: public ObjectiveFunction {
public:
public:
explicit
MulticlassSoftmax
(
const
ObjectiveConfig
&
config
)
{
explicit
MulticlassSoftmax
(
const
ObjectiveConfig
&
config
)
{
num_class_
=
config
.
num_class
;
num_class_
=
config
.
num_class
;
softmax_weight_decay_
=
1e-3
;
}
}
~
MulticlassSoftmax
()
{
~
MulticlassSoftmax
()
{
...
@@ -35,6 +36,7 @@ public:
...
@@ -35,6 +36,7 @@ public:
Log
::
Fatal
(
"Label must be in [0, %d), but found %d in label"
,
num_class_
,
label_int_
[
i
]);
Log
::
Fatal
(
"Label must be in [0, %d), but found %d in label"
,
num_class_
,
label_int_
[
i
]);
}
}
}
}
hessian_nor_
=
static_cast
<
score_t
>
(
num_class_
)
/
(
num_class_
-
1
);
}
}
void
GetGradients
(
const
double
*
score
,
score_t
*
gradients
,
score_t
*
hessians
)
const
override
{
void
GetGradients
(
const
double
*
score
,
score_t
*
gradients
,
score_t
*
hessians
)
const
override
{
...
@@ -52,11 +54,11 @@ public:
...
@@ -52,11 +54,11 @@ public:
auto
p
=
rec
[
k
];
auto
p
=
rec
[
k
];
size_t
idx
=
static_cast
<
size_t
>
(
num_data_
)
*
k
+
i
;
size_t
idx
=
static_cast
<
size_t
>
(
num_data_
)
*
k
+
i
;
if
(
label_int_
[
i
]
==
k
)
{
if
(
label_int_
[
i
]
==
k
)
{
gradients
[
idx
]
=
static_cast
<
score_t
>
(
p
-
1.0
f
);
gradients
[
idx
]
=
static_cast
<
score_t
>
(
p
-
1.0
f
+
softmax_weight_decay_
*
score
[
idx
]
);
}
else
{
}
else
{
gradients
[
idx
]
=
static_cast
<
score_t
>
(
p
);
gradients
[
idx
]
=
static_cast
<
score_t
>
(
p
+
softmax_weight_decay_
*
score
[
idx
]
);
}
}
hessians
[
idx
]
=
static_cast
<
score_t
>
(
2.0
f
*
p
*
(
1.0
f
-
p
));
hessians
[
idx
]
=
static_cast
<
score_t
>
(
hessian_nor_
*
p
*
(
1.0
f
-
p
)
+
softmax_weight_decay_
);
}
}
}
}
}
else
{
}
else
{
...
@@ -73,11 +75,11 @@ public:
...
@@ -73,11 +75,11 @@ public:
auto
p
=
rec
[
k
];
auto
p
=
rec
[
k
];
size_t
idx
=
static_cast
<
size_t
>
(
num_data_
)
*
k
+
i
;
size_t
idx
=
static_cast
<
size_t
>
(
num_data_
)
*
k
+
i
;
if
(
label_int_
[
i
]
==
k
)
{
if
(
label_int_
[
i
]
==
k
)
{
gradients
[
idx
]
=
static_cast
<
score_t
>
((
p
-
1.0
f
)
*
weights_
[
i
]);
gradients
[
idx
]
=
static_cast
<
score_t
>
((
p
-
1.0
f
+
softmax_weight_decay_
*
score
[
idx
]
)
*
weights_
[
i
]);
}
else
{
}
else
{
gradients
[
idx
]
=
static_cast
<
score_t
>
(
p
*
weights_
[
i
]);
gradients
[
idx
]
=
static_cast
<
score_t
>
(
(
p
+
softmax_weight_decay_
*
score
[
idx
])
*
weights_
[
i
]);
}
}
hessians
[
idx
]
=
static_cast
<
score_t
>
(
2.0
f
*
p
*
(
1.0
f
-
p
)
*
weights_
[
i
]);
hessians
[
idx
]
=
static_cast
<
score_t
>
(
(
hessian_nor_
*
p
*
(
1.0
f
-
p
)
+
softmax_weight_decay_
)
*
weights_
[
i
]);
}
}
}
}
}
}
...
@@ -98,6 +100,8 @@ private:
...
@@ -98,6 +100,8 @@ private:
std
::
vector
<
int
>
label_int_
;
std
::
vector
<
int
>
label_int_
;
/*! \brief Weights for data */
/*! \brief Weights for data */
const
float
*
weights_
;
const
float
*
weights_
;
double
softmax_weight_decay_
;
score_t
hessian_nor_
;
};
};
/*!
/*!
...
...
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