示例#1
0
    def templateClustering(path, number_clusters, expected_length_clusters,
                           solver, initial_neighbors, increase_persent,
                           collect_dynamic_flag, ccore_flag):
        result_testing = False

        # If phases crosses each other because of random part of the network then we should try again.
        for _ in range(0, 6, 1):
            sample = read_sample(path)
            network = hsyncnet(sample,
                               number_clusters,
                               initial_type.EQUIPARTITION,
                               initial_neighbors,
                               increase_persent,
                               ccore=ccore_flag)

            analyser = network.process(order=0.997,
                                       solution=solver,
                                       collect_dynamic=collect_dynamic_flag)
            clusters = analyser.allocate_clusters(0.1)

            if (sum([len(cluster) for cluster in clusters]) !=
                    sum(expected_length_clusters)):
                continue

            if (sorted([len(cluster)
                        for cluster in clusters]) != expected_length_clusters):
                if (sorted([len(cluster) for cluster in clusters]) !=
                        sorted(expected_length_clusters)):
                    continue

            # Unit-test is passed
            result_testing = True
            break

        assert result_testing
 def testCreationDeletionByCore(self):
     # Crash occurs in case of memory leak
     data = read_image(IMAGE_MAP_SAMPLES.IMAGE_WHITE_SEA_SMALL);
     
     for iteration in range(0, 15):
         network = hsyncnet(data, 2, ccore = True);
         del network;
示例#3
0
    def templateDynamicLength(path, number_clusters, expected_length,
                              initial_neighbors, increase_persent,
                              collect_dynamic_flag, ccore_flag):
        sample = read_sample(path)
        network = hsyncnet(sample,
                           number_clusters,
                           initial_type.EQUIPARTITION,
                           initial_neighbors,
                           increase_persent,
                           ccore=ccore_flag)

        analyser = network.process(order=0.995,
                                   solution=solve_type.FAST,
                                   collect_dynamic=collect_dynamic_flag)

        assert len(analyser) != 0

        if (collect_dynamic_flag is True):
            assert len(analyser) >= 1
            if (expected_length is None):
                assert len(analyser) > 1
            else:
                assert len(analyser) == expected_length

        else:
            assert len(analyser) == 1
def template_clustering(file, number_clusters, arg_order = 0.999, arg_collect_dynamic = True, ccore_flag = False):
        sample = read_sample(file);
        network = hsyncnet(sample, number_clusters, ccore = ccore_flag);
        
        (time, dynamic) = network.process(arg_order, collect_dynamic = arg_collect_dynamic);
        clusters = network.get_clusters();
        
        if (arg_collect_dynamic == True):
            draw_dynamics(time, dynamic, x_title = "Time", y_title = "Phase", y_lim = [0, 2 * 3.14]);
        
        draw_clusters(sample, clusters);
def template_clustering(file, number_clusters, arg_order = 0.999, arg_collect_dynamic = True, ccore_flag = False):
        sample = read_sample(file);
        network = hsyncnet(sample, number_clusters, ccore = ccore_flag);
        
        analyser = network.process(arg_order, collect_dynamic = arg_collect_dynamic);
        clusters = analyser.allocate_clusters();
        
        if (arg_collect_dynamic == True):
            sync_visualizer.show_output_dynamic(analyser);
        
        draw_clusters(sample, clusters);
 def testCoreInterfaceIntInputData():
     result_testing = False;
     
     for _ in range(10):
         hsyncnet_instance = hsyncnet([ [1], [2], [3], [20], [21], [22] ], 2, initial_type.EQUIPARTITION, ccore = True);
         analyser = hsyncnet_instance.process();
         
         if (len(analyser.allocate_clusters(0.1)) == 2):
             result_testing = True;
             break;
     
     assert result_testing;
示例#7
0
def template_clustering(file, number_clusters, arg_order = 0.999, arg_collect_dynamic = True, ccore_flag = False):
        sample = read_sample(file);
        network = hsyncnet(sample, number_clusters, initial_neighbors = int(len(sample) * 0.15), osc_initial_phases = initial_type.EQUIPARTITION, ccore = ccore_flag);
        
        (ticks, analyser) = timedcall(network.process, arg_order, solve_type.FAST, arg_collect_dynamic);
        print("Sample: ", file, "\t\tExecution time: ", ticks, "\n");
        
        clusters = analyser.allocate_clusters();
        
        if (arg_collect_dynamic == True):
            sync_visualizer.show_output_dynamic(analyser);
        
        draw_clusters(sample, clusters);
 def templateDynamicLength(path, number_clusters, expected_length, initial_neighbors, increase_persent, collect_dynamic_flag, ccore_flag):
     sample = read_sample(path);
     network = hsyncnet(sample, number_clusters, initial_type.EQUIPARTITION, initial_neighbors, increase_persent, ccore = ccore_flag);
     
     analyser = network.process(order = 0.995, solution = solve_type.FAST, collect_dynamic = collect_dynamic_flag);
     
     assert len(analyser) != 0;
     
     if (collect_dynamic_flag is True):
         assert len(analyser) >= 1;
         if (expected_length is None):
             assert len(analyser) > 1;
         else:
             assert len(analyser) == expected_length;
     
     else:
         assert len(analyser) == 1;
def template_clustering(file,
                        number_clusters,
                        arg_order=0.999,
                        arg_collect_dynamic=True,
                        ccore_flag=False):
    sample = read_sample(file)
    network = hsyncnet(sample, number_clusters, ccore=ccore_flag)

    (time, dynamic) = network.process(arg_order,
                                      collect_dynamic=arg_collect_dynamic)
    clusters = network.get_clusters()

    if (arg_collect_dynamic == True):
        draw_dynamics(time,
                      dynamic,
                      x_title="Time",
                      y_title="Phase",
                      y_lim=[0, 2 * 3.14])

    draw_clusters(sample, clusters)
示例#10
0
 def templateClustering(self, path, number_clusters, expected_length_clusters, solver, ccore_flag):
     result_testing = False;
     
     # If phases crosses each other because of random part of the network then we should try again.
     for attempt in range(0, 3, 1):
         sample = read_sample(path);
         network = hsyncnet(sample, number_clusters, initial_type.EQUIPARTITION, ccore = ccore_flag); # EQUIPARTITION - makes test more stable.
         
         analyser = network.process(order = 0.997, solution = solver, collect_dynamic = True);
         clusters = analyser.allocate_clusters(0.1);
         
         if (sum([len(cluster) for cluster in clusters]) != sum(expected_length_clusters)):
             continue;
         
         if (sorted([len(cluster) for cluster in clusters]) != expected_length_clusters):
             if (sorted([len(cluster) for cluster in clusters]) != expected_length_clusters):
                 continue;
         
         # Unit-test is passed
         result_testing = True;
         break;
     
     assert result_testing;
示例#11
0
def process_hsyncnet(sample):
    instance = hsyncnet(sample, CURRENT_CLUSTER_SIZE, initial_type.EQUIPARTITION, CURRENT_CLUSTER_SIZE)
    (ticks, _) = timedcall(instance.process, 0.998)
    return ticks