-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvisualize-motor-response
More file actions
142 lines (112 loc) · 4.64 KB
/
Copy pathvisualize-motor-response
File metadata and controls
142 lines (112 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
from os import path, makedirs
# beta-1/sim-20180511-163319
# beta-10/sim-20180512-105824
# beta-0-1/sim-20180512-105719
def dec2bin(num,num_digits):
frmt = '{:0'
frmt += str(num_digits)
frmt += 'b}'
return frmt.format(num)
loadfile = 'sim-20200303-204124-ref_500_-b_1_-li_1999_-g_4000_-l_sim-20200221-191932-ser_-b_1_-a_50_100_250_500_1500_1999_-n_12_neuuron_inst_of_20_-a_500_1000_1500_2000_3000_3999_-n_12_neurons'
gen = 2999
motor = 'dr'
#motor = ''
plt.rc('text', usetex=True)
font = {'family': 'serif', 'size': 15, 'serif': ['computer modern roman']}
plt.rc('font', **font)
plt.rc('legend', **{'fontsize': 16})
R = 1
Nsens = 100
sens = np.linspace(-1, 1, Nsens)
numAgents = 50
fontsize = 20
d = np.dtype([('MV', 'f8'), ('MR', 'f8'), ('CMV', 'f8'), ('CMR', 'f8')])
data = np.zeros((R, numAgents, Nsens), dtype=d)
#folder = 'save/' + loadfile + '/Motor_Response_' + motor + '/gen_' + str(gen) + '/'
folder = 'save/' + loadfile + '/Motor_Response' + '/gen_' + str(gen) + '/'
# TODO: Changed this to make it work
for sensInd in np.arange(1, Nsens):
file = 'MR-' + 'Nsens_' + str(Nsens) + \
'-sensInd_' + str(sensInd) + \
'-gen_' + str(gen) + \
'.npy'
filename = folder + file
data[:, :, sensInd] = np.load(filename)
fig, ax = plt.subplots(2, 2, figsize=(14, 10), sharex=False)
if motor == 'dr':
fig.text(0.5, 0.04, 'Sensory Activation (food angle)', ha='center', fontsize=fontsize)
elif motor == 'dv':
fig.text(0.5, 0.04, 'Sensory Activation (food distance)', ha='center', fontsize=fontsize)
elif motor == 'dp':
fig.text(0.5, 0.04, 'Sensory Activation (proximity sensor)', ha='center', fontsize=fontsize)
fig.text(0.04, 0.72, 'Motor Response', va='center', rotation='vertical', fontsize=fontsize)
fig.text(0.04, 0.28, 'Motor Susceptiblity', va='center', rotation='vertical', fontsize=fontsize)
title = 'Motor Response (dv, d$\omega$) of Foraging Community\n Generation: ' + str(gen)
fig.suptitle(title)
b = 0
alpha = 0.1
if motor == 'dr':
theta = sens * 180
xticks = [-180, -90, 0, 90, 180]
elif motor == 'dv':
dist = np.sqrt( 1 / ( np.arctanh( (sens + 1 ) / 2 ) ) - 1e-6 ) # plot as a function of distance
# xticks = [np.min(dist[1:-1]), 1, 2, 4, np.max(dist[1:-1])]
xticks = [0.5, 1, 2, 4, 9]
elif motor == 'dp':
xticks = [-1, -0.5, 0, 0.5, 1]
for iplot, name in enumerate(d.names):
x = int(dec2bin(iplot, 2)[0])
y = int(dec2bin(iplot, 2)[1])
# meanData = np.mean(np.mean(data[name][:, :, 1:], # average across repitions
# axis=0), axis=0)
# if motor == 'dr':
# ax[x, y].plot(
# theta[1:], meanData, color=[0, 0, 0], linewidth=4)
# else:
# ax[x, y].plot(
# dist[1:], meanData, color=[0, 0, 0], linewidth=4)
for i in range(0, 50):
if motor == 'dr':
ax[x, y].scatter(
theta[1:], np.mean(data[name][:, i, 1:], # average across repitions
axis=0), color=[b, b, b], s=30, alpha=alpha)
elif motor == 'dv':
ax[x, y].scatter(
dist[1:], np.mean(data[name][:, i, 1:], # average across repitions
axis=0), color=[b, b, b], s=30, alpha=alpha)
elif motor == 'dp':
ax[x, y].scatter(
sens[1:], np.mean(data[name][:, i, 1:], # average across repitions
axis=0), color=[b, b, b], s=30, alpha=alpha)
if motor == 'dv':
ax[x, y].set_xscale("log", nonposx='clip')
ax[x, y].set_xticks(xticks)
ax[x, y].get_xaxis().set_major_formatter(matplotlib.ticker.ScalarFormatter())
# ax[x, y].set_title(name)
ax[0, 0].set_title(r'$dv$')
ax[0, 1].set_title(r'$d\omega$')
ax[1, 0].set_title(r'$\sigma^2(dv)$')
ax[1, 1].set_title(r'$\sigma^2(d\omega)$')
# manager = plt.get_current_fig_manager()
# manager.resize(*manager.window.maxsize())
# TODO: commented this out to make it work
#
# for i in range(2):
# for j in range(2):
# # ax[i, j].set_xscale("log", nonposx='clip')
# ax[i, j].set_xticks(xticks)
# ax[i, j].xaxis.set_major_formatter(matplotlib.ticker.ScalarFormatter())
# ax[i, j].xaxis.set_major_locator(matplotlib.ticker.MaxNLocator(integer=True))
#
# # plt.axis([0.1, 10, -0.02, 1.5*np.max(meanC)])
# plt.axis([-1, 1, -1, 1])
figfolder = 'save/' + loadfile + '/figs/Motor_Response/'
if not path.exists(figfolder):
makedirs(figfolder)
figname = figfolder + motor + '-gen-' + str(gen) + '.png'
plt.savefig(figname, bbox_inches='tight', dpi=150)
plt.show()