Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
ec2f30b6
Commit
ec2f30b6
authored
Apr 29, 2012
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added missing asserts and requires clauses
parent
2ab7afe9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
101 additions
and
13 deletions
+101
-13
find_max_factor_graph_potts.h
dlib/graph_cuts/find_max_factor_graph_potts.h
+96
-13
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
typename
potts_model
>
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
;
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
)
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
bool
label_i
=
(
g
.
get_label
(
i
)
!=
0
);
const
bool
label_idx2
=
(
g
.
get_label
(
idx2
)
!=
0
);
const
unsigned
long
idx2
=
prob
.
get_neighbor
(
i
,
n
);
const
bool
label_i
=
(
prob
.
get_label
(
i
)
!=
0
);
const
bool
label_idx2
=
(
prob
.
get_label
(
idx2
)
!=
0
);
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
// 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
));
#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
;
for
(
unsigned
long
i
=
0
;
i
<
g
.
number_of_nodes
();
++
i
)
{
...
...
@@ -498,12 +540,36 @@ namespace dlib
typename
potts_model
>
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
;
dlib
::
impl
::
potts_flow_graph
<
potts_model
>
pfg
(
m
);
mc
(
pfg
,
m
.
number_of_nodes
(),
m
.
number_of_nodes
()
+
1
);
dlib
::
impl
::
potts_flow_graph
<
potts_model
>
pfg
(
prob
);
mc
(
pfg
,
prob
.
number_of_nodes
(),
prob
.
number_of_nodes
()
+
1
);
}
// ----------------------------------------------------------------------------------------
...
...
@@ -526,6 +592,23 @@ namespace dlib
// 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
));
#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
);
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
- potts_problem == an object with an interface compatible with the potts_problem
object defined at the top of this file.
- 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)
ensures
- computes the model score for the given potts_problem. We define this
...
...
@@ -206,6 +207,8 @@ namespace dlib
- 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_contains_length_one_cycle(g) == false
- for all valid i and j:
- edge(g,i,j) >= 0
ensures
- This function does the same thing as the version of potts_model_score()
defined above, except that this version operates on a dlib::graph
...
...
@@ -264,6 +267,8 @@ namespace dlib
- 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_contains_length_one_cycle(g) == false
- for all valid i and j:
- edge(g,i,j) >= 0
ensures
- This routine simply converts g into a potts_problem and calls the
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