Replies: 1 comment 1 reply
-
This piece of code might be useful: import numpy as np
import matplotlib.pyplot as plt
from lava.lib.dl import slayer
import torch
from matplotlib import pyplot as plt
fs = 100e3 # 100 KHz
fc = 15e3 # 15 KHz
sinusoid = 2.2 * np.sin(2 * np.pi * fc / fs * np.arange(2500))
noise = np.random.randn(sinusoid.shape[0])
input = torch.FloatTensor(sinusoid + noise).reshape([1, 1, -1])
rf_params = dict(threshold=2,
period= [5, 50],
decay=0.01,
shared_param=False,
log_init=True)
block = slayer.block.rf.Dense(neuron_params=rf_params, in_neurons=1, out_neurons=100)
# Overwrite the weight initialization values
block.synapse.real.weight.data = 0.1 * torch.ones_like(block.synapse.real.weight.data)
block.synapse.imag.weight.data = 0.0 * torch.ones_like(block.synapse.imag.weight.data)
out = block(input)
# Plot spiking events of RF population
ev = np.argwhere(out[0].cpu().data.numpy() > 0)
fig, ax = plt.subplots(1, 2, figsize=(10, 5), sharey=True)
ax[0].plot(ev[:, 1], ev[:, 0], '.', label='spikes')
ax[0].axis([0, input.shape[-1], 0, out.shape[1]])
ax[1].plot(block.neuron.frequency * fs, np.arange(out.shape[1]))
ax[1].vlines(x=fc, ymin=0, ymax=1000, color='gray', linestyle='dotted')
ax[0].set_xlabel('time-steps')
ax[0].set_ylabel('Neuron ID')
ax[0].legend()
ax[1].set_xlabel('Neuron center frequency (Hz)') You can play around with frequency of input, and investigate graded spike. That might give more insight on the peak. Note: A population of RF neurons act like STFT, not FFT. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everyone :)
I'm currently facing difficulties in initializing the weights of the RF-neurons. My objective is to replicate the FFT behavior observed on a white noise signal, which spans frequencies between 10KHz and 20KHz (sampling frequency= 100KHz). Additionally, I have introduced a fundamental frequency component at 15KHz.
When performing the FFT on my signal, I get a peak at the fundamental frequency (here 15 KHz). However when feeding the same signal to my 100 RF-neurons with resonating frequencies covering the whole Bandwidth (10KHz,20KHz / period=[5,10]), I keep getting random peaks.
I also expanded the signal to third dimension (time dimension).
My questions are:
1- Are the neuron weights randomized in lava-dl?
2- How should I Initialize the neuron weights to mimic the FFT.
flollowing is the code I used:
import numpy as np
import matplotlib.pyplot as plt
from lava.lib.dl import slayer
import torch
I get the following plot:
I will be extremely thankful to get some help to solve this. My thesis is based on this and it will be a major help for me. Thank you
Beta Was this translation helpful? Give feedback.
All reactions