add pratio

This commit is contained in:
tqchen 2014-08-19 08:05:05 -07:00
parent fdba6e9c46
commit 406db647f2

View File

@ -158,7 +158,7 @@ struct EvalAMS : public IEvaluator {
/*! \brief precision with cut off at top percentile */
struct EvalPrecisionRatio : public IEvaluator{
public:
EvalPrecisionRatio( const char *name ) : name_(name) {
explicit EvalPrecisionRatio(const char *name) : name_(name) {
utils::Assert(sscanf(name, "apratio@%f", &ratio_) == 1, "BUG");
}
virtual float Eval(const std::vector<float> &preds,
@ -175,17 +175,17 @@ struct EvalPrecisionRatio : public IEvaluator{
virtual const char *Name(void) const {
return name_.c_str();
}
protected:
inline double CalcPRatio(const std::vector< std::pair<float, unsigned> >& rec, const MetaInfo &info) const {
size_t cutoff = static_cast<size_t>(ratio_ * rec.size());
double wt_hit = 0.0, wsum = 0.0;
for (size_t j = 0; j < cutoff; ++j) {
wt_hit += info.labels[rec[j].second];
wsum += wt_hit / j;
wsum += wt_hit / (j + 1);
}
return wsum / cutoff;
}
protected:
float ratio_;
std::string name_;
};