Exemplo n.º 1
0
    def test_get_id_values(self):
        """Tests get_id_values function."""

        test1 = io.StringIO('1\t1.0\n2\t2.0\n3\t3.0')
        expected1 = [(1, 1.0), (2, 2.0), (3, 3.0)]
        actual1 = list(vertex_analysis.get_id_values(test1))
        self.assertEqual(actual1, expected1)

        test2 = io.StringIO('')
        expected2 = []
        actual2 = list(vertex_analysis.get_id_values(test2))
        self.assertEqual(actual2, expected2)

        test3 = io.StringIO('1\t1.0\t1.0\n2\t2.0\t2.0\n3\t3.0\t3.0')
        expected3 = [(1, 1.0, 1.0), (2, 2.0, 2.0), (3, 3.0, 3.0)]
        actual3 = list(vertex_analysis.get_id_values(test3))
        self.assertEqual(actual3, expected3)
Exemplo n.º 2
0
            '--student-archive-path', dest='student_archive_path',
            help='Path of the student archive file.', required=True)
    parser.add_argument(
            '--swig-module-path', dest='swig_module_path',
            help='Directory containing the swig modules.',
            action=ReadableDirectory, required=True)

    parser.set_defaults()

    args = parser.parse_args()

    show_unnormalized = 'frequency' in args.distributions
    show_normalized = 'normalized' in args.distributions

    # segment the data
    vertex_lines = vertex_analysis.get_id_values(args.file)
    students_wrapper = StudentContainerWrapper(
            args.swig_module_path, args.student_archive_path)
    segmenter = StudentContainerWrapper.SEGMENTERS[args.segmenter]
    mapped_lines = vertex_analysis.map_to_segments(
            vertex_lines, segmenter, students_wrapper)
    segments = vertex_analysis.reduce_to_segments(mapped_lines)

    # filter out small segments
    filtered_segments = {segment: values for segment, values in segments.items()
                         if values.size >= args.threshold}

    # set up the histogram for various colors
    size = ((12, 8) if show_unnormalized and show_normalized
            else (12, 4))
    fig = matplotlib.pyplot.figure(figsize=size)
Exemplo n.º 3
0
    parser.add_argument(
            '--swig-module-path', dest='swig_module_path',
            help='Directory containing the swig modules.',
            action=readable_directory.ReadableDirectory, required=True)

    args = parser.parse_args()

    unweighted = args.weightedness == 'unweighted'
    weighted = args.weightedness == 'weighted'

    # get container of students
    students = StudentContainerWrapper(
            args.swig_module_path, args.student_archive_path)

    # get the weights of individual segments
    lines = list(vertex_analysis.get_id_values(args.file))
    mapped_to_segments = vertex_analysis.map_to_segments(
            lines, StudentContainerWrapper.SEGMENTERS[args.field], students)
    reduced_data = vertex_analysis.reduce_to_in_out(
            mapped_to_segments, args.in_segment)
    if unweighted:
        actual_segments = {key: len(data) for key, data in reduced_data.items()}
    elif weighted:
        actual_segments = {key: sum(data) for key, data in reduced_data.items()}

    print(actual_segments)

    population_segments = segment.get_segment_counts(students, args.field)
    print(population_segments[args.in_segment])

    population = len(students)
Exemplo n.º 4
0
            '--student-archive-path', dest='student_archive_path',
            help='Path of the student archive file.', required=True)
    parser.add_argument(
            '--swig-module-path', dest='swig_module_path',
            help='Directory containing the swig modules.',
            action=ReadableDirectory, required=True)

    args = parser.parse_args()

    # segment the network for analysis
    students_wrapper = StudentContainerWrapper(
            args.swig_module_path, args.student_archive_path)
    segmenter = StudentContainerWrapper.SEGMENTERS[args.segmenter]

    for vertex_file in args.files:
        vertex_lines = vertex_analysis.get_id_values(vertex_file)

        segmented_lines = list(vertex_analysis.map_to_segments(
                vertex_lines, segmenter, students_wrapper))
        total_connections = len(segmented_lines)
        values_sum = vertex_analysis.accumulate(segmented_lines, sum)
        segments = vertex_analysis.reduce_to_segments(segmented_lines)

        # calculate the diversity of the segments
        diversity_index = 0
        if args.weightedness == 'unweighted':
            diversity_index = calculate_unweighted_index(
                    segments.values(), total_connections)
        elif args.weightedness == 'weighted':
            diversity_index = calculate_weighted_index(
                    segments.values(), values_sum)
Exemplo n.º 5
0
                        required=True)
    parser.add_argument('--swig-module-path',
                        dest='swig_module_path',
                        help='Directory containing the swig modules.',
                        action=ReadableDirectory,
                        required=True)

    args = parser.parse_args()

    # segment the network for analysis
    students_wrapper = StudentContainerWrapper(args.swig_module_path,
                                               args.student_archive_path)
    segmenter = StudentContainerWrapper.SEGMENTERS[args.segmenter]

    for vertex_file in args.files:
        vertex_lines = vertex_analysis.get_id_values(vertex_file)

        segmented_lines = list(
            vertex_analysis.map_to_segments(vertex_lines, segmenter,
                                            students_wrapper))
        total_connections = len(segmented_lines)
        values_sum = vertex_analysis.accumulate(segmented_lines, sum)
        segments = vertex_analysis.reduce_to_segments(segmented_lines)

        # calculate the diversity of the segments
        diversity_index = 0
        if args.weightedness == 'unweighted':
            diversity_index = calculate_unweighted_index(
                segments.values(), total_connections)
        elif args.weightedness == 'weighted':
            diversity_index = calculate_weighted_index(segments.values(),