-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMUtest.py
142 lines (127 loc) · 5.41 KB
/
MUtest.py
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
# %% IMPORT NECESSARY PACKAGES
import numpy as np
from MUsim import MUsim
#########################################################
#########################################################
#########################################################
# %%
# # TRADITIONAL MODE (SIZE PRINCIPLE)
# INITIALIZE SIMULATION OBJECT, mu_stat
random_seed = None # set a random seed for reproducibility, None for completely random
if random_seed is None:
random_seed_sqn = np.random.SeedSequence()
else:
random_seed_sqn = np.random.SeedSequence(random_seed)
mu_stat = MUsim(random_seed_sqn)
# GET STATIC MOTOR UNIT THRESHOLDS
mu_stat.num_units = 32
mu_stat.MUthresholds_dist = "normal"
static_units = mu_stat.sample_MUs()
# %% PLOT THRESHOLD DISTRIBUTION, FORCE PROFILE, AND INDIVIDUAL UNIT RESPONSES
mu_stat.see("thresholds") # plot binned thresholds across all units
mu_stat.see("force") # plot default applied force
mu_stat.see("curves") # plot unit response curves
# %% SIMULATE MOTOR UNITS SPIKE RESPONSE TO DEFAULT FORCE
spikes = mu_stat.simulate_spikes(noise_level=0)
mu_stat.see("spikes") # plot spike response
# %% CONVOLVE AND PLOT SMOOTHED RESPONSE
smooth = mu_stat.convolve()
mu_stat.see("smooth") # plot smoothed spike response
# %% APPLY NEW FORCE, VIEW RESPONSE
new_force_profile = 3 * mu_stat.init_force_profile
mu_stat.apply_new_force(new_force_profile)
spikes2 = mu_stat.simulate_spikes()
mu_stat.see("force") # plot new applied force
mu_stat.see("curves") # plot unit response curves
mu_stat.see("spikes") # plot spike response
# %% CONVOLVE AND PLOT SMOOTHED RESPONSE
smooth = mu_stat.convolve()
mu_stat.see("smooth")
# %% SIMULATE SESSION (MANY TRIALS)
num_trials_to_simulate = 20
mu_stat.num_trials = num_trials_to_simulate
results = mu_stat.simulate_session()
# CONVOLVE ENTIRE SESSION
smooth_results = mu_stat.convolve(target="session")
num_units_to_view = 4
select_units = np.linspace(0, mu_stat.num_units - 1, num_units_to_view).astype(int)
mu_stat.see("unit", unit=select_units[0])
mu_stat.see("unit", unit=select_units[1])
mu_stat.see("unit", unit=select_units[2])
mu_stat.see("unit", unit=select_units[3])
# %% ###################################################
mu_lorenz = MUsim(random_seed_sqn)
# GET LORENZ SIMULATED MOTOR UNITS
mu_lorenz.num_units = 30
mu_lorenz.sample_rate = 1 / (0.006) # 166.7 Hz
mu_lorenz.MUthresholds_dist = "uniform"
lorenz_units = mu_lorenz.sample_MUs(MUmode="lorenz")
# %% SIMULATE MOTOR UNITS SPIKING RULED BY LORENZ DYNAMICS
spikes = mu_lorenz.simulate_spikes(noise_level=0)
mu_lorenz.see("spikes") # plot spike response
# %% CONVOLVE AND PLOT SMOOTHED SPIKES
smooth = mu_lorenz.convolve()
mu_lorenz.see("smooth") # plot smoothed spike response
# %% VIEW LORENZ ATTRACTOR
mu_lorenz.see("lorenz")
import matplotlib.pyplot as plt
#########################################################
# %% IMPORT NECESSARY PACKAGES
import numpy as np
from MUsim import MUsim
#########################################################
#########################################################
#########################################################
# %% # DYNAMIC MODE (THRESHOLD REVERSAL)
# INITIALIZE SIMULATION OBJECT, mu_dyn
mu_dyn = MUsim(random_seed_sqn)
# # GET DYNAMIC MOTOR UNIT THRESHOLDS
mu_dyn.num_units = 10
mu_dyn.MUthresholds_dist = "uniform"
mu_dyn.MUreversal_frac = 1 # set fraction of MU population that will reverse
mu_dyn.MUreversal_static_units = list(range((mu_dyn.num_units - 1)))
dyn_units = mu_dyn.sample_MUs(MUmode="dynamic")
# %% PLOT THRESHOLD DISTRIBUTION, FORCE PROFILE, AND INDIVIDUAL UNIT RESPONSES
mu_dyn.see("thresholds") # plot binned thresholds across all units
mu_dyn.see("force") # plot default applied force
mu_dyn.see("curves") # plot unit response curves
# %% SIMULATE MOTOR UNITS SPIKE RESPONSE TO DEFAULT FORCE
spikes1 = mu_dyn.simulate_spikes()
mu_dyn.see("spikes") # plot spike response
# %% CONVOLVE AND PLOT SMOOTHED RESPONSE
smooth1 = mu_dyn.convolve()
mu_dyn.see("smooth") # plot smoothed spike response
# %% APPLY NEW FORCE, VIEW RESPONSE
new_force_profile = 5 * (mu_dyn.init_force_profile)
mu_dyn.apply_new_force(new_force_profile)
spikes2 = mu_dyn.simulate_spikes()
smooth2 = mu_dyn.convolve()
mu_dyn.see("force") # plot new applied force
mu_dyn.see("curves") # plot unit response curves
mu_dyn.see("spikes") # plot spike response
mu_dyn.see("smooth") # plot smoothed spike response
# %% APPLY NON-LINEAR FORCE, VIEW RESPONSE
new_force_profile = -3 * np.cos(mu_dyn.init_force_profile)
mu_dyn.apply_new_force(new_force_profile)
spikes3 = mu_dyn.simulate_spikes()
smooth3 = mu_dyn.convolve()
mu_dyn.see("force") # plot new applied force
mu_dyn.see("curves") # plot unit response curves
mu_dyn.see("spikes") # plot spike response
mu_dyn.see("smooth") # plot smoothed spike response
# %% CONVOLVE AND PLOT SMOOTHED RESPONSE
smooth = mu_dyn.convolve()
mu_dyn.see("smooth")
# %% SIMULATE SESSION (MANY TRIALS)
num_trials_to_simulate = 20
mu_dyn.num_trials = num_trials_to_simulate
results = mu_dyn.simulate_session()
# CONVOLVE ENTIRE SESSION
smooth_results = mu_dyn.convolve(target="session")
num_units_to_view = 4
select_units = np.linspace(0, mu_dyn.num_units - 1, num_units_to_view).astype(int)
mu_dyn.see("unit", unit=select_units[0])
mu_dyn.see("unit", unit=select_units[1])
mu_dyn.see("unit", unit=select_units[2])
mu_dyn.see("unit", unit=select_units[3])
# %%