Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Tiago Peixoto
graph-tool
Commits
9c825c08
Commit
9c825c08
authored
May 18, 2009
by
Tiago Peixoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix absolute trust weighting and add reverse trust
parent
b93b5010
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
17 deletions
+34
-17
src/graph/centrality/graph_absolute_trust.cc
src/graph/centrality/graph_absolute_trust.cc
+4
-4
src/graph/centrality/graph_absolute_trust.hh
src/graph/centrality/graph_absolute_trust.hh
+17
-11
src/graph_tool/centrality/__init__.py
src/graph_tool/centrality/__init__.py
+13
-2
No files found.
src/graph/centrality/graph_absolute_trust.cc
View file @
9c825c08
...
@@ -18,7 +18,6 @@
...
@@ -18,7 +18,6 @@
#include "graph_filtering.hh"
#include "graph_filtering.hh"
#include <boost/python.hpp>
#include <boost/python.hpp>
#include <boost/lambda/bind.hpp>
#include "graph.hh"
#include "graph.hh"
#include "graph_selectors.hh"
#include "graph_selectors.hh"
...
@@ -33,7 +32,8 @@ using namespace boost;
...
@@ -33,7 +32,8 @@ using namespace boost;
using
namespace
graph_tool
;
using
namespace
graph_tool
;
void
absolute_trust
(
GraphInterface
&
g
,
int64_t
source
,
boost
::
any
c
,
void
absolute_trust
(
GraphInterface
&
g
,
int64_t
source
,
boost
::
any
c
,
boost
::
any
t
,
double
epslon
,
size_t
max_iter
,
size_t
seed
)
boost
::
any
t
,
double
epslon
,
size_t
max_iter
,
bool
reversed
,
size_t
seed
)
{
{
rng_t
rng
(
static_cast
<
rng_t
::
result_type
>
(
seed
));
rng_t
rng
(
static_cast
<
rng_t
::
result_type
>
(
seed
));
...
@@ -45,8 +45,8 @@ void absolute_trust(GraphInterface& g, int64_t source, boost::any c,
...
@@ -45,8 +45,8 @@ void absolute_trust(GraphInterface& g, int64_t source, boost::any c,
run_action
<>
()
run_action
<>
()
(
g
,
bind
<
void
>
(
g
,
bind
<
void
>
(
get_absolute_trust
(),
(
get_absolute_trust
(),
_1
,
g
.
GetVertexIndex
(),
g
.
GetEdgeIndex
(),
source
,
_2
,
_1
,
g
.
GetVertexIndex
(),
source
,
_2
,
_3
,
epslon
,
max_iter
,
ref
(
rng
)),
_3
,
epslon
,
max_iter
,
reversed
,
ref
(
rng
)),
edge_floating_properties
(),
edge_floating_properties
(),
vertex_floating_vector_properties
())(
c
,
t
);
vertex_floating_vector_properties
())(
c
,
t
);
}
}
...
...
src/graph/centrality/graph_absolute_trust.hh
View file @
9c825c08
...
@@ -33,11 +33,11 @@ using namespace boost;
...
@@ -33,11 +33,11 @@ using namespace boost;
struct
get_absolute_trust
struct
get_absolute_trust
{
{
template
<
class
Graph
,
class
VertexIndex
,
class
EdgeIndex
,
class
TrustMap
,
template
<
class
Graph
,
class
VertexIndex
,
class
TrustMap
,
class
InferredTrustMap
>
class
InferredTrustMap
>
void
operator
()(
Graph
&
g
,
VertexIndex
vertex_index
,
EdgeIndex
edge_index
,
void
operator
()(
Graph
&
g
,
VertexIndex
vertex_index
,
int64_t
source
,
int64_t
source
,
TrustMap
c
,
InferredTrustMap
t
,
TrustMap
c
,
InferredTrustMap
t
,
double
epslon
,
double
epslon
,
size_t
max_iter
,
rng_t
&
rng
)
size_t
max_iter
,
bool
reversed
,
rng_t
&
rng
)
const
const
{
{
typedef
typename
property_traits
<
TrustMap
>::
value_type
c_type
;
typedef
typename
property_traits
<
TrustMap
>::
value_type
c_type
;
...
@@ -86,6 +86,7 @@ struct get_absolute_trust
...
@@ -86,6 +86,7 @@ struct get_absolute_trust
typename
graph_traits
<
Graph
>::
vertex_descriptor
pos
=
v
;
typename
graph_traits
<
Graph
>::
vertex_descriptor
pos
=
v
;
t_type
pos_t
=
1.0
;
t_type
pos_t
=
1.0
;
t_type
pweight
=
1.0
;
v_mark
[
v
][
vertex_index
[
v
]]
=
iter
+
1
;
v_mark
[
v
][
vertex_index
[
v
]]
=
iter
+
1
;
size_t
path_hash
=
salt
;
size_t
path_hash
=
salt
;
...
@@ -133,24 +134,30 @@ struct get_absolute_trust
...
@@ -133,24 +134,30 @@ struct get_absolute_trust
pos
=
target
(
e
,
g
);
pos
=
target
(
e
,
g
);
size_t
posi
=
vertex_index
[
pos
];
size_t
posi
=
vertex_index
[
pos
];
//update current path trust
pos_t
*=
c
[
e
];
if
(
reversed
&&
boost
::
source
(
e
,
g
)
!=
v
)
pweight
*=
c
[
e
];
// get path hash
// get path hash
hash_combine
(
path_hash
,
posi
);
hash_combine
(
path_hash
,
posi
);
if
(
path_set
.
find
(
path_hash
)
==
path_set
.
end
())
if
(
path_set
.
find
(
path_hash
)
==
path_set
.
end
())
{
{
// if new path, modify vertex trust score
path_set
.
insert
(
path_hash
);
path_set
.
insert
(
path_hash
);
//update current path trust, and update new vertex
t_type
pweight
=
pos_t
;
pos_t
*=
c
[
e
];
t_type
old
=
0
;
t_type
old
=
0
;
if
(
t_count
[
v
][
posi
]
>
0
)
if
(
t_count
[
v
][
posi
]
>
0
)
old
=
t
[
v
][
posi
]
/
t_count
[
v
][
posi
];
old
=
t
[
v
][
posi
]
/
t_count
[
v
][
posi
];
t
[
v
][
posi
]
+=
pos_t
*
pweight
;
t
[
v
][
posi
]
+=
pos_t
*
pweight
;
t_count
[
v
][
posi
]
+=
pweight
;
t_count
[
v
][
posi
]
+=
pweight
;
delta
+=
abs
(
old
-
t
[
v
][
posi
]
/
t_count
[
v
][
posi
]);
delta
+=
abs
(
old
-
t
[
v
][
posi
]
/
t_count
[
v
][
posi
]);
}
}
if
(
!
reversed
)
pweight
*=
c
[
e
];
v_mark
[
v
][
posi
]
=
iter
+
1
;
// mark vertex
v_mark
[
v
][
posi
]
=
iter
+
1
;
// mark vertex
}
}
}
}
...
@@ -161,8 +168,7 @@ struct get_absolute_trust
...
@@ -161,8 +168,7 @@ struct get_absolute_trust
}
}
}
}
#pragma omp parallel for default(shared) private(i) \
#pragma omp parallel for default(shared) private(i) schedule(dynamic)
schedule(dynamic)
for
(
i
=
(
source
==
-
1
)
?
0
:
source
;
for
(
i
=
(
source
==
-
1
)
?
0
:
source
;
i
<
((
source
==
-
1
)
?
N
:
source
+
1
);
++
i
)
i
<
((
source
==
-
1
)
?
N
:
source
+
1
);
++
i
)
{
{
...
...
src/graph_tool/centrality/__init__.py
View file @
9c825c08
...
@@ -380,7 +380,7 @@ def eigentrust(g, trust_map, vprop=None, norm=False, epslon=1e-6, max_iter=0,
...
@@ -380,7 +380,7 @@ def eigentrust(g, trust_map, vprop=None, norm=False, epslon=1e-6, max_iter=0,
return
vprop
return
vprop
def
absolute_trust
(
g
,
trust_map
,
source
=
None
,
vprop
=
None
,
epslon
=
0.001
,
def
absolute_trust
(
g
,
trust_map
,
source
=
None
,
vprop
=
None
,
epslon
=
0.001
,
max_iter
=
None
,
seed
=
None
,
ret_iter
=
False
):
max_iter
=
None
,
reversed
=
False
,
seed
=
None
,
ret_iter
=
False
):
r
"""
r
"""
Samples the absolute trust centrality of each vertex in the graph, or only
Samples the absolute trust centrality of each vertex in the graph, or only
for a given source, if one is provided.
for a given source, if one is provided.
...
@@ -402,6 +402,10 @@ def absolute_trust(g, trust_map, source=None, vprop=None, epslon=0.001,
...
@@ -402,6 +402,10 @@ def absolute_trust(g, trust_map, source=None, vprop=None, epslon=0.001,
vertices are below this value.
vertices are below this value.
max_iter : int, optional (default: None)
max_iter : int, optional (default: None)
If supplied, this will limit the total number of iterations.
If supplied, this will limit the total number of iterations.
reversed : bool, optional (default: False)
Calculates the "reversed" trust instead: The direction of the edges are
inverted, but the path weighting is preserved in the original direction
(see Notes below).
seed : int, optional (default: None)
seed : int, optional (default: None)
The initializing seed for the random number generator. If not supplied
The initializing seed for the random number generator. If not supplied
a different random value will be chosen each time.
a different random value will be chosen each time.
...
@@ -499,10 +503,17 @@ def absolute_trust(g, trust_map, source=None, vprop=None, epslon=0.001,
...
@@ -499,10 +503,17 @@ def absolute_trust(g, trust_map, source=None, vprop=None, epslon=0.001,
if
max_iter
==
None
:
if
max_iter
==
None
:
max_iter
=
0
max_iter
=
0
if
reversed
:
g
.
stash_filter
(
reversed
=
True
)
g
.
set_reversed
(
True
)
ic
=
libgraph_tool_centrality
.
\
ic
=
libgraph_tool_centrality
.
\
get_absolute_trust
(
g
.
_Graph__graph
,
source
,
get_absolute_trust
(
g
.
_Graph__graph
,
source
,
_prop
(
"e"
,
g
,
trust_map
),
_prop
(
"v"
,
g
,
vprop
),
_prop
(
"e"
,
g
,
trust_map
),
_prop
(
"v"
,
g
,
vprop
),
epslon
,
max_iter
,
seed
)
epslon
,
max_iter
,
reversed
,
seed
)
if
reversed
:
g
.
pop_filter
(
reversed
=
True
)
if
source
!=
-
1
:
if
source
!=
-
1
:
vprop_temp
.
get_array
()[:]
=
numpy
.
array
(
vprop
[
g
.
vertex
(
source
)])
vprop_temp
.
get_array
()[:]
=
numpy
.
array
(
vprop
[
g
.
vertex
(
source
)])
vprop
=
vprop_temp
vprop
=
vprop_temp
...
...
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