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

Function generate_data

examples/multiclass_classification_ex.cpp:185–245  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

183// ----------------------------------------------------------------------------------------
184
185void generate_data (
186 std::vector<sample_type>& samples,
187 std::vector<double>& labels
188)
189{
190 const long num = 50;
191
192 sample_type m;
193
194 dlib::rand rnd;
195
196
197 // make some samples near the origin
198 double radius = 0.5;
199 for (long i = 0; i < num+10; ++i)
200 {
201 double sign = 1;
202 if (rnd.get_random_double() < 0.5)
203 sign = -1;
204 m(0) = 2*radius*rnd.get_random_double()-radius;
205 m(1) = sign*sqrt(radius*radius - m(0)*m(0));
206
207 // add this sample to our set of training samples
208 samples.push_back(m);
209 labels.push_back(1);
210 }
211
212 // make some samples in a circle around the origin but far away
213 radius = 10.0;
214 for (long i = 0; i < num+20; ++i)
215 {
216 double sign = 1;
217 if (rnd.get_random_double() < 0.5)
218 sign = -1;
219 m(0) = 2*radius*rnd.get_random_double()-radius;
220 m(1) = sign*sqrt(radius*radius - m(0)*m(0));
221
222 // add this sample to our set of training samples
223 samples.push_back(m);
224 labels.push_back(2);
225 }
226
227 // make some samples in a circle around the point (25,25)
228 radius = 4.0;
229 for (long i = 0; i < num+30; ++i)
230 {
231 double sign = 1;
232 if (rnd.get_random_double() < 0.5)
233 sign = -1;
234 m(0) = 2*radius*rnd.get_random_double()-radius;
235 m(1) = sign*sqrt(radius*radius - m(0)*m(0));
236
237 // translate this point away from the origin
238 m(0) += 25;
239 m(1) += 25;
240
241 // add this sample to our set of training samples
242 samples.push_back(m);

Callers 1

mainFunction · 0.70

Calls 3

get_random_doubleMethod · 0.80
sqrtFunction · 0.50
push_backMethod · 0.45

Tested by

no test coverage detected