コード例 #1
0
ファイル: sync_tests.py プロジェクト: RuhiSharma/pyclustering
    def templateDynamicSimulationConnectionTypeTest(self, num_osc, weight, connection_type):
        network = sync_network(num_osc, weight, type_conn = connection_type);
        output_dynamic = network.simulate_dynamic(collect_dynamic = False);  # Just current state of network is required
        
        clusters = output_dynamic.allocate_sync_ensembles(0.1);

        assert len(clusters) == 1;
コード例 #2
0
ファイル: sync_tests.py プロジェクト: terry07/pyclustering
 def templateVisualizerNoFailures(self, size, velocity, ccore_flag):
     net = sync_network(size, ccore = ccore_flag);
     output_dynamic = net.simulate_dynamic(solution = solve_type.FAST, collect_dynamic = True);
     
     sync_visualizer.animate_correlation_matrix(output_dynamic, velocity);
     sync_visualizer.animate_output_dynamic(output_dynamic, velocity);
     sync_visualizer.show_correlation_matrix(output_dynamic);
     sync_visualizer.show_output_dynamic(output_dynamic);
コード例 #3
0
ファイル: ut_sync.py プロジェクト: annoviko/pyclustering
    def testVisualizeLocalOrderParameterNoFailures(self):
        net = sync_network(10, ccore = False);
        output_dynamic = net.simulate_static(20, 10, solution = solve_type.FAST, collect_dynamic = True);

        sync_visualizer.show_local_order_parameter(output_dynamic, net);
        sync_visualizer.show_local_order_parameter(output_dynamic, net, 0);
        sync_visualizer.show_local_order_parameter(output_dynamic, net, 5);
        sync_visualizer.show_local_order_parameter(output_dynamic, net, 5, 20);
コード例 #4
0
 def templateConnectionsApi(size, ccore_flag):
     network = sync_network(size, 1, type_conn = conn_type.ALL_TO_ALL, ccore = ccore_flag);
     for i in range(len(network)):
         for j in range(len(network)):
             if (i != j):
                 assert network.has_connection(i, j) == True;
                 assert len(network.get_neighbors(i)) == size - 1, str(network.get_neighbors(i));
                 assert len(network.get_neighbors(j)) == size - 1;
コード例 #5
0
 def testOutputNormalization(self):
     network = sync_network(20, 1);
      
     (t, dyn) = network.simulate(50, 20, solve_type.RK4);
      
     for iteration in range(len(dyn)):
         for index_oscillator in range(len(dyn[iteration])):
             assert (dyn[iteration][index_oscillator] >= 0);
             assert (dyn[iteration][index_oscillator] <= 2.0 * pi);
コード例 #6
0
ファイル: ut_sync.py プロジェクト: annoviko/pyclustering
 def testSyncOrderNetwork(self):
     # Check for order parameter of network with several oscillators
     network = sync_network(2, 1, ccore=False);
         
     sync_state = 1;
     tolerance = 0.1;
         
     network.simulate(50, 20, solve_type.RK4);
     assert (abs(network.sync_order() - sync_state) < tolerance) == True;
コード例 #7
0
 def templateOutputDynamicCalculateLocalOrderParameter(ccore_flag):
     net = sync_network(5, ccore = ccore_flag);
     output_dynamic = net.simulate_static(20, 10, solution = solve_type.FAST, collect_dynamic = True);
     
     assert len(output_dynamic.calculate_local_order_parameter(net, 0, 20)) == 20;
     assert len(output_dynamic.calculate_local_order_parameter(net)) == 1;
     assert len(output_dynamic.calculate_local_order_parameter(net, 5)) == 1;
     assert len(output_dynamic.calculate_local_order_parameter(net, 5, 10)) == 5;
     assert output_dynamic.calculate_local_order_parameter(net, 20)[0] > 0.9;
コード例 #8
0
def template_animate_phase_matrix(num_osc, strength = 1.0, steps = None, time = None, conn = conn_type.ALL_TO_ALL, type_solution = solve_type.FAST, ccore_flag = True):
    network = sync_network(num_osc, strength, type_conn = conn, ccore = ccore_flag);

    if ( (steps is not None) and (time is not None) ):
        sync_output_dynamic = network.simulate(steps, time, solution = type_solution, collect_dynamic = True);
    else:
        sync_output_dynamic = network.simulate_dynamic(collect_dynamic = True, order = 0.999, solution = type_solution);

    sync_visualizer.animate_phase_matrix(sync_output_dynamic);
    return network;
コード例 #9
0
def template_dynamic_sync(num_osc, k = 1, q = 1, sim_arg = None, conn = conn_type.ALL_TO_ALL, type_solution = solve_type.FAST, collect_dyn = True, ccore_flag = False):
    network = sync_network(num_osc, k, type_conn = conn, ccore = ccore_flag);
    network.cluster = q;

    if (sim_arg is not None):
        (t, dyn_phase) = network.simulate(sim_arg[0], sim_arg[1], solution = type_solution, collect_dynamic = collect_dyn);
    else:
        (t, dyn_phase) = network.simulate_dynamic(collect_dynamic = collect_dyn, solution = type_solution);
        
    draw_dynamics(t, dyn_phase, x_title = "Time", y_title = "Phase", y_lim = [0, 2 * 3.14]);
    return network;
