forked from h-mayorquin/BCPNN_sequences
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
85 lines (66 loc) · 2.54 KB
/
main.py
File metadata and controls
85 lines (66 loc) · 2.54 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
# main.py
import numpy as np
import matplotlib.pyplot as plt
from network import Protocol, NetworkManager, BCPNNPerfect # , BCPNNModular
from plotting_functions import plot_weight_matrix, plot_state_variables_vs_time, plot_winning_pattern
from plotting_functions import plot_network_activity, plot_network_activity_angle
from analysis_functions import calculate_recall_time_quantities, calculate_angle_from_history
# ---- 1. DEFINE SIMULATION PARAMETERS ----
# Network parameters
g_w_ampa = 2.0
g_w = 0.0
g_a = 10.0
tau_a = 0.250
G = 1.0
sigma = 0.0
# Pattern parameters
hypercolumns = 1
minicolumns = 10
n_patterns = 10
# Manager properties
dt = 0.001
values_to_save = ['o'] # Only save 'o' (output activity) for this example
# Protocol parameters
training_time = 0.100
inter_pulse_interval = 0.0
inter_sequence_interval = 1.0
epochs = 15
# ---- 2. BUILD AND TRAIN THE NETWORK ----
# Initialize the BCPNN network with specified parameters
nn = BCPNNPerfect(hypercolumns, minicolumns, g_w_ampa=g_w_ampa, g_w=g_w, g_a=g_a, tau_a=tau_a,
sigma=sigma, G=G,
z_transfer=False, diagonal_zero=False, strict_maximum=True, perfect=True)
# Initialize the manager to handle the network simulation
manager = NetworkManager(nn=nn, dt=dt, values_to_save=values_to_save)
# Define the training protocol
protocol = Protocol()
patterns_indexes = list(range(n_patterns))
protocol.simple_protocol(patterns_indexes, training_time=training_time,
inter_pulse_interval=inter_pulse_interval,
inter_sequence_interval=inter_sequence_interval,
epochs=epochs)
# Run the training protocol
print("Starting network training...")
manager.run_network_protocol(protocol=protocol, verbose=True)
print("Training complete.")
# Plot the learned weight matrix
plot_weight_matrix(manager.nn, ampa=True)
plt.suptitle("Learned AMPA Weight Matrix")
plt.show()
# ---- 3. RUN RECALL AND ANALYSIS ----
# Recall parameters
T_recall = 2.0
T_cue = 0.100
sequences = [patterns_indexes]
I_cue = 0.0
n_trials = 1 # Number of recall trials
# Calculate recall performance metrics
print("\nStarting recall analysis...")
aux = calculate_recall_time_quantities(manager, T_recall, T_cue, n_trials, sequences)
total_sequence_time, mean_time, std_time, success_rate, timings = aux
# Plot network activity during recall
plot_network_activity_angle(manager)
plt.suptitle("Network Activity During Recall")
plt.show()
print(f"Recall Success Rate: {success_rate}%")
print(f"Total time for sequence recall: {total_sequence_time:.2f}s")