Update app.py
Browse files
app.py
CHANGED
|
@@ -75,32 +75,36 @@ def visualize_multi_grid_vram(memory_grids):
|
|
| 75 |
|
| 76 |
return fig # Return the whole figure object
|
| 77 |
|
| 78 |
-
# Generate Spike Train using LIF Neurons
|
| 79 |
def generate_lif_spike_train(length=50, input_current=0.5):
|
| 80 |
lif_neuron = LIFNeuron()
|
| 81 |
-
spike_train = [
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
# Visualize LIF Spike Train (Real-Time Update)
|
| 85 |
-
def visualize_lif_spike_train(spike_train):
|
| 86 |
-
fig,
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
-
# New: Visualizing Synapse Learning with Action Potentials (Real-Time Update)
|
| 96 |
-
def visualize_synapse_learning(spike_train):
|
| 97 |
-
membrane_potential = np.cumsum(spike_train) # Simulating action potentials
|
| 98 |
-
fig, ax = plt.subplots(figsize=(6, 4))
|
| 99 |
-
ax.plot(membrane_potential, color='r', marker='x', linestyle='-', markersize=5)
|
| 100 |
-
ax.set_title("Synaptic Learning - Action Potential Over Time")
|
| 101 |
-
ax.set_xlabel("Time Steps")
|
| 102 |
-
ax.set_ylabel("Membrane Potential")
|
| 103 |
-
ax.grid(True)
|
| 104 |
return fig # Return the whole figure object
|
| 105 |
|
| 106 |
# Generate Multi-Grid Spikes and VRAM Updates
|
|
@@ -111,14 +115,14 @@ def generate_spikes_for_pressure(pressure, grid_count=3):
|
|
| 111 |
model = load_model(grid_count=grid_count)
|
| 112 |
if model is not None:
|
| 113 |
outputs, memory_grids = model(pressure_input)
|
| 114 |
-
spike_train = generate_lif_spike_train(length=50, input_current=pressure_normalized)
|
| 115 |
-
return outputs, memory_grids, spike_train
|
| 116 |
-
return None, None, None
|
| 117 |
|
| 118 |
# Streamlit UI for Real-time Visualization
|
| 119 |
def app():
|
| 120 |
st.title("Neuromorphic Multi-Grid VRAM & LIF Spiking Network")
|
| 121 |
-
st.write("Observe
|
| 122 |
|
| 123 |
pressure = st.slider("Select Pressure (MPa)", 0.1, 1.0, 0.5, 0.1)
|
| 124 |
grid_count = st.slider("Number of VRAM Grids", 1, 5, 3)
|
|
@@ -130,25 +134,21 @@ def app():
|
|
| 130 |
# Create empty containers for real-time plotting
|
| 131 |
plot_vram = st.empty()
|
| 132 |
plot_spike_train = st.empty()
|
| 133 |
-
plot_synapse = st.empty()
|
| 134 |
|
| 135 |
-
# Layout: VRAM plots on top, Spike and
|
| 136 |
st.write("### VRAM Grids (Above)")
|
| 137 |
-
st.write("### LIF Spike Train &
|
| 138 |
|
| 139 |
end_time = time.time() + duration * 60
|
| 140 |
while time.time() < end_time:
|
| 141 |
-
outputs, memory_grids, spike_train = generate_spikes_for_pressure(pressure, grid_count)
|
| 142 |
|
| 143 |
if outputs is not None and memory_grids is not None:
|
| 144 |
# Update VRAM plots dynamically
|
| 145 |
plot_vram.pyplot(visualize_multi_grid_vram(memory_grids))
|
| 146 |
|
| 147 |
-
# Update Spike Train plot
|
| 148 |
-
plot_spike_train.pyplot(visualize_lif_spike_train(spike_train))
|
| 149 |
-
|
| 150 |
-
# Update Synapse Learning plot
|
| 151 |
-
plot_synapse.pyplot(visualize_synapse_learning(spike_train))
|
| 152 |
|
| 153 |
time.sleep(0.2) # Update every 0.2 seconds
|
| 154 |
|
|
|
|
| 75 |
|
| 76 |
return fig # Return the whole figure object
|
| 77 |
|
| 78 |
+
# Generate Spike Train using LIF Neurons (Dynamic to Pressure)
|
| 79 |
def generate_lif_spike_train(length=50, input_current=0.5):
|
| 80 |
lif_neuron = LIFNeuron()
|
| 81 |
+
spike_train = []
|
| 82 |
+
membrane_potentials = []
|
| 83 |
+
for t in range(length):
|
| 84 |
+
spike = lif_neuron.step(input_current)
|
| 85 |
+
spike_train.append(spike)
|
| 86 |
+
membrane_potentials.append(lif_neuron.v)
|
| 87 |
+
return spike_train, membrane_potentials
|
| 88 |
|
| 89 |
# Visualize LIF Spike Train (Real-Time Update)
|
| 90 |
+
def visualize_lif_spike_train(spike_train, membrane_potentials):
|
| 91 |
+
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(6, 8))
|
| 92 |
+
|
| 93 |
+
# Plot Spike Train
|
| 94 |
+
ax1.plot(spike_train, marker='o', linestyle='-', color='b', markersize=5)
|
| 95 |
+
ax1.set_title("LIF Neuron Spike Train")
|
| 96 |
+
ax1.set_xlabel("Time Steps")
|
| 97 |
+
ax1.set_ylabel("Spike Event (1 = Spike, 0 = No Spike)")
|
| 98 |
+
ax1.set_yticks([0, 1])
|
| 99 |
+
ax1.grid(True)
|
| 100 |
+
|
| 101 |
+
# Plot Membrane Potentials
|
| 102 |
+
ax2.plot(membrane_potentials, color='r', marker='x', linestyle='-', markersize=5)
|
| 103 |
+
ax2.set_title("Membrane Potential Over Time")
|
| 104 |
+
ax2.set_xlabel("Time Steps")
|
| 105 |
+
ax2.set_ylabel("Membrane Potential (mV)")
|
| 106 |
+
ax2.grid(True)
|
| 107 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
return fig # Return the whole figure object
|
| 109 |
|
| 110 |
# Generate Multi-Grid Spikes and VRAM Updates
|
|
|
|
| 115 |
model = load_model(grid_count=grid_count)
|
| 116 |
if model is not None:
|
| 117 |
outputs, memory_grids = model(pressure_input)
|
| 118 |
+
spike_train, membrane_potentials = generate_lif_spike_train(length=50, input_current=pressure_normalized)
|
| 119 |
+
return outputs, memory_grids, spike_train, membrane_potentials
|
| 120 |
+
return None, None, None, None
|
| 121 |
|
| 122 |
# Streamlit UI for Real-time Visualization
|
| 123 |
def app():
|
| 124 |
st.title("Neuromorphic Multi-Grid VRAM & LIF Spiking Network")
|
| 125 |
+
st.write("Observe how pressure input affects the VRAM grids, LIF spikes, and membrane potential in real-time.")
|
| 126 |
|
| 127 |
pressure = st.slider("Select Pressure (MPa)", 0.1, 1.0, 0.5, 0.1)
|
| 128 |
grid_count = st.slider("Number of VRAM Grids", 1, 5, 3)
|
|
|
|
| 134 |
# Create empty containers for real-time plotting
|
| 135 |
plot_vram = st.empty()
|
| 136 |
plot_spike_train = st.empty()
|
|
|
|
| 137 |
|
| 138 |
+
# Layout: VRAM plots on top, Spike and Membrane Potentials below
|
| 139 |
st.write("### VRAM Grids (Above)")
|
| 140 |
+
st.write("### LIF Spike Train & Membrane Potential (Below)")
|
| 141 |
|
| 142 |
end_time = time.time() + duration * 60
|
| 143 |
while time.time() < end_time:
|
| 144 |
+
outputs, memory_grids, spike_train, membrane_potentials = generate_spikes_for_pressure(pressure, grid_count)
|
| 145 |
|
| 146 |
if outputs is not None and memory_grids is not None:
|
| 147 |
# Update VRAM plots dynamically
|
| 148 |
plot_vram.pyplot(visualize_multi_grid_vram(memory_grids))
|
| 149 |
|
| 150 |
+
# Update Spike Train and Membrane Potential plot
|
| 151 |
+
plot_spike_train.pyplot(visualize_lif_spike_train(spike_train, membrane_potentials))
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
time.sleep(0.2) # Update every 0.2 seconds
|
| 154 |
|