SC-NeuroCore — Quick Start on Google Colab¶
Install SC-NeuroCore and run a minimal spiking neural network in under 2 minutes.
In [ ]:
!pip install -q sc-neurocore
1. Single LIF Neuron¶
In [ ]:
from sc_neurocore.neurons.stochastic_lif import StochasticLIFNeuron
import numpy as np
neuron = StochasticLIFNeuron(v_threshold=1.0, tau_mem=20.0, noise_std=0.02)
spikes = []
for t in range(200):
current = 0.8 + 0.3 * np.sin(2 * np.pi * t / 50)
spike = neuron.step(current)
spikes.append(spike)
print(f"Total spikes: {sum(spikes)} / 200 steps")
print(f"Firing rate: {sum(spikes)/200:.1%}")
2. Dense Layer (5 neurons)¶
In [ ]:
from sc_neurocore.layers.vectorized_layer import VectorizedSCLayer
layer = VectorizedSCLayer(n_inputs=10, n_neurons=5, length=512)
inputs = np.random.uniform(0.3, 0.7, 10)
output = layer.forward(inputs)
print("Output firing rates:", np.round(output, 3))
3. Spike Raster Plot¶
In [ ]:
import matplotlib.pyplot as plt
neurons = [StochasticLIFNeuron(v_threshold=1.0, tau_mem=20.0, noise_std=0.02, seed=i) for i in range(5)]
T = 200
raster = np.zeros((5, T), dtype=int)
for t in range(T):
for i, n in enumerate(neurons):
current = 0.6 + 0.4 * np.sin(2 * np.pi * (t + i * 40) / 100)
raster[i, t] = n.step(current)
fig, ax = plt.subplots(figsize=(10, 3))
for i in range(5):
spike_times = np.where(raster[i])[0]
ax.scatter(spike_times, np.full_like(spike_times, i), s=2, c='#1f77b4')
ax.set_xlabel("Time Step")
ax.set_ylabel("Neuron")
ax.set_title("SC-NeuroCore \u2014 LIF Spike Raster")
ax.set_yticks(range(5))
plt.tight_layout()
plt.show()
4. Stochastic Computing Convolution¶
In [ ]:
from sc_neurocore.layers.sc_conv_layer import SCConv2DLayer
conv = SCConv2DLayer(in_channels=1, out_channels=4, kernel_size=3, padding=1)
image = np.random.uniform(0, 1, (1, 8, 8))
output = conv.forward(image)
print(f"Input: {image.shape} \u2192 Output: {output.shape}")