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

Function setup_simple_network

dlib/test/bayes_nets.cpp:30–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28
29 template <typename gtype>
30 void setup_simple_network (
31 gtype& bn
32 )
33 {
34 /*
35 A
36 / \
37 T S
38 */
39
40 using namespace bayes_node_utils;
41
42 bn.set_number_of_nodes(3);
43 bn.add_edge(A, T);
44 bn.add_edge(A, S);
45
46
47 set_node_num_values(bn, A, 2);
48 set_node_num_values(bn, T, 2);
49 set_node_num_values(bn, S, 2);
50
51 assignment parents;
52
53 // set probabilities for node A
54 set_node_probability(bn, A, 1, parents, 0.1);
55 set_node_probability(bn, A, 0, parents, 1-0.1);
56
57 // set probabilities for node T
58 parents.add(A, 1);
59 set_node_probability(bn, T, 1, parents, 0.5);
60 set_node_probability(bn, T, 0, parents, 1-0.5);
61 parents[A] = 0;
62 set_node_probability(bn, T, 1, parents, 0.5);
63 set_node_probability(bn, T, 0, parents, 1-0.5);
64
65 // set probabilities for node S
66 parents[A] = 1;
67 set_node_probability(bn, S, 1, parents, 0.5);
68 set_node_probability(bn, S, 0, parents, 1-0.5);
69 parents[A] = 0;
70 set_node_probability(bn, S, 1, parents, 0.5);
71 set_node_probability(bn, S, 0, parents, 1-0.5);
72
73
74 // test the serialization code here by pushing this network though it
75 ostringstream sout;
76 serialize(bn, sout);
77 bn.clear();
78 DLIB_TEST(bn.number_of_nodes() == 0);
79 istringstream sin(sout.str());
80 deserialize(bn, sin);
81 DLIB_TEST(bn.number_of_nodes() == 3);
82 }
83
84
85 template <typename gtype>

Callers 1

bayes_nets_testFunction · 0.85

Calls 8

set_node_num_valuesFunction · 0.85
set_node_probabilityFunction · 0.85
serializeFunction · 0.70
deserializeFunction · 0.70
addMethod · 0.45
clearMethod · 0.45
number_of_nodesMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected