def degree_assortativity_coefficient( graph: PropertyGraph, source_degree_type: DegreeType = DegreeType.OUT, destination_degree_type: DegreeType = DegreeType.IN, weight=None, ): """ Calculates and returns the degree assortativity of a given graph. Paramaters: * graph: the PropertyGraph to be analyzed * source_degree_type: description of degree type to consider for the source node on an edge expected values are DegreeType.IN or DegreeType.OUT * destination_degree_type: description the degree type to consider for the destination node on an edge expected values are DegreeType.IN or DegreeType.OUT * weight (optional): edge property to use if using weighted degrees """ # get the tables associated with the degree types of the source and destination nodes calculate_degree(graph, "temp_DegreeType.IN", "temp_DegreeType.OUT", weight) source_degree = graph.get_node_property("temp_" + str(source_degree_type)) destination_degree = graph.get_node_property("temp_" + str(destination_degree_type)) try: # Calculate the average in and out degrees of graph # (with respect to number of edges, not number of nodes) num_edges = graph.num_edges() source_average, destination_average = average_degree( graph, num_edges, source_degree, destination_degree) # Calculate the numerator (product of deviation from mean) # and the factors of the denominator (square deviation from mean) product_of_dev = GAccumulator[float](0) square_of_source_dev = GAccumulator[float](0) square_of_destination_dev = GAccumulator[float](0) do_all( range(graph.num_nodes()), degree_assortativity_coefficient_operator( graph, source_degree, source_average, destination_degree, destination_average, product_of_dev, square_of_source_dev, square_of_destination_dev, ), steal=True, loop_name="degree assortativity coefficient calculation", ) return product_of_dev.reduce() / sqrt( square_of_source_dev.reduce() * square_of_destination_dev.reduce()) finally: graph.remove_node_property("temp_DegreeType.IN") graph.remove_node_property("temp_DegreeType.OUT")
def test_commit(property_graph): # TODO(amp): mark_all_properties_persistent shouldn't be required. Why is it? property_graph.mark_all_properties_persistent() with TemporaryDirectory() as tmpdir: property_graph.path = tmpdir property_graph.write() del property_graph property_graph = PropertyGraph(tmpdir) assert property_graph.num_nodes() == 29092 assert property_graph.num_edges() == 39283 assert len(property_graph.node_schema()) == 31 assert len(property_graph.edge_schema()) == 19