コード例 #10
0
ファイル: sync_examples.py プロジェクト: terry07/pyclustering
def template_dynamic_sync(num_osc, k = 1, sim_arg = None, conn = conn_type.ALL_TO_ALL, type_solution = solve_type.FAST, collect_dyn = True, ccore_flag = False):
    network = sync_network(num_osc, k, type_conn = conn, ccore = ccore_flag);

    if (sim_arg is not None):
        sync_output_dynamic = network.simulate(sim_arg[0], sim_arg[1], solution = type_solution, collect_dynamic = collect_dyn);
    else:
        sync_output_dynamic = network.simulate_dynamic(collect_dynamic = collect_dyn, solution = type_solution);

    sync_visualizer.show_output_dynamic(sync_output_dynamic);
    sync_visualizer.animate_output_dynamic(sync_output_dynamic);
    sync_visualizer.animate_correlation_matrix(sync_output_dynamic);
    return network;
コード例 #11
0
ファイル: ut_sync.py プロジェクト: annoviko/pyclustering
 def testOutputNormalization(self):
     network = sync_network(20, 1, ccore=False);
       
     output_dynamic = network.simulate(50, 20, solve_type.RK4);
      
     t = output_dynamic.time;
     dyn = output_dynamic.output;
      
     for iteration in range(len(dyn)):
         for index_oscillator in range(len(dyn[iteration])):
             assert (dyn[iteration][index_oscillator] >= 0);
             assert (dyn[iteration][index_oscillator] <= 2.0 * pi);
コード例 #12
0
 def templateSimulateTest(self, nodes = 10, weight = 1, solution = solve_type.FAST, ccore_flag = False):
     sim_time = 20;
     sim_steps = 50;
     tolerance = 0.01;
       
     network = sync_network(nodes, weight, ccore = ccore_flag);
             
     (t, dyn_phase) = network.simulate(sim_steps, sim_time, solution);
       
     index = len(dyn_phase) - 1;
     value = dyn_phase[index][0];
       
     for item in dyn_phase[index]:
         assert (abs(item - value) < tolerance) == True;
コード例 #13
0
ファイル: sync_tests.py プロジェクト: terry07/pyclustering
 def templateDynamicSimulationConnectionTypeTest(self, num_osc, weight, connection_type):
     testing_result = False;
     
     for _ in range(3):
         network = sync_network(num_osc, weight, type_conn = connection_type);
         output_dynamic = network.simulate_dynamic(collect_dynamic = False);  # Just current state of network is required
         
         clusters = output_dynamic.allocate_sync_ensembles(0.1);
         
         if (len(clusters) != 1):
             continue;
         
         testing_result = True;
         break;
     
     assert testing_result == True;
コード例 #14
0
 def templateSimulateTest(nodes, weight, solution, ccore_flag):
     sim_time = 20;
     sim_steps = 50;
     tolerance = 0.01;
        
     network = sync_network(nodes, weight, ccore = ccore_flag);
              
     output_dynamic = network.simulate(sim_steps, sim_time, solution);
      
     dyn_phase = output_dynamic.output;
      
     index = len(dyn_phase) - 1;
     value = dyn_phase[index][0];
        
     for item in dyn_phase[index]:
         if ((abs(item - value) < tolerance) != True):
             print(dyn_phase[:][0]);
              
         assert (abs(item - value) < tolerance) == True;
コード例 #15
0
ファイル: ut_sync.py プロジェクト: annoviko/pyclustering
 def testSyncOrderSingleOscillator(self):
     # Check for order parameter of network with one oscillator
     network = sync_network(1, 1, ccore=False);
     assert network.sync_order() == 1;
コード例 #16
0
ファイル: ut_sync.py プロジェクト: annoviko/pyclustering
 def testOutputDynamicLengthStaticSimulationWithouCollecting(self):
     net = sync_network(5, ccore=False);
     output_dynamic = net.simulate_static(10, 10, solution = solve_type.FAST, collect_dynamic = False);
      
     assert len(output_dynamic) == 1; # 10 steps without initial values.    
コード例 #17
0
ファイル: ut_sync.py プロジェクト: annoviko/pyclustering
 def testOutputDynamicLengthDynamicSimulationWithoutCollecting(self):
     net = sync_network(5, ccore=False);
     output_dynamic = net.simulate_dynamic(solution = solve_type.FAST, collect_dynamic = False);
      
     assert len(output_dynamic) == 1;
コード例 #18
0
ファイル: ut_sync.py プロジェクト: zbxzc35/pyclustering
 def testSyncLocalOrderSingleOscillator(self):
     network = sync_network(1, 1)
     assert network.sync_local_order() == 0
コード例 #19
0
 def testOutputDinamicLengthSimulation(self):
     net = sync_network(5);
     output_dynamic = net.simulate(10, 10, solution = solve_type.FAST, collect_dynamic = True);
     
     assert len(output_dynamic) == 11; # 10 steps without initial values.
