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
1c9cd293
Commit
1c9cd293
authored
Oct 04, 2017
by
Tiago Peixoto
Browse files
{scalar_}assortatitivy(): Return NaN if undefined
parent
d4a8428b
Pipeline
#375
passed with stage
in 173 minutes and 6 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/graph/correlations/graph_assortativity.hh
View file @
1c9cd293
...
...
@@ -22,6 +22,10 @@
#include
"graph_util.hh"
#include
"hash_map_wrap.hh"
#if (BOOST_VERSION >= 106000)
# include <boost/math/special_functions/relative_difference.hpp>
#endif
namespace
graph_tool
{
using
namespace
std
;
...
...
@@ -76,7 +80,15 @@ struct get_assortativity_coefficient
}
t2
/=
n_edges
*
n_edges
;
r
=
(
t1
-
t2
)
/
(
1.0
-
t2
);
#if (BOOST_VERSION >= 106000)
if
(
boost
::
math
::
relative_difference
(
1.
,
t2
)
>
1e-8
)
#else
if
(
abs
(
1.
-
t2
)
>
1e-8
)
#endif
r
=
(
t1
-
t2
)
/
(
1.0
-
t2
);
else
r
=
std
::
numeric_limits
<
double
>::
quiet_NaN
();
// "jackknife" variance
double
err
=
0
;
...
...
@@ -104,7 +116,14 @@ struct get_assortativity_coefficient
});
if
(
!
is_directed
::
apply
<
Graph
>::
type
::
value
)
err
/=
2
;
r_err
=
sqrt
(
err
);
#if (BOOST_VERSION >= 106000)
if
(
boost
::
math
::
relative_difference
(
1.
,
t2
)
>
1e-8
)
#else
if
(
abs
(
1.
-
t2
)
>
1e-8
)
#endif
r_err
=
sqrt
(
err
);
else
r_err
=
std
::
numeric_limits
<
double
>::
quiet_NaN
();
}
};
...
...
@@ -127,7 +146,7 @@ struct get_scalar_assortativity_coefficient
(
g
,
[
&
](
auto
v
)
{
double
k1
=
double
(
deg
(
v
,
g
)
)
;
auto
k1
=
deg
(
v
,
g
);
for
(
auto
u
:
out_neighbors_range
(
v
,
g
))
{
auto
k2
=
deg
(
u
,
g
);
...
...
@@ -143,13 +162,33 @@ struct get_scalar_assortativity_coefficient
double
t1
=
e_xy
/
n_edges
;
a
/=
n_edges
;
b
/=
n_edges
;
double
stda
=
sqrt
(
da
/
n_edges
-
a
*
a
);
double
stdb
=
sqrt
(
db
/
n_edges
-
b
*
b
);
double
stda
;
double
stdb
;
#if (BOOST_VERSION >= 106000)
if
(
boost
::
math
::
relative_difference
(
da
/
n_edges
,
a
*
a
)
<
1e-8
)
stda
=
0
;
else
stda
=
sqrt
(
da
/
n_edges
-
a
*
a
);
if
(
boost
::
math
::
relative_difference
(
db
/
n_edges
,
b
*
b
)
<
1e-8
)
stdb
=
0
;
else
stdb
=
sqrt
(
db
/
n_edges
-
b
*
b
);
#else
if
(
sqrt
(
abs
(
da
/
n_edges
-
a
*
a
))
<
1e-8
)
stda
=
0
;
else
stda
=
sqrt
(
da
/
n_edges
-
a
*
a
);
if
(
sqrt
(
abs
(
db
/
n_edges
-
b
*
b
))
<
1e-8
)
stdb
=
0
;
else
stdb
=
sqrt
(
db
/
n_edges
-
b
*
b
);
#endif
if
(
stda
*
stdb
>
0
)
r
=
(
t1
-
a
*
b
)
/
(
stda
*
stdb
);
else
r
=
(
t1
-
a
*
b
);
r
=
std
::
numeric_limits
<
double
>::
quiet_NaN
(
);
// "jackknife" variance
r_err
=
0.0
;
...
...
@@ -182,7 +221,10 @@ struct get_scalar_assortativity_coefficient
});
if
(
!
is_directed
::
apply
<
Graph
>::
type
::
value
)
err
/=
2
;
r_err
=
sqrt
(
err
);
if
(
stda
*
stdb
>
0
)
r_err
=
sqrt
(
err
);
else
r_err
=
std
::
numeric_limits
<
double
>::
quiet_NaN
();
}
};
...
...
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