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

Function make_training_examples

examples/graph_labeling_ex.cpp:61–170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59 typename labels_type
60 >
61void make_training_examples(
62 dlib::array<graph_type>& samples,
63 labels_type& labels
64)
65{
66 /*
67 This function makes 3 graphs we will use for training. All of them
68 will contain 4 nodes and have the structure shown below:
69
70 (0)-----(1)
71 | |
72 | |
73 | |
74 (3)-----(2)
75
76 In this example, each node has a 2-D vector. The first element of this vector
77 is 1 when the node should have a label of false while the second element has
78 a value of 1 when the node should have a label of true. Additionally, the
79 edge vectors will contain a value of 1 when the nodes connected by the edge
80 should share the same label and a value of 0 otherwise.
81
82 We want to see that the machine learning method is able to figure out how
83 these features relate to the labels. If it is successful it will create a
84 graph_labeler which can predict the correct labels for these and other
85 similarly constructed graphs.
86
87 Finally, note that these tools require all values in the edge vectors to be >= 0.
88 However, the node vectors may contain both positive and negative values.
89 */
90
91 samples.clear();
92 labels.clear();
93
94 std::vector<bool> label;
95 graph_type g;
96
97 // ---------------------------
98 g.set_number_of_nodes(4);
99 label.resize(g.number_of_nodes());
100 // store the vector [0,1] into node 0. Also label it as true.
101 g.node(0).data = 0, 1; label[0] = true;
102 // store the vector [0,0] into node 1.
103 g.node(1).data = 0, 0; label[1] = true; // Note that this node's vector doesn't tell us how to label it.
104 // We need to take the edges into account to get it right.
105 // store the vector [1,0] into node 2.
106 g.node(2).data = 1, 0; label[2] = false;
107 // store the vector [0,0] into node 3.
108 g.node(3).data = 0, 0; label[3] = false;
109
110 // Add the 4 edges as shown in the ASCII art above.
111 g.add_edge(0,1);
112 g.add_edge(1,2);
113 g.add_edge(2,3);
114 g.add_edge(3,0);
115
116 // set the 1-D vector for the edge between node 0 and 1 to the value of 1.
117 edge(g,0,1) = 1;
118 // set the 1-D vector for the edge between node 1 and 2 to the value of 0.

Callers 1

mainFunction · 0.70

Calls 4

clearMethod · 0.45
resizeMethod · 0.45
number_of_nodesMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected