chongxi / spiketag

Next generation of spike sorting package for BMI
BSD 3-Clause "New" or "Revised" License
6 stars 4 forks source link

A BMI class contains both the real-time packet interface and the memory interface #58

Open chongxi opened 4 years ago

chongxi commented 4 years ago

https://github.com/chongxi/spiketag/commit/7ddcc9a3cf01c15c126736edd131c24db3180932

To simply high-level programming. I decided to build this class in a way it can be used in any stage of the processing.

0. To configure FPGA with sorting:

from spiketag.base import probe
from spiketag.realtime import BMI
prb = probe(prb_file)
bmi = BMI(prb)

Then check bmi.fpga

Two parameters are critical in the pathway to convert spiking activities into behaviour bin_size T and bin_number B

1. To start and stop the BMI:

from spiketag.base import probe
from spiketag.realtime import BMI

prb = probe(prb_file)
bmi = BMI(prb, fetfile)
bmi.set_binner(bin_size, bin_number)
#optional: bmi.set_decoder(dec, dec_file)
bmi.start(gui_queue=True)
bmi.stop()

2. To check the memory interface:

bmi.fpga.configured_groups      (this tells which groups will report spike-id packet) 
bmi.fpga.n_units            (this tells how many neurons will report spike-id packet)
bmi.fpga.target_unit    (this controls which neuron generate the spike TTL from FPGA)

bmi.fpga.ch_grpNo
bmi.fpga.ch_hash
bmi.fpga.ch_ref
bmi.fpga.thres[grp_id]
bmi.fpga.scale[grp_id]
bmi.fpga.shift[grp_id]
bmi.fpga.pca[grp_id]
bmi.fpga.vq[grp_id]
bmi.fpga.label[grp_id]

as simple as that,

3. then we connect decoder to the binner which is part of the bmi

dec = NaiveBayes(t_step=bin_size, t_window=B_bins*bin_size)
dec.connect_to(pc)
dec.partition(training_range=[0.0, .5], valid_range=[0.5, 0.6], testing_range=[0.6, 1.0])
(train_X, train_y), (valid_X, valid_y), (test_X, test_y) = dec.get_data()
dec.fit(train_X, train_y)
predicted_y = dec.predict(test_X)
score = dec.evaluate(smooth(predicted_y, 60), test_y)
bmi.connect_to(dec)

Because bmi already has its own bin_size and bin_number it is easier to wrap all above procedure into one line of code

bmi.set_decoder(`NaiveBayes`)
chongxi commented 4 years ago

All of the above-fantasized APIs require shared memory between the binner and decoder. Remember they will be running on different processors. To be specific, the decoder will be triggered dec.predict(X) each time when a new bin is filled X=binner.output()

chongxi commented 4 years ago

image

chongxi commented 4 years ago

To make it consistent to the decoder input structure, the input matrix shape is changed to (B_bins, N_units)