Пример #1
0
 /*! \brief save a DataMatrix as DMatrixPage */
 inline static void Save(const char *fname_, const DataMatrix &mat, bool silent) {
   std::string fname = fname_;
   utils::FileStream fs(utils::FopenCheck(fname.c_str(), "wb"));
   int magic = kMagic;
   fs.Write(&magic, sizeof(magic));
   mat.info.SaveBinary(fs);
   fs.Close();
   fname += ".row.blob";
   utils::IIterator<RowBatch> *iter = mat.fmat()->RowIterator();
   utils::FileStream fbin(utils::FopenCheck(fname.c_str(), "wb"));
   SparsePage page;
   iter->BeforeFirst();
   while (iter->Next()) {
     const RowBatch &batch = iter->Value();
     for (size_t i = 0; i < batch.size; ++i) {
       page.Push(batch[i]);
       if (page.MemCostBytes() >= kPageSize) {
         page.Save(&fbin); page.Clear();
       }
     }
   }
   if (page.data.size() != 0) page.Save(&fbin);
   fbin.Close();
   if (!silent) {
     utils::Printf("DMatrixPage: %lux%lu is saved to %s\n",
                   static_cast<unsigned long>(mat.info.num_row()),
                   static_cast<unsigned long>(mat.info.num_col()), fname_);
   }
 }
Пример #2
0
 inline void BoostOneIter(const DataMatrix &train,
                          float *grad, float *hess, bst_ulong len) {
   this->gpair_.resize(len);
   const bst_omp_uint ndata = static_cast<bst_omp_uint>(len);
   #pragma omp parallel for schedule(static)
   for (bst_omp_uint j = 0; j < ndata; ++j) {
     gpair_[j] = bst_gpair(grad[j], hess[j]);
   }
   gbm_->DoBoost(train.fmat(), train.info.info, &gpair_);
 }