本文整理汇总了C++中DataSet::QSort方法的典型用法代码示例。如果您正苦于以下问题:C++ DataSet::QSort方法的具体用法?C++ DataSet::QSort怎么用?C++ DataSet::QSort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataSet
的用法示例。
在下文中一共展示了DataSet::QSort方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Train
void BoostCart::Train(DataSet& pos, DataSet& neg) {
Config& c = Config::GetInstance();
JoinCascador& joincascador = *c.joincascador;
// statistic parameters
const int pos_original_size = pos.size;
const int neg_original_size = int(pos_original_size * c.nps[stage]);
int neg_rejected = 0;
const int landmark_n = c.landmark_n;
const int normalization_step = landmark_n*c.score_normalization_steps[stage];
RNG& rng = c.rng_pool[0];
//int drop_n = (1. - c.recall[stage])*pos.size / K; // pos drop number per cart
//if (drop_n <= 1) drop_n = 1;
int drop_n = c.drops[stage];
const int start_of_cart = joincascador.current_cart_idx + 1;
int restarts = 0;
double best_drop_rate = 0.;
Cart best_cart = carts[0];
// Real Boost
// if neg.size < neg_th, mining starts
int current_stage_idx = c.joincascador->current_stage_idx;
int neg_th = int(pos.size*c.nps[current_stage_idx] * c.mining_th[current_stage_idx]);
for (int k = start_of_cart; k < K; k++) {
const int kk = k + 1;
Cart& cart = carts[k];
if (neg.size < neg_th) {
neg.MoreNegSamples(pos.size, c.nps[stage]);
neg_th = int(neg.size * c.mining_th[current_stage_idx]); // update neg_th
}
// print out data set status
pos.QSort(); neg.QSort();
LOG("Pos max score = %.4lf, min score = %.4lf", pos.scores[0], pos.scores[pos.size - 1]);
LOG("Neg max score = %.4lf, min score = %.4lf", neg.scores[0], neg.scores[neg.size - 1]);
// draw scores desity graph
draw_density_graph(pos.scores, neg.scores);
// update weights
DataSet::UpdateWeights(pos, neg);
LOG("Current Positive DataSet Size is %d", pos.size);
LOG("Current Negative DataSet Size is %d", neg.size);
// train cart
TIMER_BEGIN
LOG("Train %d th Cart", k + 1);
cart.Train(pos, neg);
LOG("Done with %d th Cart, costs %.4lf s", k + 1, TIMER_NOW);
TIMER_END
joincascador.current_cart_idx = k;
// update score and last_score
pos.UpdateScores(cart);
neg.UpdateScores(cart);
if (kk % normalization_step == 0) {
DataSet::CalcMeanAndStd(pos, neg, cart.mean, cart.std);
pos.ApplyMeanAndStd(cart.mean, cart.std);
neg.ApplyMeanAndStd(cart.mean, cart.std);
}
else {
cart.mean = 0.;
cart.std = 1.;
}
// select th for pre-defined recall
pos.QSort();
neg.QSort();
cart.th = pos.CalcThresholdByNumber(drop_n);
int pos_n = pos.size;
int neg_n = neg.size;
int will_removed = neg.PreRemove(cart.th);
double tmp_drop_rate = double(will_removed) / neg_n;
int number_of_carts = joincascador.current_stage_idx*joincascador.K + joincascador.current_cart_idx;
if (c.restart_on && tmp_drop_rate < c.restart_th[joincascador.current_stage_idx] && number_of_carts > 10) {
restarts++;
LOG("***** Drop %d, Drop rate neg is %.4lf%%, Restart current Cart *****", will_removed, tmp_drop_rate*100.);
LOG("***** Restart Time: %d *****", restarts);
LOG("Current trained Cart below");
cart.PrintSelf();
// compare with best cart for now
if (tmp_drop_rate > best_drop_rate) {
best_drop_rate = tmp_drop_rate;
best_cart = cart;
}
// select the best cart for this cart
if (restarts >= c.restart_times) {
LOG("***** Select a cart which give us %.4lf%% drop rate *****", best_drop_rate*100.);
cart = best_cart;
best_drop_rate = 0.;
pos.ResetScores();
neg.ResetScores();
pos.UpdateScores(cart);
neg.UpdateScores(cart);
if (kk % normalization_step == 0) {
DataSet::CalcMeanAndStd(pos, neg, cart.mean, cart.std);
pos.ApplyMeanAndStd(cart.mean, cart.std);
neg.ApplyMeanAndStd(cart.mean, cart.std);
}
else {
cart.mean = 0.;
cart.std = 1.;
//.........这里部分代码省略.........