def test_get_vertex_total_weight(self): """Tests get_vertex_total_weight.""" test1 = [('1', '2', 0.1), ('2', '3', 0.2), ('1', '3', 0.3)] expected1 = 0.4 actual1 = edge_analysis.get_vertex_total_weight(test1, '1') self.assertAlmostEqual(actual1, expected1) test2 = [('1', '2', 0.1), ('2', '3', 0.2), ('1', '3', 0.3)] expected2 = 0.3 actual2 = edge_analysis.get_vertex_total_weight(test2, '2') self.assertAlmostEqual(actual2, expected2) test3 = [('1', '2', 0.1), ('2', '3', 0.2), ('1', '3', 0.3)] expected3 = 0.5 actual3 = edge_analysis.get_vertex_total_weight(test3, '3') self.assertAlmostEqual(actual3, expected3)
students_wrapper = StudentContainerWrapper( args.swig_module_path, args.student_archive_path) segment_counts = segment.get_segment_counts(students_wrapper, args.field) # compare actual edges with expected edges, put into matrix segments = sorted(list(segment_counts.keys())) population = sum(segment_counts.values()) heatmatrix = numpy.zeros((len(segments), len(segments))) for vertex1, vertex2, actual_weight in edge_lines: vertex1_weight = segment_counts[vertex1] vertex2_weight = segment_counts[vertex2] # store vertex expected weight v1v2_expected_weight = ( (vertex2_weight / population) * edge_analysis.get_vertex_total_weight(edge_lines, vertex1)) v2v1_expected_weight = ( (vertex1_weight / population) * edge_analysis.get_vertex_total_weight(edge_lines, vertex2)) # store the difference of actual and expected in a matrix vertex1_index = segments.index(vertex1) vertex2_index = segments.index(vertex2) heatmatrix[vertex2_index, vertex1_index] = ( calculation.relative_percent_difference( actual_weight, v1v2_expected_weight)) if vertex1 != vertex2: heatmatrix[vertex1_index, vertex2_index] = ( calculation.relative_percent_difference( actual_weight, v2v1_expected_weight))
students_wrapper = StudentContainerWrapper(args.swig_module_path, args.student_archive_path) segment_counts = segment.get_segment_counts(students_wrapper, args.field) # compare actual edges with expected edges, put into matrix segments = sorted(list(segment_counts.keys())) population = sum(segment_counts.values()) heatmatrix = numpy.zeros((len(segments), len(segments))) for vertex1, vertex2, actual_weight in edge_lines: vertex1_weight = segment_counts[vertex1] vertex2_weight = segment_counts[vertex2] # store vertex expected weight v1v2_expected_weight = ( (vertex2_weight / population) * edge_analysis.get_vertex_total_weight(edge_lines, vertex1)) v2v1_expected_weight = ( (vertex1_weight / population) * edge_analysis.get_vertex_total_weight(edge_lines, vertex2)) # store the difference of actual and expected in a matrix vertex1_index = segments.index(vertex1) vertex2_index = segments.index(vertex2) heatmatrix[vertex2_index, vertex1_index] = (calculation.relative_percent_difference( actual_weight, v1v2_expected_weight)) if vertex1 != vertex2: heatmatrix[vertex1_index, vertex2_index] = ( calculation.relative_percent_difference( actual_weight, v2v1_expected_weight))