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
ec2f30b6
Commit
ec2f30b6
authored
Apr 29, 2012
by
Davis King
Browse files
Added missing asserts and requires clauses
parent
2ab7afe9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
101 additions
and
13 deletions
+101
-13
dlib/graph_cuts/find_max_factor_graph_potts.h
dlib/graph_cuts/find_max_factor_graph_potts.h
+96
-13
dlib/graph_cuts/find_max_factor_graph_potts_abstract.h
dlib/graph_cuts/find_max_factor_graph_potts_abstract.h
+5
-0
No files found.
dlib/graph_cuts/find_max_factor_graph_potts.h
View file @
ec2f30b6
...
@@ -423,26 +423,51 @@ namespace dlib
...
@@ -423,26 +423,51 @@ namespace dlib
typename
potts_model
typename
potts_model
>
>
typename
potts_model
::
value_type
potts_model_score
(
typename
potts_model
::
value_type
potts_model_score
(
const
potts_model
&
g
const
potts_model
&
prob
)
)
{
{
#ifdef ENABLE_ASSERTS
for
(
unsigned
long
i
=
0
;
i
<
prob
.
number_of_nodes
();
++
i
)
{
for
(
unsigned
long
jj
=
0
;
jj
<
prob
.
number_of_neighbors
(
i
);
++
jj
)
{
unsigned
long
j
=
prob
.
get_neighbor
(
i
,
jj
);
DLIB_ASSERT
(
prob
.
factor_value_disagreement
(
i
,
j
)
>=
0
,
"
\t
value_type potts_model_score(prob)"
<<
"
\n\t
Invalid inputs were given to this function."
<<
"
\n\t
i: "
<<
i
<<
"
\n\t
j: "
<<
j
<<
"
\n\t
prob.factor_value_disagreement(i,j): "
<<
prob
.
factor_value_disagreement
(
i
,
j
)
);
DLIB_ASSERT
(
prob
.
factor_value_disagreement
(
i
,
j
)
==
prob
.
factor_value_disagreement
(
j
,
i
),
"
\t
value_type potts_model_score(prob)"
<<
"
\n\t
Invalid inputs were given to this function."
<<
"
\n\t
i: "
<<
i
<<
"
\n\t
j: "
<<
j
<<
"
\n\t
prob.factor_value_disagreement(i,j): "
<<
prob
.
factor_value_disagreement
(
i
,
j
)
<<
"
\n\t
prob.factor_value_disagreement(j,i): "
<<
prob
.
factor_value_disagreement
(
j
,
i
)
);
}
}
#endif
typename
potts_model
::
value_type
score
=
0
;
typename
potts_model
::
value_type
score
=
0
;
for
(
unsigned
long
i
=
0
;
i
<
g
.
number_of_nodes
();
++
i
)
for
(
unsigned
long
i
=
0
;
i
<
prob
.
number_of_nodes
();
++
i
)
{
{
const
bool
label
=
(
g
.
get_label
(
i
)
!=
0
);
const
bool
label
=
(
prob
.
get_label
(
i
)
!=
0
);
if
(
label
)
if
(
label
)
score
+=
g
.
factor_value
(
i
);
score
+=
prob
.
factor_value
(
i
);
}
}
for
(
unsigned
long
i
=
0
;
i
<
g
.
number_of_nodes
();
++
i
)
for
(
unsigned
long
i
=
0
;
i
<
prob
.
number_of_nodes
();
++
i
)
{
{
for
(
unsigned
long
n
=
0
;
n
<
g
.
number_of_neighbors
(
i
);
++
n
)
for
(
unsigned
long
n
=
0
;
n
<
prob
.
number_of_neighbors
(
i
);
++
n
)
{
{
const
unsigned
long
idx2
=
g
.
get_neighbor
(
i
,
n
);
const
unsigned
long
idx2
=
prob
.
get_neighbor
(
i
,
n
);
const
bool
label_i
=
(
g
.
get_label
(
i
)
!=
0
);
const
bool
label_i
=
(
prob
.
get_label
(
i
)
!=
0
);
const
bool
label_idx2
=
(
g
.
get_label
(
idx2
)
!=
0
);
const
bool
label_idx2
=
(
prob
.
get_label
(
idx2
)
!=
0
);
if
(
label_i
!=
label_idx2
&&
i
<
idx2
)
if
(
label_i
!=
label_idx2
&&
i
<
idx2
)
score
-=
g
.
factor_value_disagreement
(
i
,
idx2
);
score
-=
prob
.
factor_value_disagreement
(
i
,
idx2
);
}
}
}
}
...
@@ -469,6 +494,23 @@ namespace dlib
...
@@ -469,6 +494,23 @@ namespace dlib
// The edges and node's have to use the same type to represent factor weights!
// The edges and node's have to use the same type to represent factor weights!
COMPILE_TIME_ASSERT
((
is_same_type
<
edge_type
,
type
>::
value
==
true
));
COMPILE_TIME_ASSERT
((
is_same_type
<
edge_type
,
type
>::
value
==
true
));
#ifdef ENABLE_ASSERTS
for
(
unsigned
long
i
=
0
;
i
<
g
.
number_of_nodes
();
++
i
)
{
for
(
unsigned
long
jj
=
0
;
jj
<
g
.
node
(
i
).
number_of_neighbors
();
++
jj
)
{
unsigned
long
j
=
g
.
node
(
i
).
neighbor
(
jj
).
index
();
DLIB_ASSERT
(
edge
(
g
,
i
,
j
)
>=
0
,
"
\t
edge_type potts_model_score(g,labels)"
<<
"
\n\t
Invalid inputs were given to this function."
<<
"
\n\t
i: "
<<
i
<<
"
\n\t
j: "
<<
j
<<
"
\n\t
edge(g,i,j): "
<<
edge
(
g
,
i
,
j
)
);
}
}
#endif
typename
graph_type
::
edge_type
score
=
0
;
typename
graph_type
::
edge_type
score
=
0
;
for
(
unsigned
long
i
=
0
;
i
<
g
.
number_of_nodes
();
++
i
)
for
(
unsigned
long
i
=
0
;
i
<
g
.
number_of_nodes
();
++
i
)
{
{
...
@@ -498,12 +540,36 @@ namespace dlib
...
@@ -498,12 +540,36 @@ namespace dlib
typename
potts_model
typename
potts_model
>
>
void
find_max_factor_graph_potts
(
void
find_max_factor_graph_potts
(
potts_model
&
m
potts_model
&
prob
)
)
{
{
#ifdef ENABLE_ASSERTS
for
(
unsigned
long
i
=
0
;
i
<
prob
.
number_of_nodes
();
++
i
)
{
for
(
unsigned
long
jj
=
0
;
jj
<
prob
.
number_of_neighbors
(
i
);
++
jj
)
{
unsigned
long
j
=
prob
.
get_neighbor
(
i
,
jj
);
DLIB_ASSERT
(
prob
.
factor_value_disagreement
(
i
,
j
)
>=
0
,
"
\t
void find_max_factor_graph_potts(prob)"
<<
"
\n\t
Invalid inputs were given to this function."
<<
"
\n\t
i: "
<<
i
<<
"
\n\t
j: "
<<
j
<<
"
\n\t
prob.factor_value_disagreement(i,j): "
<<
prob
.
factor_value_disagreement
(
i
,
j
)
);
DLIB_ASSERT
(
prob
.
factor_value_disagreement
(
i
,
j
)
==
prob
.
factor_value_disagreement
(
j
,
i
),
"
\t
void find_max_factor_graph_potts(prob)"
<<
"
\n\t
Invalid inputs were given to this function."
<<
"
\n\t
i: "
<<
i
<<
"
\n\t
j: "
<<
j
<<
"
\n\t
prob.factor_value_disagreement(i,j): "
<<
prob
.
factor_value_disagreement
(
i
,
j
)
<<
"
\n\t
prob.factor_value_disagreement(j,i): "
<<
prob
.
factor_value_disagreement
(
j
,
i
)
);
}
}
#endif
min_cut
mc
;
min_cut
mc
;
dlib
::
impl
::
potts_flow_graph
<
potts_model
>
pfg
(
m
);
dlib
::
impl
::
potts_flow_graph
<
potts_model
>
pfg
(
prob
);
mc
(
pfg
,
m
.
number_of_nodes
(),
m
.
number_of_nodes
()
+
1
);
mc
(
pfg
,
prob
.
number_of_nodes
(),
prob
.
number_of_nodes
()
+
1
);
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
@@ -526,6 +592,23 @@ namespace dlib
...
@@ -526,6 +592,23 @@ namespace dlib
// The edges and node's have to use the same type to represent factor weights!
// The edges and node's have to use the same type to represent factor weights!
COMPILE_TIME_ASSERT
((
is_same_type
<
edge_type
,
type
>::
value
==
true
));
COMPILE_TIME_ASSERT
((
is_same_type
<
edge_type
,
type
>::
value
==
true
));
#ifdef ENABLE_ASSERTS
for
(
unsigned
long
i
=
0
;
i
<
g
.
number_of_nodes
();
++
i
)
{
for
(
unsigned
long
jj
=
0
;
jj
<
g
.
node
(
i
).
number_of_neighbors
();
++
jj
)
{
unsigned
long
j
=
g
.
node
(
i
).
neighbor
(
jj
).
index
();
DLIB_ASSERT
(
edge
(
g
,
i
,
j
)
>=
0
,
"
\t
void find_max_factor_graph_potts(g,labels)"
<<
"
\n\t
Invalid inputs were given to this function."
<<
"
\n\t
i: "
<<
i
<<
"
\n\t
j: "
<<
j
<<
"
\n\t
edge(g,i,j): "
<<
edge
(
g
,
i
,
j
)
);
}
}
#endif
dlib
::
impl
::
general_potts_problem
<
graph_type
>
gg
(
g
,
labels
);
dlib
::
impl
::
general_potts_problem
<
graph_type
>
gg
(
g
,
labels
);
find_max_factor_graph_potts
(
gg
);
find_max_factor_graph_potts
(
gg
);
...
...
dlib/graph_cuts/find_max_factor_graph_potts_abstract.h
View file @
ec2f30b6
...
@@ -172,6 +172,7 @@ namespace dlib
...
@@ -172,6 +172,7 @@ namespace dlib
- potts_problem == an object with an interface compatible with the potts_problem
- potts_problem == an object with an interface compatible with the potts_problem
object defined at the top of this file.
object defined at the top of this file.
- for all valid i and j:
- for all valid i and j:
- prob.factor_value_disagreement(i,j) >= 0
- prob.factor_value_disagreement(i,j) == prob.factor_value_disagreement(j,i)
- prob.factor_value_disagreement(i,j) == prob.factor_value_disagreement(j,i)
ensures
ensures
- computes the model score for the given potts_problem. We define this
- computes the model score for the given potts_problem. We define this
...
@@ -206,6 +207,8 @@ namespace dlib
...
@@ -206,6 +207,8 @@ namespace dlib
- graph_type::edge_type is some signed type such as int or double
- graph_type::edge_type is some signed type such as int or double
- graph_type::type must be the same type as graph_type::edge_type
- graph_type::type must be the same type as graph_type::edge_type
- graph_contains_length_one_cycle(g) == false
- graph_contains_length_one_cycle(g) == false
- for all valid i and j:
- edge(g,i,j) >= 0
ensures
ensures
- This function does the same thing as the version of potts_model_score()
- This function does the same thing as the version of potts_model_score()
defined above, except that this version operates on a dlib::graph
defined above, except that this version operates on a dlib::graph
...
@@ -264,6 +267,8 @@ namespace dlib
...
@@ -264,6 +267,8 @@ namespace dlib
- graph_type::edge_type is some signed type such as int or double
- graph_type::edge_type is some signed type such as int or double
- graph_type::type must be the same type as graph_type::edge_type
- graph_type::type must be the same type as graph_type::edge_type
- graph_contains_length_one_cycle(g) == false
- graph_contains_length_one_cycle(g) == false
- for all valid i and j:
- edge(g,i,j) >= 0
ensures
ensures
- This routine simply converts g into a potts_problem and calls the
- This routine simply converts g into a potts_problem and calls the
version of find_max_factor_graph_potts() defined above on it. Therefore,
version of find_max_factor_graph_potts() defined above on it. Therefore,
...
...
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