| 71 | // ---------------------------------------------------------------------------------------- |
| 72 | |
| 73 | double test_rank_unlabeled_training_samples ( |
| 74 | const std::vector<sample_type>& samples, |
| 75 | const std::vector<double>& labels, |
| 76 | active_learning_mode mode, |
| 77 | int iterations, |
| 78 | bool pick_front |
| 79 | ) |
| 80 | { |
| 81 | matrix<double,2,1> s; |
| 82 | s = sum(mat(labels) > 0), sum(mat(labels) < 0); |
| 83 | s /= labels.size(); |
| 84 | |
| 85 | |
| 86 | svm_c_linear_dcd_trainer<linear_kernel<sample_type> > trainer; |
| 87 | trainer.set_c(25); |
| 88 | |
| 89 | const unsigned long initial_size = 1; |
| 90 | std::vector<sample_type> tsamples(samples.begin(), samples.begin()+initial_size); |
| 91 | std::vector<double> tlabels(labels.begin(), labels.begin()+initial_size); |
| 92 | |
| 93 | decision_function<linear_kernel<sample_type> > df; |
| 94 | |
| 95 | double random_score = 0; |
| 96 | double active_learning_score = 0; |
| 97 | for (int i = 0; i < iterations; ++i) |
| 98 | { |
| 99 | print_spinner(); |
| 100 | random_subset_selector<sample_type> sss = randomly_subsample(samples,50,i); |
| 101 | random_subset_selector<double> ssl = randomly_subsample(labels,50,i); |
| 102 | std::vector<unsigned long> results; |
| 103 | |
| 104 | results = rank_unlabeled_training_samples(trainer, tsamples, tlabels, sss, mode); |
| 105 | |
| 106 | const unsigned long idx = pick_front ? results.front() : results.back(); |
| 107 | tsamples.push_back(sss[idx]); |
| 108 | tlabels.push_back(ssl[idx]); |
| 109 | |
| 110 | df = trainer.train(tsamples, tlabels); |
| 111 | //cout << "tsamples.size(): " << tsamples.size() << endl; |
| 112 | const unsigned long num = tsamples.size(); |
| 113 | const double active = test_binary_decision_function(df, samples, labels)*s; |
| 114 | //cout << "test: "<< active; |
| 115 | df = trainer.train(randomly_subsample(samples,num,i), randomly_subsample(labels,num,i)); |
| 116 | const double random = test_binary_decision_function(df, samples, labels)*s; |
| 117 | //cout << "test: "<< random << endl; |
| 118 | |
| 119 | active_learning_score += active; |
| 120 | random_score += random; |
| 121 | |
| 122 | //cout << "\n\n***********\n\n" << flush; |
| 123 | } |
| 124 | |
| 125 | dlog << LINFO << "pick_front: " << pick_front << " mode: "<< mode; |
| 126 | dlog << LINFO << "active_learning_score: "<< active_learning_score; |
| 127 | dlog << LINFO << "random_score: "<< random_score; |
| 128 | return active_learning_score / random_score; |
| 129 | } |
| 130 |
no test coverage detected