lposani / decodanda

Decoding and geometrical analysis of neural activity with built-in best practices
GNU General Public License v3.0
29 stars 3 forks source link

Does `decondanda` only work with binary conditions/variables? #1

Closed qsimeon closed 1 year ago

qsimeon commented 1 year ago

First off, really great package! I am honored to be the first to post an issue. I was wondering whether the Decodanda class only works with binary task variables? For example in the Bernardi et al. 2020 paper, there stimulus variable could take four values 'A', 'B', 'C' and 'D' corresponding to the four distinct fractal images the monkeys were trained on. I've trained a neural network model and collected the activations of some layer (16 units = 16 "neurons") and eventually I want to get to doing the CCGP. Here's my code omitting all the model and dataset stuff.

data = {
    'raster': raster,   # <TxN array>, neural activations 
    'context': context, # <Tx1 array>, labels
    'stimulus': stimulus, # <Tx1 array>, labels
    'action': action,    # <Tx1 array>, labels
    'reinforcer': action,    # <Tx1 array>, labels
    'trial': trial, # <Tx1 array>, trial number
}

conditions = {
    'stimulus': np.unique(stimulus).tolist(),
}
print(conditions)

dec = Decodanda(data=data, conditions=conditions, verbose=True)

performances, null = dec.decode(
                        training_fraction=0.5,  # fraction of trials used for training
                        cross_validations=10,   # number of cross validation folds
                        nshuffles=20)           # number of null model iterations

print(performances)
print(null)

This outputs """ {'stimulus': [0, 1, 2, 3]} {'stimulus': 1.0} {'stimulus': array([0.49646302, 0.49308682, 0.5153537 , 0.525 , 0.49533762, 0.53553055, 0.50393891, 0.5068328 , 0.48561093, 0.51109325, 0.49847267, 0.50217042, 0.51655949, 0.49742765, 0.49766881, 0.51197749, 0.52974277, 0.49019293, 0.49533762, 0.50562701])} """

But I can't trust that this is correct since I don't think that decondanda is designed to work with variables that are not binary (in this case stimulus is quaternary). So my question (not really "issue") is am I correct in thinking that?

lposani commented 1 year ago

Hi Quilee, thank you for your interest in the package :) Decodanda is currently designed to handle binary variables only. I am working on an expansion to multi-class, but in the meantime, you can "binarize" stimulus by dividing stimuli into two groups of two, or by only using two stimuli at a time. For example conditions = { 'stimulus': { 'A': lambda d: d['stimulus'] < 2, 'B': lambda d: d['stimulus'] >= 2, } } to group the stimuli into two groups, or conditions = {'stimulus':[1, 2]} for using only two at a time

JensBlack commented 4 months ago

@lposani

Great package! Thank you for making it.

Has this feature been added yet?

lposani commented 4 months ago

Hi @JensBlack, I have not added this feature yet, but given that several people seem to ask for it, I will speed up the development!