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

Function main

examples/graph_labeling_ex.cpp:174–258  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

172// ----------------------------------------------------------------------------------------
173
174int main()
175{
176 try
177 {
178 // Get the training samples we defined above.
179 dlib::array<graph_type> samples;
180 std::vector<std::vector<bool> > labels;
181 make_training_examples(samples, labels);
182
183
184 // Create a structural SVM trainer for graph labeling problems. The vector_type
185 // needs to be set to a type capable of holding node or edge vectors.
186 typedef matrix<double,0,1> vector_type;
187 structural_graph_labeling_trainer<vector_type> trainer;
188 // This is the usual SVM C parameter. Larger values make the trainer try
189 // harder to fit the training data but might result in overfitting. You
190 // should set this value to whatever gives the best cross-validation results.
191 trainer.set_c(10);
192
193 // Do 3-fold cross-validation and print the results. In this case it will
194 // indicate that all nodes were correctly classified.
195 cout << "3-fold cross-validation: " << cross_validate_graph_labeling_trainer(trainer, samples, labels, 3) << endl;
196
197 // Since the trainer is working well. Let's have it make a graph_labeler
198 // based on the training data.
199 graph_labeler<vector_type> labeler = trainer.train(samples, labels);
200
201
202 /*
203 Let's try the graph_labeler on a new test graph. In particular, let's
204 use one with 5 nodes as shown below:
205
206 (0 F)-----(1 T)
207 | |
208 | |
209 | |
210 (3 T)-----(2 T)------(4 T)
211
212 I have annotated each node with either T or F to indicate the correct
213 output (true or false).
214 */
215 graph_type g;
216 g.set_number_of_nodes(5);
217 g.node(0).data = 1, 0; // Node data indicates a false node.
218 g.node(1).data = 0, 1; // Node data indicates a true node.
219 g.node(2).data = 0, 0; // Node data is ambiguous.
220 g.node(3).data = 0, 0; // Node data is ambiguous.
221 g.node(4).data = 0.1, 0; // Node data slightly indicates a false node.
222
223 g.add_edge(0,1);
224 g.add_edge(1,2);
225 g.add_edge(2,3);
226 g.add_edge(3,0);
227 g.add_edge(2,4);
228
229 // Set the edges up so nodes 1, 2, 3, and 4 are all strongly connected.
230 edge(g,0,1) = 0;
231 edge(g,1,2) = 1;

Callers

nothing calls this directly

Calls 6

make_training_examplesFunction · 0.70
set_cMethod · 0.45
trainMethod · 0.45
sizeMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected