Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Organizing the neurons on a firing pattern plot #950

Open
celiasmith opened this issue Apr 13, 2018 · 2 comments
Open

Organizing the neurons on a firing pattern plot #950

celiasmith opened this issue Apr 13, 2018 · 2 comments

Comments

@celiasmith
Copy link
Contributor

It'd be nice to have an option to organize the neurons on a firing pattern plot (like in the old GUI). Where neurons with similar tuning are near each other. It makes the output look more like calcium imaging and fMRI data.

@tcstewar
Copy link
Collaborator

Agreed. Right now, you can sort of do that manually by defining your own encoders, but we should either have a helper function to do that, or build it into the GUI the same way we did in Nengo 1.4....

@tcstewar
Copy link
Collaborator

Here's a quick helper function that does this!

import nengo

import numpy as np

def compute_score(encoders, order, width, index):
    N = len(encoders)
    score = 0
    
    e = encoders[order[index]]
    deltas = [1, -1, width, -width]
    for delta in deltas:
        e2 = encoders[order[(index+delta)%N]]        
        score += np.dot(e, e2)
    return score
    

def reorganize(encoders, width, iterations=10, seed=None):
    N = len(encoders)
    order = np.arange(N)
    
    rng = np.random.RandomState(seed=seed)
    items = np.random.randint(N, size=(iterations*N, 2))
    
    for i,j in items:
        if i != j:
            score = compute_score(encoders, order, width, i) + compute_score(encoders, order, width, j)
            order[[i,j]] = order[[j,i]]
            score_swap = compute_score(encoders, order, width, i) + compute_score(encoders, order, width, j)
            if score_swap < score:
                order[[i,j]] = order[[j,i]]
                
    return encoders[order]


model = nengo.Network()
with model:
    
    stim = nengo.Node(lambda t: [np.sin(2*np.pi*t), np.cos(2*np.pi*t)])
    
    ens = nengo.Ensemble(n_neurons=400, dimensions=2)
    enc = nengo.dists.UniformHypersphere(surface=True).sample(ens.n_neurons, d=2)
    enc2 = reorganize(enc, int(np.ceil(np.sqrt(ens.n_neurons))), seed=1, iterations=10) 
    ens.encoders = enc2
    
    nengo.Connection(stim, ens)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants