Skip to content

Commit 6d59982

Browse files
committed
Merge branch 'release-v0.2'
Updated model performing closer to the desired outcomes.
2 parents f14ecb4 + 92d25bb commit 6d59982

8 files changed

+747
-285
lines changed

src/model/lifNetwork.py

Lines changed: 452 additions & 281 deletions
Large diffs are not rendered by default.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
## Testing script
2+
3+
import src.model.copied_from_ipynb_discussion_with_jesse as lif
4+
from src.plotting import plotStructure as lifplot
5+
import matplotlib.pyplot as plt
6+
import matplotlib
7+
import numpy as np
8+
import os
9+
from tqdm import tqdm
10+
from datetime import datetime
11+
import numpy.typing as npt
12+
13+
14+
15+
16+
################################################################################
17+
### PLOTTING FUNCTIONS, DON'T TOUCH!!!
18+
################################################################################
19+
20+
def plot_helper(ax:plt.Axes, y:list, label:str,
21+
n_sim:int, sim_duration:float, n_neurons:int, proba_conn:float,):
22+
"""Plot the plot."""
23+
ax.plot(y, label=label, marker='+', linestyle='-')
24+
ax.set_title(f"<w(t)>\n\
25+
| n_iterations: {n_sim} | sim_duration: {sim_duration} ms |\n\
26+
| n_neurons: {n_neurons} | proba_of_connection: {proba_conn} |")
27+
ax.set_xlabel(f"n-th iteration | each iteration = {sim_duration} ms")
28+
ax.set_ylabel("mean network weight")
29+
ax.legend()
30+
31+
# ax.vlines(x=iteration*sim_duration, ymin=0, ymax=1,
32+
# label="Simulation Iteration",
33+
# color="red", alpha=0.3)
34+
# ax.set_ylim(bottom=0, top=1)
35+
# ax.set_xlim(left=0, right=n_sim*sim_duration)
36+
# plt.legend()
37+
38+
return ax
39+
40+
def save_helper(fig:matplotlib.figure.Figure, iteration:int, export_directory:str) -> None:
41+
"""Save the plot in current working directory."""
42+
# Export plot
43+
os.makedirs(export_directory, exist_ok=True)
44+
fig.savefig(f"{export_directory}/iteration_{iteration}.png",
45+
facecolor="white")
46+
return
47+
48+
def plot_network_mean_weight_over_time(n_neurons:int=300,
49+
n_sim:int=10000,
50+
sim_duration:float=100,
51+
proba_conn:float=0.08,
52+
mean_w:list=[0.1, 0.2, 0.3, 0.5],
53+
export_iteration_skip:int=10,
54+
plot_dim:tuple=(25, 10)):
55+
"""Plot the mean network weight over time."""
56+
57+
# Set variables
58+
export_directory = "export_"+datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
59+
holder_mean_network_w = {}
60+
holder_LIF = {}
61+
62+
# Instantiate a model for each mean_w item
63+
for each_mean_w in mean_w:
64+
name = f"mean_w={each_mean_w}"
65+
holder_LIF[name] = lif.LIF_Network(n_neurons=n_neurons)
66+
holder_LIF[name].p_conn = proba_conn
67+
holder_LIF[name].mean_w = each_mean_w
68+
holder_LIF[name].random_conn()
69+
# lifplot.plot_structure(holder_LIF[name])
70+
holder_mean_network_w[name] = []
71+
72+
# Run each of the n_sim
73+
for iteration in tqdm(np.arange(n_sim),
74+
desc=f"Simulation progress - total of {n_sim} simulations"):
75+
# Simulate for each model
76+
for nn_name, nn in holder_LIF.items():
77+
nn.simulate(timesteps=sim_duration)
78+
mean_network_w = np.mean(nn.network_W[nn.network_conn.astype(bool)])
79+
holder_mean_network_w[nn_name].append(mean_network_w)
80+
81+
# Plot every `export_iteration_skip`-th simulation iteration
82+
if (iteration % export_iteration_skip == 0):
83+
fig, ax = plt.subplots(figsize=plot_dim)
84+
85+
# Plot for each of the mean_w
86+
for nn_name, mean_network_w in holder_mean_network_w.items():
87+
plot_helper(ax=ax, y=mean_network_w, label=nn_name,
88+
n_sim=n_sim, sim_duration=sim_duration, n_neurons=n_neurons,
89+
proba_conn=proba_conn)
90+
91+
# Save figure
92+
save_helper(fig=fig, iteration=iteration, export_directory=export_directory)
93+
94+
# Display inline (JupyterNotebook)
95+
# display(fig)
96+
97+
if __name__ == "__main__":
98+
plot_network_mean_weight_over_time()
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
## Testing script
2+
3+
from src.model import lifNetwork as lif
4+
from src.plotting import plotStructure as lifplot
5+
import matplotlib.pyplot as plt
6+
import matplotlib
7+
import numpy as np
8+
import os
9+
from tqdm import tqdm
10+
from datetime import datetime
11+
import numpy.typing as npt
12+
13+
14+
15+
16+
################################################################################
17+
### PLOTTING FUNCTIONS, DON'T TOUCH!!!
18+
################################################################################
19+
20+
def plot_helper(ax:plt.Axes, y:list, label:str,
21+
n_sim:int, sim_duration:float, n_neurons:int, proba_conn:float,):
22+
"""Plot the plot."""
23+
ax.plot(y, label=label, marker='+', linestyle='-')
24+
ax.set_title(f"<w(t)>\n\
25+
| n_iterations: {n_sim} | sim_duration: {sim_duration} ms |\n\
26+
| n_neurons: {n_neurons} | proba_of_connection: {proba_conn} |")
27+
ax.set_xlabel(f"n-th iteration | each iteration = {sim_duration} ms")
28+
ax.set_ylabel("mean network weight")
29+
ax.legend()
30+
31+
# ax.vlines(x=iteration*sim_duration, ymin=0, ymax=1,
32+
# label="Simulation Iteration",
33+
# color="red", alpha=0.3)
34+
# ax.set_ylim(bottom=0, top=1)
35+
# ax.set_xlim(left=0, right=n_sim*sim_duration)
36+
# plt.legend()
37+
38+
return ax
39+
40+
def save_helper(fig:matplotlib.figure.Figure, iteration:int, export_directory:str) -> None:
41+
"""Save the plot in current working directory."""
42+
# Export plot
43+
os.makedirs(export_directory, exist_ok=True)
44+
fig.savefig(f"{export_directory}/iteration_{iteration}.png",
45+
facecolor="white")
46+
return
47+
48+
def plot_network_mean_weight_over_time(n_neurons:int=300,
49+
n_sim:int=10000,
50+
sim_duration:float=100,
51+
proba_conn:float=0.08,
52+
mean_w:list=[0.1, 0.2, 0.3, 0.5],
53+
export_iteration_skip:int=10,
54+
plot_dim:tuple=(25, 10)):
55+
"""Plot the mean network weight over time."""
56+
57+
# Set variables
58+
export_directory = "export_"+datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
59+
holder_mean_network_w = {}
60+
holder_LIF = {}
61+
62+
# Instantiate a model for each mean_w item
63+
for each_mean_w in mean_w:
64+
name = f"mean_w={each_mean_w}"
65+
holder_LIF[name] = lif.LIF_Network(n_neurons=n_neurons)
66+
holder_LIF[name].random_conn(proba_conn=proba_conn, mean_w=each_mean_w)
67+
# lifplot.plot_structure(holder_LIF[name])
68+
holder_mean_network_w[name] = []
69+
70+
# Run each of the n_sim
71+
for iteration in tqdm(np.arange(n_sim),
72+
desc=f"Simulation progress - total of {n_sim} simulations"):
73+
# Simulate for each model
74+
for nn_name, nn in holder_LIF.items():
75+
nn.simulate(sim_duration=sim_duration)
76+
mean_network_w = nn.calc_nn_mean_w()
77+
holder_mean_network_w[nn_name].append(mean_network_w)
78+
79+
# Plot every `export_iteration_skip`-th simulation iteration
80+
if (iteration % export_iteration_skip == 0):
81+
fig, ax = plt.subplots(figsize=plot_dim)
82+
83+
# Plot for each of the mean_w
84+
for nn_name, mean_network_w in holder_mean_network_w.items():
85+
plot_helper(ax=ax, y=mean_network_w, label=nn_name,
86+
n_sim=n_sim, sim_duration=sim_duration, n_neurons=n_neurons,
87+
proba_conn=proba_conn)
88+
89+
# Save figure
90+
save_helper(fig=fig, iteration=iteration, export_directory=export_directory)
91+
92+
# Display inline (JupyterNotebook)
93+
# display(fig)
94+
95+
if __name__ == "__main__":
96+
plot_network_mean_weight_over_time()
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
## Testing script
2+
3+
from src.model import lifNetwork as lif
4+
from src.plotting import plotStructure as lifplot
5+
import matplotlib.pyplot as plt
6+
import matplotlib
7+
import numpy as np
8+
import os
9+
from tqdm import tqdm
10+
from datetime import datetime
11+
import numpy.typing as npt
12+
13+
14+
15+
16+
################################################################################
17+
### PLOTTING FUNCTIONS, DON'T TOUCH!!!
18+
################################################################################
19+
20+
def plot_helper(ax:plt.Axes, y:list, label:str,
21+
n_sim:int, sim_duration:float, n_neurons:int, proba_conn:float,):
22+
"""Plot the plot."""
23+
ax.plot(y, label=label, marker='+', linestyle='-')
24+
ax.set_title(f"<w(t)>\n\
25+
| n_iterations: {n_sim} | sim_duration: {sim_duration} ms |\n\
26+
| n_neurons: {n_neurons} | proba_of_connection: {proba_conn} |")
27+
ax.set_xlabel(f"n-th iteration | each iteration = {sim_duration} ms")
28+
ax.set_ylabel("mean network weight")
29+
ax.legend()
30+
31+
# ax.vlines(x=iteration*sim_duration, ymin=0, ymax=1,
32+
# label="Simulation Iteration",
33+
# color="red", alpha=0.3)
34+
# ax.set_ylim(bottom=0, top=1)
35+
# ax.set_xlim(left=0, right=n_sim*sim_duration)
36+
# plt.legend()
37+
38+
return ax
39+
40+
def save_helper(fig:matplotlib.figure.Figure, iteration:int, export_directory:str) -> None:
41+
"""Save the plot in current working directory."""
42+
# Export plot
43+
os.makedirs(export_directory, exist_ok=True)
44+
plt.grid(True)
45+
fig.savefig(f"{export_directory}/iteration_{iteration}.png",
46+
facecolor="white")
47+
return
48+
49+
def plot_network_mean_weight_over_time(n_neurons:int=500,
50+
n_sim:int=50000,
51+
sim_duration:float=1000,
52+
proba_conn:float=0.08,
53+
mean_w:list=[0.1, 0.2, 0.3, 0.5],
54+
export_iteration_skip:int=10,
55+
plot_dim:tuple=(25, 10)):
56+
"""Plot the mean network weight over time."""
57+
58+
# Set variables
59+
export_directory = "export_"+datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
60+
holder_mean_network_w = {}
61+
holder_LIF = {}
62+
63+
# Instantiate a model for each mean_w item
64+
for each_mean_w in mean_w:
65+
name = f"mean_w={each_mean_w}"
66+
holder_LIF[name] = lif.LIF_Network(n_neurons=n_neurons)
67+
holder_LIF[name].random_conn(proba_conn=proba_conn, mean_w=each_mean_w)
68+
# lifplot.plot_structure(holder_LIF[name])
69+
holder_mean_network_w[name] = []
70+
71+
# Run each of the n_sim
72+
for iteration in tqdm(np.arange(n_sim),
73+
desc=f"Simulation progress - total of {n_sim} simulations"):
74+
# Simulate for each model
75+
for nn_name, nn in holder_LIF.items():
76+
nn.simulate(sim_duration=sim_duration)
77+
mean_network_w = nn.calc_nn_mean_w()
78+
holder_mean_network_w[nn_name].append(mean_network_w)
79+
80+
# Plot every `export_iteration_skip`-th simulation iteration
81+
if (iteration % export_iteration_skip == 0):
82+
fig, ax = plt.subplots(figsize=plot_dim)
83+
84+
# Plot for each of the mean_w
85+
for nn_name, mean_network_w in holder_mean_network_w.items():
86+
plot_helper(ax=ax, y=mean_network_w, label=nn_name,
87+
n_sim=n_sim, sim_duration=sim_duration, n_neurons=n_neurons,
88+
proba_conn=proba_conn)
89+
90+
# Save figure
91+
save_helper(fig=fig, iteration=iteration, export_directory=export_directory)
92+
93+
# Display inline (JupyterNotebook)
94+
# display(fig)
95+
96+
if __name__ == "__main__":
97+
plot_network_mean_weight_over_time()

src/modelTestingScripts/5_modelTest_tony_aliCapacitance_kappa8.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Testing script
22

3-
from src.model import lifNetwork_tonyTEST as lif
3+
from src.model import lifNetwork_test_tony as lif
44
from src.plotting import plotStructure as lifplot
55
import matplotlib.pyplot as plt
66
import numpy as np

src/modelTestingScripts/6_modelTest_tony_aliCapacitance_kappa400.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Testing script
22

3-
from src.model import lifNetwork_tonyTEST as lif
3+
from src.model import lifNetwork_test_tony as lif
44
from src.plotting import plotStructure as lifplot
55
import matplotlib.pyplot as plt
66
import numpy as np

src/modelTestingScripts/7_modelTest_tony_paperCapacitance_kappa8.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Testing script
22

3-
from src.model import lifNetwork_tonyTEST as lif
3+
from src.model import lifNetwork_test_tony as lif
44
from src.plotting import plotStructure as lifplot
55
import matplotlib.pyplot as plt
66
import numpy as np

src/modelTestingScripts/8_modelTest_tony_paperCapacitance_kappa400.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Testing script
22

3-
from src.model import lifNetwork_tonyTEST as lif
3+
from src.model import lifNetwork_test_tony as lif
44
from src.plotting import plotStructure as lifplot
55
import matplotlib.pyplot as plt
66
import numpy as np

0 commit comments

Comments
 (0)