Browse Source

hacky correction for uniform distribution in circ corr coeff calculation

Paul Pfeiffer 3 years ago
parent
commit
0ccc36b431

+ 10 - 7
scripts/spatial_maps/simplex_input_tuning_correlation/circular_correlation_length.py

@@ -45,26 +45,29 @@ def get_circular_correlation_measure(angles_1, angles_2):
 N = 1000
 
 random_angles_1 = np.random.uniform(-np.pi, np.pi, N)
-random_angles_2 = np.random.uniform(-np.pi, np.pi, N)
 angles_close_to_pi_half = np.random.vonmises(np.pi / 2.0, 20, N)
-angles_close_to_minus_pi_half = angles_close_to_pi_half-np.pi*np.random.uniform(0.9, 1.1, N)
+angles_close_to_minus_pi_half = angles_close_to_pi_half - np.pi / 2.0 * np.random.uniform(0.9, 1.1, N)
+
+
 
 angles_description = ["random", "von_mises_pi_half", "von_mises_minus_pi_half"]
 angles_collection = [random_angles_1, angles_close_to_pi_half, angles_close_to_minus_pi_half]
 
 for desc, angles in zip(angles_description, angles_collection):
     print(desc)
-    print("C_1 = {:.2f}".format(get_c_p(angles, 1)))
     print("mean R_1 = {:.2f}".format(get_r_p(angles, 1) / N))
     print("T_1 = {:.2f}".format(get_t_p(angles, 1)))
     print()
 
+print(get_circular_correlation_measure(random_angles_1, angles_close_to_minus_pi_half))
 
-print(get_circular_correlation_measure(random_angles_1, angles_close_to_pi_half))
-print(get_circular_correlation_measure(angles_close_to_minus_pi_half, angles_close_to_pi_half))
 import matplotlib.pyplot as plt
+
+plt.figure()
 plt.hist(random_angles_1)
-plt.hist(angles_close_to_pi_half)
 plt.hist(angles_close_to_minus_pi_half)
 
-plt.show()
+plt.figure()
+plt.hist2d(random_angles_1, angles_close_to_minus_pi_half)
+
+plt.show()

+ 27 - 15
scripts/spatial_maps/simplex_input_tuning_correlation/correlation_length_with_circular_correlation_formula.py

@@ -1,20 +1,18 @@
-import os
 import matplotlib.pyplot as plt
 import numpy as np
-from pypet import Trajectory
-from pypet.brian2 import Brian2MonitorResult
 
 from scripts.interneuron_placement import create_grid_of_excitatory_neurons, get_correct_position_mesh
 from scripts.spatial_maps.uniform_perlin_map import UniformPerlinMap
-from scipy.optimize import curve_fit
-import pandas as pd
+
 
 def phi_diff(d_phi):
-    return (d_phi + np.pi) % (2*np.pi) - np.pi
+    return (d_phi + np.pi) % (2 * np.pi) - np.pi
+
 
 def exp_fit_func(x, corr_len):
     return np.pi / 2. * np.exp(-corr_len * x)
 
+
 use_saved_array = False
 dim = 60
 size = 900
@@ -30,7 +28,8 @@ for idx, (corr_len, axes_line) in enumerate(zip(corr_len_list, axes)):
 
     perlin_map = UniformPerlinMap(dim, dim, corr_len, size, size, 3)
 
-    ex_positions, ex_tunings = create_grid_of_excitatory_neurons(perlin_map.sheet_x, perlin_map.sheet_y, perlin_map.x_dim,
+    ex_positions, ex_tunings = create_grid_of_excitatory_neurons(perlin_map.sheet_x, perlin_map.sheet_y,
+                                                                 perlin_map.x_dim,
                                                                  perlin_map.get_tuning)
 
     ex_tun_array = np.array(ex_tunings).reshape((dim, dim))
@@ -39,27 +38,30 @@ for idx, (corr_len, axes_line) in enumerate(zip(corr_len_list, axes)):
     x_index = [pos[0] for pos in ex_positions]
     y_index = [pos[1] for pos in ex_positions]
 
-    x_displacements = range(-dim+1,dim)
-    y_displacements = range(-dim+1,dim)
-    r_c_array = np.ndarray((len(x_displacements),len(y_displacements)))
+    x_displacements = range(-dim + 1, dim)
+    y_displacements = range(-dim + 1, dim)
+    r_c_array = np.ndarray((len(x_displacements), len(y_displacements)))
 
     # For test purposes:
     # for i in range(dim):
     #     for j in range(dim):
     #         ex_tun_array[i,j] = np.sin(2*np.pi*i/dim)
 
-    for id_dx in x_displacements:
-        for id_dy in y_displacements:
-            a_1 = ex_tun_array[max(0, id_dx): min(dim, dim + id_dx), max(0, id_dy): min(dim, dim + id_dy)]
+    for x_displacement in x_displacements:
+        for y_displacement in y_displacements:
+            a_1 = ex_tun_array[max(0, x_displacement): min(dim, dim + x_displacement), max(0, y_displacement): min(dim, dim + y_displacement)]
             C_11 = np.sum(np.cos(a_1)) / len(a_1)
             S_11 = np.sum(np.sin(a_1)) / len(a_1)
             T_11 = np.arctan2(S_11, C_11)
 
-            a_2 = ex_tun_array[max(0, -id_dx): min(dim, dim - id_dx), max(0, -id_dy): min(dim, dim - id_dy)]
+            a_2 = ex_tun_array[max(0, -x_displacement): min(dim, dim - x_displacement), max(0, -y_displacement): min(dim, dim - y_displacement)]
             C_21 = np.sum(np.cos(a_2)) / len(a_2)
             S_21 = np.sum(np.sin(a_2)) / len(a_2)
             T_21 = np.arctan2(S_21, C_21)
 
+            # TODO: hack to avoid arbitrary mean directions in effectively uniform data
+            T_11 = 0
+            T_21 = 0
             r_c_denominator = np.sin(a_1 - T_11) * np.sin(a_2 - T_21)
             r_c_norm = np.sqrt(np.sum(np.sin(a_1 - T_11) ** 2) * np.sum(np.sin(a_2 - T_21) ** 2))
             if r_c_norm != 0:
@@ -67,7 +69,17 @@ for idx, (corr_len, axes_line) in enumerate(zip(corr_len_list, axes)):
             else:
                 # TODO: Not sure which value to put here.
                 r_c = 0
-            r_c_array[id_dx + dim - 1, id_dy + dim - 1] = r_c
+            if False and (x_displacement == 0 and y_displacement == 1):
+                plt.figure()
+                plt.suptitle("{:.2f}".format(r_c))
+                plt.hist2d(a_1.flatten() - T_11, a_2.flatten() - T_21)
+                print(T_11)
+                print(T_21)
+                print()
+                plt.show()
+                plt.close()
+
+            r_c_array[x_displacement + dim - 1, y_displacement + dim - 1] = r_c
     print(r_c_array)
 
     X, Y = get_correct_position_mesh(ex_positions)