Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tiago Peixoto
graph-tool
Commits
212f2f2f
Commit
212f2f2f
authored
Aug 19, 2015
by
Tiago Peixoto
Browse files
transition(): Fix matrix transposition
parent
33b9efb0
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/graph/spectral/graph_transition.cc
View file @
212f2f2f
...
...
@@ -37,7 +37,7 @@ void transition(GraphInterface& g, boost::any index, boost::any weight,
if
(
!
belongs
<
vertex_scalar_properties
>
()(
index
))
throw
ValueException
(
"index vertex property must have a scalar value type"
);
typedef
ConstantPropertyMap
<
double
,
GraphInterface
::
edge_t
>
weight_map_t
;
typedef
ConstantPropertyMap
<
size_t
,
GraphInterface
::
edge_t
>
weight_map_t
;
typedef
mpl
::
push_back
<
edge_scalar_properties
,
weight_map_t
>::
type
weight_props_t
;
...
...
@@ -45,7 +45,7 @@ void transition(GraphInterface& g, boost::any index, boost::any weight,
throw
ValueException
(
"weight edge property must have a scalar value type"
);
if
(
weight
.
empty
())
weight
=
weight_map_t
(
1
.0
);
weight
=
weight_map_t
(
1
);
multi_array_ref
<
double
,
1
>
data
=
get_array
<
double
,
1
>
(
odata
);
multi_array_ref
<
int32_t
,
1
>
i
=
get_array
<
int32_t
,
1
>
(
oi
);
...
...
src/graph/spectral/graph_transition.hh
View file @
212f2f2f
...
...
@@ -27,22 +27,21 @@ namespace graph_tool
using
namespace
boost
;
template
<
class
Graph
,
class
Weight
,
class
EdgeSelector
>
template
<
class
Graph
,
class
Weight
>
typename
property_traits
<
Weight
>::
value_type
sum_degree
(
Graph
&
g
,
typename
graph_traits
<
Graph
>::
vertex_descriptor
v
,
Weight
w
,
EdgeSelector
)
const
Weight
&
w
)
{
typename
property_traits
<
Weight
>::
value_type
sum
=
0
;
typename
EdgeSelector
::
type
e
,
e_end
;
for
(
tie
(
e
,
e_end
)
=
EdgeSelector
::
get_edges
(
v
,
g
);
e
!=
e_end
;
++
e
)
sum
+=
get
(
w
,
*
e
);
for
(
const
auto
&
e
:
out_edges_range
(
v
,
g
))
sum
+=
get
(
w
,
e
);
return
sum
;
}
template
<
class
Graph
,
class
EdgeSelector
>
double
template
<
class
Graph
>
size_t
sum_degree
(
Graph
&
g
,
typename
graph_traits
<
Graph
>::
vertex_descriptor
v
,
ConstantPropertyMap
<
double
,
GraphInterface
::
edge_t
>
w
,
out_edge_iteratorS
<
Graph
>
)
const
ConstantPropertyMap
<
size_t
,
GraphInterface
::
edge_t
>
&
)
{
return
out_degreeS
()(
v
,
g
);
}
...
...
@@ -58,12 +57,12 @@ struct get_transition
int
pos
=
0
;
for
(
auto
v
:
vertices_range
(
g
))
{
double
k
=
sum_degree
(
g
,
v
,
weight
,
out_edge_iteratorS
<
Graph
>
()
);
auto
k
=
sum_degree
(
g
,
v
,
weight
);
for
(
const
auto
&
e
:
out_edges_range
(
v
,
g
))
{
data
[
pos
]
=
weight
[
e
]
/
k
;
i
[
pos
]
=
get
(
index
,
source
(
e
,
g
));
j
[
pos
]
=
get
(
index
,
target
(
e
,
g
));
data
[
pos
]
=
double
(
weight
[
e
]
)
/
k
;
j
[
pos
]
=
get
(
index
,
source
(
e
,
g
));
i
[
pos
]
=
get
(
index
,
target
(
e
,
g
));
++
pos
;
}
}
...
...
src/graph_tool/spectral/__init__.py
View file @
212f2f2f
...
...
@@ -446,7 +446,7 @@ def transition(g, weight=None, index=None):
.. note::
For directed graphs the definition above means that the entry
:math:`T_{i
,
j}` corresponds to the directed edge :math:`j\to
:math:`T_{ij}` corresponds to the directed edge :math:`j\to
i`. Although this is a typical definition in network and graph theory
literature, many also use the transpose of this matrix.
...
...
@@ -500,9 +500,6 @@ def transition(g, weight=None, index=None):
i
=
numpy
.
zeros
(
E
,
dtype
=
"int32"
)
j
=
numpy
.
zeros
(
E
,
dtype
=
"int32"
)
if
g
.
is_directed
():
g
=
GraphView
(
g
,
reversed
=
True
,
skip_properties
=
True
)
libgraph_tool_spectral
.
transition
(
g
.
_Graph__graph
,
_prop
(
"v"
,
g
,
index
),
_prop
(
"e"
,
g
,
weight
),
data
,
i
,
j
)
...
...
Write
Preview
Supports
Markdown
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