コード例 #20
0
 def testCreate(self):
     network = sync_network(10, 1);
     assert network.num_osc == 10;
コード例 #21
0
 def testCreate(self):
     network = sync_network(10, 1)
     assert len(network) == 10
コード例 #22
0
 def testOutputDynamicLengthDynamicSimulation(self):
     net = sync_network(5);
     output_dynamic = net.simulate_dynamic(solution = solve_type.FAST, collect_dynamic = True);
      
     assert len(output_dynamic) > 1; 
コード例 #23
0
def template_animate_output_dynamic(title, amount_oscillators, coupling_stregth, frequency, order):
    network = sync_network(amount_oscillators, coupling_stregth, frequency, ccore = True);
    sync_output_dynamic = network.simulate_dynamic(order, solution = solve_type.RK4, collect_dynamic = True);
    
    sync_visualizer.animate(sync_output_dynamic, title);
コード例 #24
0
 def templateCreateNetwork(size, ccore_flag):
     network = sync_network(size, 1, ccore=ccore_flag)
     assert len(network) == size
コード例 #25
0
 def testCreate(self):
     network = sync_network(10, 1);
     assert len(network) == 10;
コード例 #26
0
 def testOutputDynamicLengthDynamicSimulation(self):
     net = sync_network(5);
     output_dynamic = net.simulate_dynamic(solution = solve_type.FAST, collect_dynamic = True);
     
     assert len(output_dynamic) > 1; 
コード例 #27
0
 def templateCreateNetwork(size, ccore_flag):
     network = sync_network(size, 1, ccore = ccore_flag);
     assert len(network) == size;
コード例 #28
0
 def testCreationDeletionByCore(self):
     # Crash occurs in case of memory leak
     for iteration in range(0, 15):
         network = sync_network(4096, 1, type_conn = conn_type.ALL_TO_ALL, ccore = True);
         del network;
コード例 #29
0
ファイル: ut_sync.py プロジェクト: annoviko/pyclustering
 def testSyncLocalOrderSingleOscillator(self):
     network = sync_network(1, 1);
     assert network.sync_local_order() == 0;
コード例 #30
0
 def testOutputDynamicLengthSimulation(self):
     net = sync_network(5);
     output_dynamic = net.simulate(10, 10, solution = solve_type.FAST, collect_dynamic = True);
      
     assert len(output_dynamic) == 11; # 10 steps without initial values.
コード例 #31
0
ファイル: ut_sync.py プロジェクト: zbxzc35/pyclustering
 def testSyncOrderSingleOscillator(self):
     # Check for order parameter of network with one oscillator
     network = sync_network(1, 1, ccore=False)
     assert network.sync_order() == 1
コード例 #32
0
 def testCreate(self):
     network = sync_network(10, 1)
     assert network.num_osc == 10
コード例 #33
0
 def templateDynamicSimulationConvergence(self, num_osc, weight, connection_type, ccore_flag):
     network = sync_network(num_osc, weight, type_conn = connection_type, initial_phases=initial_type.EQUIPARTITION, ccore = ccore_flag);
     output_dynamic = network.simulate_dynamic(collect_dynamic = False);  # Just current state of network is required
      
     clusters = output_dynamic.allocate_sync_ensembles(0.1);
     assert len(clusters) == 1;
コード例 #34
0
def template_animate_output_dynamic(title, amount_oscillators, coupling_stregth, frequency, order):
    network = sync_network(amount_oscillators, coupling_stregth, frequency, ccore = True);
    sync_output_dynamic = network.simulate_dynamic(order, solution = solve_type.RK4, collect_dynamic = True);
    
    sync_visualizer.animate(sync_output_dynamic, title, title + ".mp4");
コード例 #35
0
 def testOutputDynamicLengthStaticSimulationWithouCollecting(self):
     net = sync_network(5);
     output_dynamic = net.simulate_static(10, 10, solution = solve_type.FAST, collect_dynamic = False);
      
     assert len(output_dynamic) == 1; # 10 steps without initial values.    
コード例 #36
0
 def testCreationDeletionByCore(self):
     # Crash occurs in case of memory leak
     for _ in range(0, 15):
         network = sync_network(4096, 1, type_conn = conn_type.ALL_TO_ALL, ccore = True);
         del network;
コード例 #37
0
 def testOutputDynamicLengthDynamicSimulationWithoutCollecting(self):
     net = sync_network(5);
     output_dynamic = net.simulate_dynamic(solution = solve_type.FAST, collect_dynamic = False);
      
     assert len(output_dynamic) == 1;
コード例 #38
0
 def templateDynamicSimulationConvergence(self, num_osc, weight, connection_type, ccore_flag):
     network = sync_network(num_osc, weight, type_conn = connection_type, initial_phases=initial_type.EQUIPARTITION, ccore = ccore_flag);
     (t, dyn) = network.simulate_dynamic(collect_dynamic = False);  # Just current state of network is required
     
     clusters = network.allocate_sync_ensembles(0.1);
     assert len(clusters) == 1;