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
9895116d
Commit
9895116d
authored
Oct 24, 2016
by
Guolin Ke
Browse files
clean code
parent
94460df7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
28 deletions
+16
-28
src/application/predictor.hpp
src/application/predictor.hpp
+16
-28
No files found.
src/application/predictor.hpp
View file @
9895116d
...
...
@@ -60,15 +60,7 @@ public:
* \return Prediction result
*/
double
PredictRawOneLine
(
const
std
::
vector
<
std
::
pair
<
int
,
double
>>&
features
)
{
const
int
tid
=
omp_get_thread_num
();
// init feature value
std
::
memset
(
features_
[
tid
],
0
,
sizeof
(
double
)
*
num_features_
);
// put feature value
for
(
const
auto
&
p
:
features
)
{
if
(
p
.
first
<
num_features_
)
{
features_
[
tid
][
p
.
first
]
=
p
.
second
;
}
}
const
int
tid
=
PutFeatureValuesToBuffer
(
features
);
// get result without sigmoid transformation
return
boosting_
->
PredictRaw
(
features_
[
tid
]);
}
...
...
@@ -79,15 +71,7 @@ public:
* \return Predictied leaf index
*/
std
::
vector
<
int
>
PredictLeafIndexOneLine
(
const
std
::
vector
<
std
::
pair
<
int
,
double
>>&
features
)
{
const
int
tid
=
omp_get_thread_num
();
// init feature value
std
::
memset
(
features_
[
tid
],
0
,
sizeof
(
double
)
*
num_features_
);
// put feature value
for
(
const
auto
&
p
:
features
)
{
if
(
p
.
first
<
num_features_
)
{
features_
[
tid
][
p
.
first
]
=
p
.
second
;
}
}
const
int
tid
=
PutFeatureValuesToBuffer
(
features
);
// get result for leaf index
return
boosting_
->
PredictLeafIndex
(
features_
[
tid
]);
}
...
...
@@ -98,16 +82,8 @@ public:
* \return Prediction result
*/
double
PredictOneLine
(
const
std
::
vector
<
std
::
pair
<
int
,
double
>>&
features
)
{
const
int
tid
=
omp_get_thread_num
();
// init feature value
std
::
memset
(
features_
[
tid
],
0
,
sizeof
(
double
)
*
num_features_
);
// put feature value
for
(
const
auto
&
p
:
features
)
{
if
(
p
.
first
<
num_features_
)
{
features_
[
tid
][
p
.
first
]
=
p
.
second
;
}
}
// get result with sigmoid transform
const
int
tid
=
PutFeatureValuesToBuffer
(
features
);
// get result with sigmoid transform if needed
return
boosting_
->
Predict
(
features_
[
tid
]);
}
/*!
...
...
@@ -205,6 +181,18 @@ public:
}
private:
int
PutFeatureValuesToBuffer
(
const
std
::
vector
<
std
::
pair
<
int
,
double
>>&
features
)
{
int
tid
=
omp_get_thread_num
();
// init feature value
std
::
memset
(
features_
[
tid
],
0
,
sizeof
(
double
)
*
num_features_
);
// put feature value
for
(
const
auto
&
p
:
features
)
{
if
(
p
.
first
<
num_features_
)
{
features_
[
tid
][
p
.
first
]
=
p
.
second
;
}
}
return
tid
;
}
/*! \brief Boosting model */
const
Boosting
*
boosting_
;
/*! \brief Buffer for feature values */
...
...
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