MCPcopy Create free account
hub / github.com/davisking/dlib / train_probabilistic_decision_function

Function train_probabilistic_decision_function

dlib/svm/svm.h:767–903  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 // count the number of positive and negative examples
792 const long num_pos = (long)sum(mat(y) > 0);
793 const long num_neg = (long)sum(mat(y) < 0);
794
795 // make sure requires clause is not broken
796 DLIB_ASSERT(is_binary_classification_problem(x,y) == true &&
797 1 < folds && folds <= std::min(num_pos,num_neg),
798 "\tprobabilistic_decision_function train_probabilistic_decision_function()"
799 << "\n\t invalid inputs were given to this function"
800 << "\n\t x.size(): " << x.size()
801 << "\n\t y.size(): " << y.size()
802 << "\n\t folds: " << folds
803 << "\n\t num_pos: " << num_pos
804 << "\n\t num_neg: " << num_neg
805 << "\n\t is_binary_classification_problem(x,y): " << is_binary_classification_problem(x,y)
806 );
807
808 // figure out how many positive and negative examples we will have in each fold
809 const long num_pos_test_samples = num_pos/folds;
810 const long num_pos_train_samples = num_pos - num_pos_test_samples;
811 const long num_neg_test_samples = num_neg/folds;
812 const long num_neg_train_samples = num_neg - num_neg_test_samples;
813
814 typename trainer_type::trained_function_type d;
815 std::vector<sample_type> x_test, x_train;
816 std::vector<scalar_type> y_test, y_train;
817 x_test.resize (num_pos_test_samples + num_neg_test_samples);
818 y_test.resize (num_pos_test_samples + num_neg_test_samples);
819 x_train.resize(num_pos_train_samples + num_neg_train_samples);
820 y_train.resize(num_pos_train_samples + num_neg_train_samples);
821
822 std::vector<scalar_type> out, out_label;
823
824 long pos_idx = 0;

Callers 6

perform_testMethod · 0.85
trainMethod · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 9

learn_platt_scalingFunction · 0.85
matFunction · 0.70
minFunction · 0.70
sumFunction · 0.50
sizeMethod · 0.45
resizeMethod · 0.45
trainMethod · 0.45
push_backMethod · 0.45

Tested by 1

perform_testMethod · 0.68