Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
bcb84de4
Commit
bcb84de4
authored
May 02, 2012
by
Davis King
Browse files
Added asserts
parent
9926bc92
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
4 deletions
+68
-4
dlib/svm/graph_labeler.h
dlib/svm/graph_labeler.h
+66
-4
dlib/svm/graph_labeler_abstract.h
dlib/svm/graph_labeler_abstract.h
+2
-0
No files found.
dlib/svm/graph_labeler.h
View file @
bcb84de4
...
@@ -43,6 +43,13 @@ namespace dlib
...
@@ -43,6 +43,13 @@ namespace dlib
edge_weights
(
edge_weights_
),
edge_weights
(
edge_weights_
),
node_weights
(
node_weights_
)
node_weights
(
node_weights_
)
{
{
// make sure requires clause is not broken
DLIB_ASSERT
(
min
(
edge_weights
)
>=
0
,
"
\t
graph_labeler::graph_labeler()"
<<
"
\n\t
Invalid inputs were given to this function."
<<
"
\n\t
min(edge_weights): "
<<
min
(
edge_weights
)
<<
"
\n\t
this: "
<<
this
);
}
}
const
vector_type
&
get_edge_weights
(
const
vector_type
&
get_edge_weights
(
...
@@ -53,18 +60,73 @@ namespace dlib
...
@@ -53,18 +60,73 @@ namespace dlib
template
<
typename
graph_type
>
template
<
typename
graph_type
>
void
operator
()
(
void
operator
()
(
const
graph_type
&
samp
,
const
graph_type
&
samp
le
,
result_type
&
labels
result_type
&
labels
)
const
)
const
{
{
// make sure requires clause is not broken
#ifdef ENABLE_ASSERTS
DLIB_ASSERT
(
get_edge_weights
().
size
()
!=
0
&&
get_node_weights
().
size
()
!=
0
&&
graph_contains_length_one_cycle
(
sample
)
==
false
,
"
\t
void graph_labeler::operator()"
<<
"
\n\t
Invalid inputs were given to this function."
<<
"
\n\t
get_edge_weights().size(): "
<<
get_edge_weights
().
size
()
<<
"
\n\t
get_node_weights().size(): "
<<
get_node_weights
().
size
()
<<
"
\n\t
graph_contains_length_one_cycle(sample): "
<<
graph_contains_length_one_cycle
(
sample
)
<<
"
\n\t
this: "
<<
this
);
for
(
unsigned
long
i
=
0
;
i
<
sample
.
number_of_nodes
();
++
i
)
{
if
(
is_matrix
<
vector_type
>::
value
&&
is_matrix
<
typename
graph_type
::
type
>::
value
)
{
// check that dot() is legal.
DLIB_ASSERT
(
get_node_weights
().
size
()
==
sample
.
node
(
i
).
data
.
size
(),
"
\t
void graph_labeler::operator()"
<<
"
\n\t
The size of the node weight vector must match the one in the node."
<<
"
\n\t
get_node_weights().size(): "
<<
get_node_weights
().
size
()
<<
"
\n\t
sample.node(i).data.size(): "
<<
sample
.
node
(
i
).
data
.
size
()
<<
"
\n\t
i: "
<<
i
<<
"
\n\t
this: "
<<
this
);
}
for
(
unsigned
long
n
=
0
;
n
<
sample
.
node
(
i
).
number_of_neighbors
();
++
n
)
{
if
(
is_matrix
<
vector_type
>::
value
&&
is_matrix
<
typename
graph_type
::
edge_type
>::
value
)
{
// check that dot() is legal.
DLIB_ASSERT
(
get_edge_weights
().
size
()
==
sample
.
node
(
i
).
edge
(
n
).
size
(),
"
\t
void graph_labeler::operator()"
<<
"
\n\t
The size of the edge weight vector must match the one in graph's edge."
<<
"
\n\t
get_edge_weights().size(): "
<<
get_edge_weights
().
size
()
<<
"
\n\t
sample.node(i).edge(n).size(): "
<<
sample
.
node
(
i
).
edge
(
n
).
size
()
<<
"
\n\t
i: "
<<
i
<<
"
\n\t
this: "
<<
this
);
}
DLIB_ASSERT
(
min
(
sample
.
node
(
i
).
edge
(
n
))
>=
0
,
"
\t
void graph_labeler::operator()"
<<
"
\n\t
Invalid inputs were given to this function."
<<
"
\n\t
min(sample.node(i).edge(n)): "
<<
min
(
sample
.
node
(
i
).
edge
(
n
))
<<
"
\n\t
i: "
<<
i
<<
"
\n\t
n: "
<<
n
<<
"
\n\t
this: "
<<
this
);
}
}
#endif
labels
.
clear
();
labels
.
clear
();
graph
<
double
,
double
>::
kernel_1a
g
;
graph
<
double
,
double
>::
kernel_1a
g
;
copy_graph_structure
(
samp
,
g
);
copy_graph_structure
(
samp
le
,
g
);
for
(
unsigned
long
i
=
0
;
i
<
g
.
number_of_nodes
();
++
i
)
for
(
unsigned
long
i
=
0
;
i
<
g
.
number_of_nodes
();
++
i
)
{
{
g
.
node
(
i
).
data
=
dot
(
node_weights
,
samp
.
node
(
i
).
data
);
g
.
node
(
i
).
data
=
dot
(
node_weights
,
samp
le
.
node
(
i
).
data
);
for
(
unsigned
long
n
=
0
;
n
<
g
.
node
(
i
).
number_of_neighbors
();
++
n
)
for
(
unsigned
long
n
=
0
;
n
<
g
.
node
(
i
).
number_of_neighbors
();
++
n
)
{
{
...
@@ -72,7 +134,7 @@ namespace dlib
...
@@ -72,7 +134,7 @@ namespace dlib
// Don't compute an edge weight more than once.
// Don't compute an edge weight more than once.
if
(
i
<
j
)
if
(
i
<
j
)
{
{
g
.
node
(
i
).
edge
(
n
)
=
dot
(
edge_weights
,
samp
.
node
(
i
).
edge
(
n
));
g
.
node
(
i
).
edge
(
n
)
=
dot
(
edge_weights
,
samp
le
.
node
(
i
).
edge
(
n
));
}
}
}
}
...
...
dlib/svm/graph_labeler_abstract.h
View file @
bcb84de4
...
@@ -99,6 +99,8 @@ namespace dlib
...
@@ -99,6 +99,8 @@ namespace dlib
requires
requires
- graph_type is an implementation of dlib/graph/graph_kernel_abstract.h
- graph_type is an implementation of dlib/graph/graph_kernel_abstract.h
- graph_contains_length_one_cycle(sample) == false
- graph_contains_length_one_cycle(sample) == false
- #get_edge_weights().size() != 0
- #get_node_weights().size() != 0
- for all valid i and j:
- for all valid i and j:
- min(edge(sample,i,j)) >= 0
- min(edge(sample,i,j)) >= 0
- it must be legal to call dot(edge(sample,i,j), get_edge_weights())
- it must be legal to call dot(edge(sample,i,j), get_edge_weights())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment