Commit 9895116d authored by Guolin Ke's avatar Guolin Ke
Browse files

clean code

parent 94460df7
...@@ -60,15 +60,7 @@ public: ...@@ -60,15 +60,7 @@ public:
* \return Prediction result * \return Prediction result
*/ */
double PredictRawOneLine(const std::vector<std::pair<int, double>>& features) { double PredictRawOneLine(const std::vector<std::pair<int, double>>& features) {
const int tid = omp_get_thread_num(); const int tid = PutFeatureValuesToBuffer(features);
// 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 without sigmoid transformation // get result without sigmoid transformation
return boosting_->PredictRaw(features_[tid]); return boosting_->PredictRaw(features_[tid]);
} }
...@@ -79,15 +71,7 @@ public: ...@@ -79,15 +71,7 @@ public:
* \return Predictied leaf index * \return Predictied leaf index
*/ */
std::vector<int> PredictLeafIndexOneLine(const std::vector<std::pair<int, double>>& features) { std::vector<int> PredictLeafIndexOneLine(const std::vector<std::pair<int, double>>& features) {
const int tid = omp_get_thread_num(); const int tid = PutFeatureValuesToBuffer(features);
// 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 for leaf index // get result for leaf index
return boosting_->PredictLeafIndex(features_[tid]); return boosting_->PredictLeafIndex(features_[tid]);
} }
...@@ -98,16 +82,8 @@ public: ...@@ -98,16 +82,8 @@ public:
* \return Prediction result * \return Prediction result
*/ */
double PredictOneLine(const std::vector<std::pair<int, double>>& features) { double PredictOneLine(const std::vector<std::pair<int, double>>& features) {
const int tid = omp_get_thread_num(); const int tid = PutFeatureValuesToBuffer(features);
// init feature value // get result with sigmoid transform if needed
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
return boosting_->Predict(features_[tid]); return boosting_->Predict(features_[tid]);
} }
/*! /*!
...@@ -205,6 +181,18 @@ public: ...@@ -205,6 +181,18 @@ public:
} }
private: 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 */ /*! \brief Boosting model */
const Boosting* boosting_; const Boosting* boosting_;
/*! \brief Buffer for feature values */ /*! \brief Buffer for feature values */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment