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

Method train

examples/custom_trainer_ex.cpp:91–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89
90
91 custom_decision_function train (
92 const std::vector<sample_type>& samples,
93 const std::vector<double>& labels
94 ) const
95 /*!
96 requires
97 - is_binary_classification_problem(samples, labels) == true
98 (e.g. labels consists of only +1 and -1 values, samples.size() == labels.size())
99 ensures
100 - returns a decision function F with the following properties:
101 - if (new_x is a sample predicted have +1 label) then
102 - F(new_x) >= 0
103 - else
104 - F(new_x) < 0
105 !*/
106 {
107 sample_type positive_center, negative_center;
108
109 // compute sums of each class
110 positive_center = 0;
111 negative_center = 0;
112 for (unsigned long i = 0; i < samples.size(); ++i)
113 {
114 if (labels[i] == +1)
115 positive_center += samples[i];
116 else // this is a -1 sample
117 negative_center += samples[i];
118 }
119
120 // divide by number of +1 samples
121 positive_center /= sum(mat(labels) == +1);
122 // divide by number of -1 samples
123 negative_center /= sum(mat(labels) == -1);
124
125 custom_decision_function df;
126 df.positive_center = positive_center;
127 df.negative_center = negative_center;
128
129 return df;
130 }
131};
132
133// ----------------------------------------------------------------------------------------

Callers 1

mainFunction · 0.45

Calls 3

sumFunction · 0.50
matFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected