chongxi / spiketag

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

Decoder load and save #60

Closed chongxi closed 4 years ago

chongxi commented 4 years ago

This will dramatically save time in an online experiment and simplify the BMI API.

Save after partition, but before fit

Train a decoder:

dec = NaiveBayes(t_step=bin_size, t_window=B_bins*bin_size)
dec.connect_to(pc)
dec.partition(training_range=[0.0, 1.0], valid_range=[0.5, 0.6], testing_range=[0.0, 1.0],
              low_speed_cutoff={'training': True, 'testing': False})

### save ###
dec.save('./nb_dec0')
##########

score = dec.score(smooth_sec=2)

Load and run a decoder in real-time for BMI

### load ###
from spiketag.analysis.decoder import load_decoder
dec = load_decoder('./nb_dec0')
##########

score = dec.score(smooth_sec=2)
bmi.set_decoder(dec)
chongxi commented 4 years ago

After loading the decoder and score it, we can use it to decode spike count vectors

dec.predict(dec.test_X[:3, :])

and smooth it using different parameters and rescore it (using r2_score)

predicted_y = dec.predict(dec.test_X)
smoothed_y = smooth(predicted_y, 20)
new_score = dec.r2_score(smoothed_y, dec.test_y)