50#include <lal/numeric/rational.hpp>
51#include <lal/graphs/undirected_graph.hpp>
52#include <lal/graphs/directed_graph.hpp>
53#include <lal/graphs/free_tree.hpp>
54#include <lal/graphs/rooted_tree.hpp>
76template <
class graph_t,
class return_type>
79(
const graph_t& g, uint64_t p, uint64_t (graph_t::*degree_function)(
node)
const noexcept)
83 std::is_same_v<return_type, uint64_t> ||
84 std::is_same_v<return_type, numeric::integer>
92 for (
node u = 0; u < g.get_num_nodes(); ++u) {
93 const uint64_t deg = (g.*degree_function)(u);
95 if constexpr (std::is_same_v<return_type, numeric::integer>) {
101 for (uint64_t i = 0; i < p; ++i) {
131 sum_powers_degrees<graphs::undirected_graph, numeric::integer>
152 sum_powers_degrees<graphs::undirected_graph, uint64_t>
174 sum_powers_degrees<graphs::directed_graph, numeric::integer>
195 sum_powers_degrees<graphs::directed_graph, uint64_t>
217 sum_powers_degrees<graphs::directed_graph, numeric::integer>
238 sum_powers_degrees<graphs::directed_graph, uint64_t>
264 assert(t.is_rooted_tree());
266 return t.get_num_edges();
288 assert(t.is_rooted_tree());
290 return t.get_num_edges();
311 sum_powers_degrees<graphs::directed_graph, numeric::integer>
332 sum_powers_degrees<graphs::directed_graph, uint64_t>
354template <
class graph_t,
class return_type>
357(
const graph_t& g, uint64_t p, uint64_t (graph_t::*degree_function)(
node)
const noexcept)
361 std::is_floating_point_v<return_type> ||
362 std::is_same_v<return_type, numeric::rational>
365 if constexpr (std::is_floating_point_v<return_type>) {
367 sum_powers_degrees<graph_t,uint64_t>(g,p,degree_function);
368 return static_cast<return_type
>(S)/
static_cast<return_type
>(g.get_num_nodes());
372 sum_powers_degrees<graph_t,numeric::integer>(g,p,degree_function);
399 moment_degree<graphs::undirected_graph, numeric::rational>
415 moment_degree<graphs::undirected_graph, double>
439 moment_degree<graphs::directed_graph, numeric::rational>
455 moment_degree<graphs::directed_graph, double>
479 moment_degree<graphs::directed_graph, numeric::rational>
495 moment_degree<graphs::directed_graph, double>
524 assert(t.is_rooted_tree());
526 const auto n = t.get_num_nodes();
546 assert(t.is_rooted_tree());
548 const auto n = t.get_num_nodes();
549 return static_cast<double>(n - 1)/
static_cast<double>(n);
572 moment_degree<graphs::directed_graph, numeric::rational>
589 moment_degree<graphs::directed_graph, double>
619 const uint64_t n = t.get_num_nodes();
632 return (k2_tree - k2_linear)/(k2_star - k2_linear);
657 const uint64_t n = t.get_num_nodes();
663 assert(t.is_rooted_tree());
670 return (k2_tree - k2_linear)/(k2_star - k2_linear);
685 const uint64_t n = t.get_num_nodes();
696 const double k2_linear =
static_cast<double>(4*n - 6)/
static_cast<double>(n);
697 const double k2_star =
static_cast<double>(n - 1);
698 return (k2_tree - k2_linear)/(k2_star - k2_linear);
714 const uint64_t n = t.get_num_nodes();
720 assert(t.is_rooted_tree());
725 const double k2_linear =
static_cast<double>(4*n - 6)/
static_cast<double>(n);
726 const double k2_star =
static_cast<double>(n - 1);
727 return (k2_tree - k2_linear)/(k2_star - k2_linear);
Directed graph class.
Definition: directed_graph.hpp:68
uint64_t get_out_degree(node u) const noexcept
Returns the out-degree of a node.
Definition: directed_graph.hpp:358
uint64_t get_degree(node u) const noexcept
Returns the in-degree plus the out-degree of this vertex.
Definition: directed_graph.hpp:354
uint64_t get_in_degree(node u) const noexcept
Returns the in-degree of a node.
Definition: directed_graph.hpp:365
Free tree graph class.
Definition: free_tree.hpp:60
Rooted tree graph class.
Definition: rooted_tree.hpp:103
Undirected graph class.
Definition: undirected_graph.hpp:67
uint64_t get_degree(node u) const noexcept
Returns the number of neighbours of u.
Definition: undirected_graph.hpp:327
Arbitrary precision integer.
Definition: integer.hpp:60
Exact rational number.
Definition: rational.hpp:63
numeric::rational moment_in_degree_rational(const graphs::directed_graph &g, uint64_t p) noexcept
Computes the -th moment of in-degree about zero of a directed graph as an exact rational value.
Definition: degrees.hpp:476
numeric::rational hubiness_rational(const graphs::free_tree &t) noexcept
Computes the hubiness coefficient as an exact rational number.
Definition: degrees.hpp:617
return_type sum_powers_degrees(const graph_t &g, uint64_t p, uint64_t(graph_t::*degree_function)(node) const noexcept) noexcept
Generic template function for the sum of degrees.
Definition: degrees.hpp:79
return_type moment_degree(const graph_t &g, uint64_t p, uint64_t(graph_t::*degree_function)(node) const noexcept) noexcept
Generic template function for the moment of degree about 0.
Definition: degrees.hpp:357
numeric::integer sum_powers_out_degrees_integer(const graphs::directed_graph &g, uint64_t p) noexcept
Computes the sum of out-degrees raised to the -th power.
Definition: degrees.hpp:308
numeric::integer sum_powers_in_degrees_integer(const graphs::directed_graph &g, uint64_t p) noexcept
Computes the sum of in-degrees raised to the -th power.
Definition: degrees.hpp:214
uint64_t sum_powers_out_degrees(const graphs::directed_graph &g, uint64_t p) noexcept
Computes the sum of out-degrees raised to the -th power.
Definition: degrees.hpp:329
numeric::rational moment_out_degree_rational(const graphs::directed_graph &g, uint64_t p) noexcept
Computes the -th moment of out-degree about zero of a directed graph as an exact rational value.
Definition: degrees.hpp:569
double moment_in_degree(const graphs::directed_graph &g, uint64_t p) noexcept
Computes the -th moment of in-degree about zero of a directed graph as a floating point value.
Definition: degrees.hpp:492
numeric::integer sum_powers_degrees_integer(const graphs::undirected_graph &g, uint64_t p) noexcept
Computes the sum of degrees raised to the -th power.
Definition: degrees.hpp:128
double hubiness(const graphs::free_tree &t) noexcept
Computes the hubiness coefficient as a floating point value.
Definition: degrees.hpp:683
uint64_t sum_powers_in_degrees(const graphs::directed_graph &g, uint64_t p) noexcept
Computes the sum of in-degrees raised to the -th power.
Definition: degrees.hpp:235
numeric::rational moment_degree_rational(const graphs::undirected_graph &g, uint64_t p) noexcept
Computes the -th moment of degree about zero of a graph as an exact rational value.
Definition: degrees.hpp:396
double moment_out_degree(const graphs::directed_graph &g, uint64_t p) noexcept
Computes the -th moment of out-degree about zero of a directed graph as a floating point value.
Definition: degrees.hpp:586
Main namespace of the library.
Definition: basic_types.hpp:50
uint64_t node
Node type. See Node / Vertex page for further details.
Definition: basic_types.hpp:53