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
ec1997be
Commit
ec1997be
authored
Apr 30, 2012
by
Davis King
Browse files
Filled out the implementation of is_graph_labeling_problem().
parent
3321b43e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
5 deletions
+49
-5
dlib/svm/structural_svm_graph_labeling_problem.h
dlib/svm/structural_svm_graph_labeling_problem.h
+49
-5
No files found.
dlib/svm/structural_svm_graph_labeling_problem.h
View file @
ec1997be
...
@@ -30,8 +30,8 @@ namespace dlib
...
@@ -30,8 +30,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_type::type and graph_type::edge_type are either dlib::matrix types
- graph_type::type and graph_type::edge_type are either
both
dlib::matrix types
capable of containing column vectors or some kind of sparse vector type.
capable of containing column vectors or
both
some kind of sparse vector type.
ensures
ensures
- Note that a graph labeling problem is a task to learn a binary classifier which
- Note that a graph labeling problem is a task to learn a binary classifier which
predicts the correct label for each node in the provided graphs. Additionally,
predicts the correct label for each node in the provided graphs. Additionally,
...
@@ -43,13 +43,10 @@ namespace dlib
...
@@ -43,13 +43,10 @@ namespace dlib
example graphs of connected nodes while labels should indicate the desired
example graphs of connected nodes while labels should indicate the desired
label of each node. The precise requirements for a valid graph labeling
label of each node. The precise requirements for a valid graph labeling
problem are listed below.
problem are listed below.
- There is at least one node with a label of 0 and one with a label != 0.
- This function returns true if all of the following are true and false otherwise:
- This function returns true if all of the following are true and false otherwise:
- is_learning_problem(samples, labels) == true
- is_learning_problem(samples, labels) == true
- All the vectors stored on the edges of each graph in samples
- All the vectors stored on the edges of each graph in samples
contain only values which are >= 0.
contain only values which are >= 0.
- graph_type::type and graph_type::edge_type either both represent
dlib::matrix column vectors or are both sparse vectors.
- for all valid i:
- for all valid i:
- graph_contains_length_one_cycle(samples[i]) == false
- graph_contains_length_one_cycle(samples[i]) == false
- samples[i].number_of_nodes() == labels[i].size()
- samples[i].number_of_nodes() == labels[i].size()
...
@@ -61,9 +58,56 @@ namespace dlib
...
@@ -61,9 +58,56 @@ namespace dlib
- All vectors have non-zero size. That is, they have more than 0 dimensions.
- All vectors have non-zero size. That is, they have more than 0 dimensions.
!*/
!*/
{
{
using
namespace
dlib
::
sparse_vector
;
using
namespace
dlib
;
if
(
!
is_learning_problem
(
samples
,
labels
))
return
false
;
const
bool
ismat
=
is_matrix
<
typename
graph_type
::
type
>::
value
;
// these are -1 until assigned with a value
long
node_dims
=
-
1
;
long
edge_dims
=
-
1
;
for
(
unsigned
long
i
=
0
;
i
<
samples
.
size
();
++
i
)
{
if
(
samples
[
i
].
number_of_nodes
()
!=
labels
[
i
].
size
())
return
false
;
if
(
graph_contains_length_one_cycle
(
samples
[
i
]))
return
false
;
for
(
unsigned
long
j
=
0
;
j
<
samples
[
i
].
number_of_nodes
();
++
j
)
{
if
(
samples
[
i
].
node
(
j
).
data
.
size
()
==
0
)
return
false
;
if
(
ismat
&&
node_dims
==
-
1
)
node_dims
=
samples
[
i
].
node
(
j
).
data
.
size
();
// all nodes must have vectors of the same size.
if
(
ismat
&&
(
long
)
samples
[
i
].
node
(
j
).
data
.
size
()
!=
node_dims
)
return
false
;
for
(
unsigned
long
n
=
0
;
n
<
samples
[
i
].
node
(
j
).
number_of_neighbors
();
++
n
)
{
if
(
ismat
&&
samples
[
i
].
node
(
j
).
edge
(
n
).
size
()
==
0
)
return
false
;
if
(
min
(
samples
[
i
].
node
(
j
).
edge
(
n
))
<
0
)
return
false
;
if
(
ismat
&&
edge_dims
==
-
1
)
edge_dims
=
samples
[
i
].
node
(
j
).
edge
(
n
).
size
();
// all edges must have vectors of the same size.
if
(
ismat
&&
(
long
)
samples
[
i
].
node
(
j
).
edge
(
n
).
size
()
!=
edge_dims
)
return
false
;
}
}
}
return
true
;
return
true
;
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
namespace
impl
namespace
impl
...
...
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