Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • 34eda6e
  • /
  • neural_decoding
  • /
  • neural_decoding.py
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:cb6e85bc1b67971488e5a05f98b16c005edf0ba9
directory badge
swh:1:dir:edb0c430edb630930b7d19e07adfaa41e865a4c5

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
neural_decoding.py
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 21 14:53:21 2021

@author: adrie
"""


import pynapple as nap
import pandas as pd
from sklearn.preprocessing import StandardScaler
import numpy as np

def bayesian_decoder_1d(spike_counts, bin_size, tuning_curves):
    
    spike_counts_array = spike_counts.values
    proba_angle = np.zeros((spike_counts.shape[0], tuning_curves.shape[0]))

    part1 = np.exp(-(bin_size/1000)*tcurves_array.sum(1))    
    part2 = px
    
    for i in range(len(proba_angle)):
        part3 = np.prod(tcurves_array**spike_counts_array[i], 1)
        p = part1 * part2 * part3
        proba_angle[i] = p/p.sum() # Normalization process here

    proba_angle  = pd.DataFrame(index = spike_counts.index.values, columns = tuning_curves.index.values, data= proba_angle)    

    decoded = nts.Tsd(t = proba_angle.index.values, d = proba_angle.idxmax(1).values, time_units = 'ms')

    return decoded, proba_angle

def latent_decoder_ring(spike_counts, method='isomap', count_nor = 'sqrt'):
    
    from numpy import linalg as LA
    
    spk = spike_counts.values

    match count_norm:
        case 'sqrt':            
            spk = np.sqrt(spk)
        case 'zscore'
            spk = StandardScaler().fit_transform(spk)
        
        
    match method:
        case 'isomap':
            from sklearn.manifold import Isomap
            embedding = Isomap(n_components=2)
            
    spk_transformed = embedding.fit_transform(X)
    
    theta = np.arctan2(spk_transformed[1,:], spk_transformed[0,:])
    rho = LA.norm(spk_transformed, axis=0)          
    
    return theta, rho, embeddings 

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API