| 765 | typename label_vector_type |
| 766 | > |
| 767 | const probabilistic_function<typename trainer_type::trained_function_type> |
| 768 | train_probabilistic_decision_function ( |
| 769 | const trainer_type& trainer, |
| 770 | const sample_vector_type& x, |
| 771 | const label_vector_type& y, |
| 772 | const long folds |
| 773 | ) |
| 774 | { |
| 775 | typedef typename sample_vector_type::value_type sample_type; |
| 776 | typedef typename label_vector_type::value_type scalar_type; |
| 777 | |
| 778 | /* |
| 779 | This function fits a sigmoid function to the output of the |
| 780 | svm trained by svm_nu_trainer or a similar trainer. The |
| 781 | technique used is the one described in the papers: |
| 782 | |
| 783 | Probabilistic Outputs for Support Vector Machines and |
| 784 | Comparisons to Regularized Likelihood Methods by |
| 785 | John C. Platt. March 26, 1999 |
| 786 | |
| 787 | A Note on Platt's Probabilistic Outputs for Support Vector Machines |
| 788 | by Hsuan-Tien Lin, Chih-Jen Lin, and Ruby C. Weng |
| 789 | */ |
| 790 | |
| 791 | // make sure requires clause is not broken |
| 792 | DLIB_ASSERT(is_binary_classification_problem(x,y) == true && |
| 793 | 1 < folds && folds <= (long)x.size(), |
| 794 | "\tprobabilistic_decision_function train_probabilistic_decision_function()" |
| 795 | << "\n\t invalid inputs were given to this function" |
| 796 | << "\n\t x.size(): " << x.size() |
| 797 | << "\n\t y.size(): " << y.size() |
| 798 | << "\n\t folds: " << folds |
| 799 | << "\n\t is_binary_classification_problem(x,y): " << is_binary_classification_problem(x,y) |
| 800 | ); |
| 801 | |
| 802 | // count the number of positive and negative examples |
| 803 | const long num_pos = (long)sum(mat(y) > 0); |
| 804 | const long num_neg = (long)sum(mat(y) < 0); |
| 805 | |
| 806 | // figure out how many positive and negative examples we will have in each fold |
| 807 | const long num_pos_test_samples = num_pos/folds; |
| 808 | const long num_pos_train_samples = num_pos - num_pos_test_samples; |
| 809 | const long num_neg_test_samples = num_neg/folds; |
| 810 | const long num_neg_train_samples = num_neg - num_neg_test_samples; |
| 811 | |
| 812 | typename trainer_type::trained_function_type d; |
| 813 | std::vector<sample_type> x_test, x_train; |
| 814 | std::vector<scalar_type> y_test, y_train; |
| 815 | x_test.resize (num_pos_test_samples + num_neg_test_samples); |
| 816 | y_test.resize (num_pos_test_samples + num_neg_test_samples); |
| 817 | x_train.resize(num_pos_train_samples + num_neg_train_samples); |
| 818 | y_train.resize(num_pos_train_samples + num_neg_train_samples); |
| 819 | |
| 820 | std::vector<scalar_type> out, out_label; |
| 821 | |
| 822 | long pos_idx = 0; |
| 823 | long neg_idx = 0; |
| 824 |
no test coverage detected