#ifndef XGBOOST_REGRANK_OBJ_HPP #define XGBOOST_REGRANK_OBJ_HPP /*! * \file xgboost_regrank_obj.h * \brief implementation of objective functions * \author Tianqi Chen, Kailong Chen */ namespace xgboost{ namespace regrank{ class RegressionObj : public IObjFunction{ public: RegressionObj(void){ loss.loss_type = LossType::kLinearSquare; } virtual ~RegressionObj(){} virtual void SetParam(const char *name, const char *val){ if( !strcmp( "loss_type", name ) ) loss.loss_type = atoi( val ); } virtual void GetGradient(const std::vector& preds, const DMatrix::Info &info, std::vector &grad, std::vector &hess ) { grad.resize(preds.size()); hess.resize(preds.size()); const unsigned ndata = static_cast(preds.size()); #pragma omp parallel for schedule( static ) for (unsigned j = 0; j < ndata; ++j){ grad[j] = loss.FirstOrderGradient(preds[j], info.labels[j]) * info.GetWeight(j); hess[j] = loss.SecondOrderGradient(preds[j], info.labels[j]) * info.GetWeight(j); } } virtual const char* DefaultEvalMetric(void) { if( loss.loss_type == LossType::kLogisticClassify ) return "error"; else return "rmse"; } virtual void PredTransform(std::vector &preds){ const unsigned ndata = static_cast(preds.size()); #pragma omp parallel for schedule( static ) for (unsigned j = 0; j < ndata; ++j){ preds[j] = loss.PredTransform( preds[j] ); } } private: LossType loss; }; }; namespace regrank{ // TODO rank objective }; }; #endif