コード例 #1
0
ファイル: experiment.py プロジェクト: jmulgrew/dot-experiment
    def create_images(files,repeat,frames = float('inf')):
        '''Cycles through image stimuli continously. If the experiment is paused
        or the maximum amount of frames has been presented (end of exposure period)
        then it finishes.
        '''
        def render(stim):
            if stim.done:
                return 0
            else:
                item = stim.items[stim.i%len(stim.items)]
                item['content'].draw()
                return item['value']

        def move(stim,loop=repeat,max_frames = frames):
            if loop and not stim.paused:
                if stim.i+1 >= max_frames and (stim.i+1)%len(stim.items) == 0:
                    stim.done = True
                stim.i += 0 if stim.done else 1

            elif not stim.paused:
                if stim.i+1 == len(stim.items):
                    stim.done = True
                stim.i += 0 if stim.done else 1

        # Create items
        items = [{  'content': visual.ImageStim(screen,image = file),
                    'value': 100 if file == files[0] else 0
                } for file in files]
        return stimulus(items,render,move,do_nothing)
コード例 #2
0
ファイル: experiment.py プロジェクト: jmulgrew/dot-experiment
    def create_instructions(instructions):
        '''Creates and cycles through the instructions and images in the
        experiment.yml file.
        '''
        def render(stim):
            if stim.done:
                return 0
            else:
                item = stim.items[stim.i]
                for i in item['content']:
                    i.draw()
                return item['value']

        def next(stim):
            if stim.i+1 == len(stim.items):
                stim.done = True
            stim.i += 0 if stim.done else 1

        # Create items
        items = list()
        for instruct in instructions:
            content = list()
            if instruct['text'] and instruct['img']: # second instruction screen
                content.append(visual.TextStim(screen, text=instruct['text'], alignHoriz='center', alignVert='center', pos = (0.0, -0.65), color = (1.0,1.0,1.0), height = .08, wrapWidth = 0.97))
                content.append(visual.ImageStim(screen,image = instruct['img'], pos = (0.0, 0.1)))
            else: # first instruction screen
                content.append(visual.TextStim(screen, text=instruct['text'], alignHoriz='center', alignVert='center', pos = (0.0, 0.0), color = (1.0,1.0,1.0), height = .08, wrapWidth = 0.97))
            items.append({ 'content': content, 'value': 0})

        return stimulus(items,render,do_nothing,next)
コード例 #3
0
ファイル: experiment.py プロジェクト: jmulgrew/dot-experiment
    def create_sounds(audio_dict,order,freq):
        '''Creates audio stimuli stream based on the order text file. Ensures that
        each syllable plays for 300ms. If the experiment is paused or the image
        cycle has been completed, it finishes.
        '''
        def render(stim):
            item = stim.items[stim.i]
            if not stim.paused and item is not None:
                item['content'].play()
                return item['value']
            else:
                return 0

        def move(stim):
            if not stim.paused:
                if stim.i+1 == len(stim.items):
                    stim.done = True
                else:
                    stim.i += 1
        # Create items
        items = []
        for k in order:
            items += [{
                'content': Sound(audio_dict['files'][int(k)],secs=0.3),
                'value': int(k)
            }] + [None for i in range(freq-1)]

        return stimulus(items,render,move,do_nothing)
コード例 #4
0
ファイル: fig-lesion.py プロジェクト: HiMehta/Neurosciences
def run(ax, lesion, name, title):

    S = np.zeros((len(targets),4))
    model = Model()
    model.make_lesion(lesion)

    if os.path.exists('lesion-%s.npy' % name):
        S = np.load('lesion-%s.npy' % name)
    else:
        for i,target in enumerate(targets):
            rho,theta = target
            x_,y_ = polar_to_logpolar(rho/90.0, np.pi*theta/180.0)
            x_,y_ = 2*x_, 2*y_-1
            model.reset()
            model.R = stimulus((rho, theta))
            model.run(duration=5*second, dt=5*millisecond, epsilon=0.001)
            x,y = decode(model.SC_V)
            S[i] = x_, y_, x, y
            print 'Target at (%d,%d): %f' % (rho,theta, np.sqrt((x-x_)*(x-x_) + (y-y_)*(y-y_)))
        np.save('lesion-%s.npy' % name, S)

    logpolar_frame(ax)
    for i in range(len(S)):
        ax.plot([S[i,0],S[i,2]],[S[i,1],S[i,3]], color='k', lw=.5)
    ax.scatter(S[:,0], S[:,1], s=35, color='k', marker='o', lw=.5)
    ax.scatter(S[:,2], S[:,3], s=35, color='k', marker='o', facecolors='w', lw=.5)
    ax.text(0,-1, title, ha="left", va="top", fontsize=14)
    if lesion is not None:
        position,size = lesion
        rho,theta = position
        rho,theta = rho/90.0, np.pi*theta/180.0
        x,y = polar_to_logpolar(rho,theta)
        radius = size/90.0
        ax.add_patch(plt.Circle((2*x,2*y-1), radius=radius,  ec='k', fc='w', zorder=+10, alpha=.5))
        ax.add_patch(plt.Circle((2*x,2*y-1), radius=radius,  ec='k', lw=.5, fc='none', zorder=+15))
コード例 #5
0
ファイル: fig-lesion.py プロジェクト: mtopalid/Neurosciences
def run(ax, lesion, name, title):

    S = np.zeros((len(targets),4))
    model = Model()
    model.make_lesion(lesion)

    if os.path.exists('lesion-%s.npy' % name):
        S = np.load('lesion-%s.npy' % name)
    else:
        for i,target in enumerate(targets):
            rho,theta = target
            x_,y_ = polar_to_logpolar(rho/90.0, np.pi*theta/180.0)
            x_,y_ = 2*x_, 2*y_-1
            model.reset()
            model.R = stimulus((rho, theta))
            model.run(duration=5*second, dt=5*millisecond, epsilon=0.001)
            x,y = decode(model.SC_V)
            S[i] = x_, y_, x, y
            print 'Target at (%d,%d): %f' % (rho,theta, np.sqrt((x-x_)*(x-x_) + (y-y_)*(y-y_)))
        np.save('lesion-%s.npy' % name, S)

    logpolar_frame(ax)
    for i in range(len(S)):
        ax.plot([S[i,0],S[i,2]],[S[i,1],S[i,3]], color='k', lw=.5)
    ax.scatter(S[:,0], S[:,1], s=35, color='k', marker='o', lw=.5)
    ax.scatter(S[:,2], S[:,3], s=35, color='k', marker='o', facecolors='w', lw=.5)
    ax.text(0,-1, title, ha="left", va="top", fontsize=14)
    if lesion is not None:
        position,size = lesion
        rho,theta = position
        rho,theta = rho/90.0, np.pi*theta/180.0
        x,y = polar_to_logpolar(rho,theta)
        radius = size/90.0
        ax.add_patch(plt.Circle((2*x,2*y-1), radius=radius,  ec='k', fc='w', zorder=+10, alpha=.5))
        ax.add_patch(plt.Circle((2*x,2*y-1), radius=radius,  ec='k', lw=.5, fc='none', zorder=+15))
コード例 #6
0
 def setStim(self, amp, delta, T, times):
     self.amp = amp  #amplitude
     self.delta = delta  # period bt stim
     self.T = T  # period stim
     self.times = times
     self.mystim = stimulus(self.patterns, self.lagStim, self.delta, self.T,
                            self.times)
     self.mystim.inten = self.amp
コード例 #7
0
    def __init__(self):  #Global parameters needed
        # single neuron
        self.n = 10  #n pop
        self.tau = 10.  #timescale of populations
        self.nu = 1.  # slope PWL TF
        self.theta = 0.  # lower threshold
        self.uc = 1.  #upper threshold

        # Learning Rule
        self.wmax = 1.8  # maximum learned
        self.thres = 0.6  # threshold
        self.delay = 15.3  # delay
        self.w0 = 0.01  # initial condition dynamics
        bf = 10.  # slope f and g
        xf = 0.7  # threshold f and g
        self.a_post = bf
        self.b_post = xf
        self.a_pre = bf
        self.b_pre = xf
        self.tau_learning = 400.  # time scale LR

        # stimulus
        self.amp = 5.5  #amplitude
        self.patterns = np.identity(self.n)  # stimulation matrix
        self.patterns = [self.patterns[:, i]
                         for i in range(self.n)]  # puting in a list
        self.dt = 0.5  # dt dinamics
        self.npts = int(np.floor(self.delay / self.dt) + 1)  # points delay
        self.lagStim = 100.  # lag before stimulation
        self.delta = 10.  # period bt stim
        self.T = 10.  # period stim
        self.times = 150
        self.mystim = stimulus(self.patterns, self.lagStim, self.delta, self.T,
                               self.times)
        self.mystim.inten = self.amp

        #Homeostatic LR
        self.tau_H = 200000.  # tau
        self.y0 = .12 * np.ones(self.n)  # target rate

        #inhibition
        self.w_i = 2.

        #if there is noise in the simulations
        self.amp_noise = 0
コード例 #8
0
a_pre = 0.5
b_pre = -3.0
tau_learning = 10.0


# comment this lines if you don t want to load or save the parameters of the simulation
# name='failure_learning2.param'
# save_param(name)
# load_param(name)


w_inh = w_i / n
r1_matrix = np.ones((n, n))
patterns = np.identity(n)
patterns = [patterns[:, i] for i in range(n)]
mystim = stimulus(patterns, lagStim, delta, period, times)
mystim.inten = amp

# integrator
npts = int(np.floor(delay / dt) + 1)  # points delay
tmax = times * (lagStim + n * (period + delta)) + 40
# initial conditions
x0 = 0.01 * np.ones((npts, n))
W0 = [(wmax / n) * np.ones((n, n)) for i in range(npts)]
theintegrator = myintegrator(delay, dt, n, tmax)
theintegrator.fast = False
rowsum, u, Wdiag, Woffdiag, connectivity, W01, t = theintegrator.DDE_Norm_additive(field, x0, W0)


# new instance of the model
# with no stimulation
コード例 #9
0
a_pre=bf
b_pre=xf
tau_learning=400.#30000.

a1=6.
b1=-0.25
#-------------------------------------------------------------------
#-----------------Stimulation of Populations------------------------
#-------------------------------------------------------------------

# setting up the simulation 

r1_matrix=np.ones((n,n))
patterns=np.identity(n)
patterns=[patterns[:,i] for i in range(n)]
mystim=stimulus(patterns,lagStim,delta,period,times)
mystim.inten=amp

#integrator
npts=int(np.floor(delay/dt)+1)         # points delay
tmax=times*(lagStim+n*(period+delta))+100.+mystim.delay_begin

thetmax=tmax+15.5*tau_H

#initial conditions
a0=np.zeros((npts,n))
x0=0.1*np.ones((npts,n))
W0=[0.1*np.ones((n,n)) for i in range(npts)]
H0=[np.array([0.1 for i in range(n)]) for i in range(npts)]
#H0=[np.array([19.52158144,13.31267976,13.35448593,13.35612847,13.35535822,13.35451532,13.35366458,13.35281449,13.35258073,13.35252602]) for i in range(npts)]
#H0=[0.5*np.ones(n) for i in range(npts)]
コード例 #10
0
    x = (Z*X).sum() / Z_sum
    y = (Z*Y).sum() / Z_sum
    return x,y

p = 100
np.random.seed(123)

if os.path.exists('data/double-target-intensity-5.npy'):
    T5 = np.load('data/double-target-intensity-5.npy')
else:
    rho = 5
    model= Model()
    T5 = np.zeros((p,2))
    for i,theta in enumerate(np.linspace(10,45,p)):
        model.reset()
        model.R = np.maximum( stimulus((rho, -theta), size=1, intensity=1) ,
                              stimulus((rho, +theta), size=1, intensity=1) )
        model.R += np.random.uniform(0,0.05,model.R.shape)

        model.run(duration=5*second, dt=5*millisecond, epsilon=0.0)
        x,y = decode(model.SC_V)
        print u"Δθ = %.2f: (%f,%f)" % (2*theta, x, y)
        T5[i] = x,y
    np.save("data/double-target-intensity-5.npy",T5)

if os.path.exists('data/double-target-intensity-10.npy'):
    T10 = np.load('data/double-target-intensity-10.npy')
else:
    rho = 10
    model= Model()
    T10 = np.zeros((p,2))
コード例 #11
0
import os
import numpy as np

from helper import *
from stimulus import *
from graphics import *
from projections import *


if __name__ == "__main__":
    import matplotlib.pyplot as plt

    fig = plt.figure(figsize=(16, 6), facecolor="w")

    # Stimuli luminances are not additive
    R = stimulus(position=(5, 0))
    P = retina_projection(retina_shape, [1024, 1024])

    # ---------------------------------
    ax = plt.subplot(2, 1, 1)
    ax.tick_params(direction="outward")
    ax.spines["right"].set_color("none")
    ax.spines["top"].set_color("none")
    ax.spines["left"].set_color("none")
    ax.spines["bottom"].set_color("none")
    ax.xaxis.set_ticks_position("bottom")
    ax.spines["bottom"].set_position(("data", -0.05))

    X = np.linspace(0, 90, R.shape[1])
    for rho in [2, 5, 10, 20, 40, 60, 80]:
        R = stimulus(position=(rho, 0))
コード例 #12
0
    ax.set_xlim(-90,90)
    ax.set_ylim(0,250)
    ax.set_zlim(0,300)
    ax.set_xlabel(u'Stimuli position [°]', fontsize=fontsize,labelpad=4)
    ax.set_ylabel('Time [ms]', fontsize=fontsize,labelpad=5)
    ax.set_zlabel('Discharge rate (spike/s)', fontsize=fontsize,labelpad=5)
    ax.tick_params(axis='both', which='major', labelsize=fontsize-1)
    ax.set_zticks([0,100,200,300])


plt.figure(figsize=(2.5,6.5), facecolor='w',dpi=100)

model = Model()

model.reset()
model.R = stimulus((5.0, -30), size=1, intensity=1)


ax = plt.subplot(311, projection='3d')
run(model,ax)
ax.text2D(0.0, 1.0, "a", va='top', ha='right',
          transform=ax.transAxes, fontsize=10, fontweight='bold')


# Get location of -20/+20 on SC
model.reset()
model.R = stimulus((5.0, -20), size=1, intensity=1)
model.run(1.*second, 4*millisecond)
x,_ = polar_to_logpolar(5/90.,0.)
x = int(x*128)
y1 = model.SC_V[:,x].argmax()
コード例 #13
0
ファイル: state.py プロジェクト: olakiril/Python
max_trials = 1
RP = 4
ITI = 2

# Set images
GO_images = glob('images/obj1*')
NOGO_images = glob('images/obj2*')

# Initialize image matrices
GO_resp = np.ones(np.size(GO_images))
NOGO_resp = np.zeros(np.size(NOGO_images))
ALL_images = GO_images + NOGO_images
ALL_resp = np.concatenate([GO_resp, NOGO_resp])

# Load images
stim = stimulus(ALL_images, w, h)

# Datajoin stuff
#session = dict(mouse_id=1, session_tmst=timer.start_time)
#Sessions().insert1(session)

# Initialize other settings
timer.start()
stim.init_block()
trial = 0
state_time = 0
pygame.mouse.set_visible(0)

# RUN
while trial < max_trials:  # Each trial is one block
コード例 #14
0
T = np.zeros((len(targets), 2))
for i, target in enumerate(targets):
    rho, theta = target
    rho, theta = rho / 90.0, np.pi * theta / 180.0
    x, y = polar_to_logpolar(rho, theta)
    T[i] = 2 * x, 2 * y - 1

if not os.path.exists('accuracy.npy'):
    model = Model()
    D = np.zeros((len(targets), 2))
    for i, target in enumerate(targets):
        rho, theta = target
        x_, y_ = polar_to_logpolar(rho / 90.0, np.pi * theta / 180.0)
        x_, y_ = 2 * x_, 2 * y_ - 1
        model.reset()
        model.R = stimulus((rho, theta))
        model.run(duration=5 * second, dt=5 * millisecond, epsilon=0.001)
        x, y = decode(model.SC_V)
        D[i] = x, y
        print 'Target at (%d,%d): %f' % (rho, theta,
                                         np.sqrt((x - x_) * (x - x_) +
                                                 (y - y_) * (y - y_)))
    np.save('accuracy.npy', D)
else:
    D = np.load('accuracy.npy')

fig = plt.figure(figsize=(8, 8), facecolor='w')
ax1 = plt.subplot(111, aspect=1)
logpolar_frame(ax1)
for i in range(len(D)):
    plt.plot([T[i, 0], D[i, 0]], [T[i, 1], D[i, 1]], color='k')
コード例 #15
0
ファイル: test.py プロジェクト: olakiril/Python
import time
from matplotlib import pyplot

GO_images = ('image1.jpg', 'image2.jpg')
NOGO_images = ('image3.jpg', 'image4.jpg')

# Initialize image matrices
GO_resp = np.ones(np.size(GO_images))
NOGO_resp = np.zeros(np.size(NOGO_images))
ALL_images = GO_images + NOGO_images
ALL_resp = np.concatenate([GO_resp, NOGO_resp])

pygame.init()
clock = pygame.time.Clock()
FPS = 60
s = stimulus(ALL_images)
s.init_block()

stimes = np.zeros(200)
etimes = np.zeros(200)
for itrial in range(200):
    stimes[itrial] = time.time()
    s.init_trial()
    s.show()
    clock.tick(FPS)
    s.unshow()
    etimes[itrial] = time.time()

times = etimes - stimes
s.close()
コード例 #16
0
    from mpl_toolkits.axes_grid1 import ImageGrid
    from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes
    from mpl_toolkits.axes_grid1.inset_locator import mark_inset

    fig = plt.figure(figsize=(10, 8), facecolor='w')
    ax1, ax2 = ImageGrid(fig, 111, nrows_ncols=(1, 2), axes_pad=0.5)

    polar_frame(ax1, legend=True)
    zax = zoomed_inset_axes(ax1, 6, loc=1)
    polar_frame(zax, zoom=True)
    zax.set_xlim(0.0, 0.1)
    zax.set_xticks([])
    zax.set_ylim(-.05, .05)
    zax.set_yticks([])
    zax.set_frame_on(True)
    mark_inset(ax1, zax, loc1=2, loc2=4, fc="none", ec="0.5")

    # Stimuli luminances are not additive
    R = np.maximum(stimulus(position=(1, 0)), stimulus(position=(5, 0)))

    polar_imshow(ax1, R)
    polar_imshow(zax, R)

    logpolar_frame(ax2, legend=True)
    P = retina_projection()
    SC = R[P[..., 0], P[..., 1]]
    logpolar_imshow(ax2, SC)

    # plt.savefig("fig-input.pdf")
    plt.show()
コード例 #17
0
    ################################
    
    ax1, ax2 = ImageGrid(fig, 212, nrows_ncols=(1,2), axes_pad=0.5)
    polar_frame(ax1, legend=True,reduced=True)
    '''
    zax = zoomed_inset_axes(ax1, 6, loc=1)
    polar_frame(zax, zoom=True)
    zax.set_xlim(0.0, 0.15)
    zax.set_xticks([])
    zax.set_ylim(-.05, .05)
    zax.set_yticks([])
    zax.set_frame_on(True)
    mark_inset(ax1, zax, loc1=2, loc2=4, fc="none", ec="0.5")
    '''
    # Stimuli luminances are not additive
    R = np.maximum(stimulus(position=(1,0)), stimulus(position=(5,0)))
    R = np.maximum(R , stimulus(position=(10,0)))
    polar_imshow(ax1, R,reduced=True)
    #polar_imshow(zax, R)
    
    logpolar_frame(ax2, legend=True)
    P = retina_projection()
    SC = R[P[...,0], P[...,1]]
    logpolar_imshow(ax2, SC)
    ax1.text(1.1, 1.1, u"b",
                 ha="left", va="bottom", fontsize=20, fontweight='bold')


    fig.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.95,
                                        wspace=0.15, hspace=0.2)
    plt.savefig("figures/Fig-1.pdf")
コード例 #18
0
    x = (Z*X).sum() / Z_sum
    y = (Z*Y).sum() / Z_sum
    return x,y

p = 100
np.random.seed(123)

if os.path.exists('data/double-target-intensity-5.npy'):
    T5 = np.load('data/double-target-intensity-5.npy')
else:
    rho = 5
    model= Model()
    T5 = np.zeros((p,2))
    for i,theta in enumerate(np.linspace(10,45,p)):
        model.reset()
        model.R = np.maximum( stimulus((rho, -theta), size=1, intensity=1) ,
                              stimulus((rho, +theta), size=1, intensity=1) )
        model.R += np.random.uniform(0,0.05,model.R.shape)

        model.run(duration=5*second, dt=5*millisecond, epsilon=0.0)
        x,y = decode(model.SC_V)
        print u"Δθ = %.2f: (%f,%f)" % (2*theta, x, y)
        T5[i] = x,y
    np.save("data/double-target-intensity-5.npy",T5)

if os.path.exists('data/double-target-intensity-10.npy'):
    T10 = np.load('data/double-target-intensity-10.npy')
else:
    rho = 10
    model= Model()
    T10 = np.zeros((p,2))
コード例 #19
0
# -----------------------------------------------------------------------------
import os
import numpy as np

from helper import *
from stimulus import *
from graphics import *
from projections import *

if __name__ == '__main__':
    import matplotlib.pyplot as plt

    fig = plt.figure(figsize=(16, 6), facecolor='w')

    # Stimuli luminances are not additive
    R = stimulus(position=(5, 0))
    P = retina_projection(retina_shape, [1024, 1024])

    # ---------------------------------
    ax = plt.subplot(2, 1, 1)
    ax.tick_params(direction="outward")
    ax.spines['right'].set_color('none')
    ax.spines['top'].set_color('none')
    ax.spines['left'].set_color('none')
    ax.spines['bottom'].set_color('none')
    ax.xaxis.set_ticks_position('bottom')
    ax.spines['bottom'].set_position(('data', -0.05))

    X = np.linspace(0, 90, R.shape[1])
    for rho in [2, 5, 10, 20, 40, 60, 80]:
        R = stimulus(position=(rho, 0))
コード例 #20
0
w0=0.1*random.randn(N,N)#ones((N,N))#random.randn(N, N)
w0=list(w0.reshape(N*N))
y0=list(u0)+w0
u0=array(u0)
y0=array(y0)
################################
##Building patterns
times=1
delay_inter=1000
delay_intra=40
n=2.0
v1=array([1,0,0])#*(1/sqrt(2))
v2=array([0,1,0])#*(1/sqrt(2))
v3=array([0,0,1])#*(1/sqrt(2))
patterns=[v1,-0.3*v1]#random.binomial(1,0.5,N)i
mystim=stimulus(patterns,delay_inter,delay_intra,times)
mystim.tstim=90
mystim.inten=1.9
mystim.delay_begin=700
dt=0.1
tmax=mystim.delay_begin+times*n*(mystim.tstim+delay_inter)-times*delay_inter+times*delay_intra+700


###########Building network#######
ubar=array([0.3,0.3,0.3])#0.1*random.randn(N)#array([2,3])
net=network(u0,struct)
net.covmean(array(ubar))
net.stim(mystim.stim)
net.homeostatic(0)
net.alpha=20
net.v12=0
コード例 #21
0
ファイル: fig-accuracy.py プロジェクト: HiMehta/Neurosciences
for i,target in enumerate(targets):
    rho,theta = target
    rho,theta  = rho/90.0, np.pi*theta/180.0
    x,y = polar_to_logpolar(rho,theta)
    T[i] = 2*x,2*y-1


if not os.path.exists('accuracy.npy'):
    model = Model()
    D = np.zeros((len(targets),2))
    for i,target in enumerate(targets):
        rho,theta = target
        x_,y_ = polar_to_logpolar(rho/90.0, np.pi*theta/180.0)
        x_,y_ = 2*x_, 2*y_-1
        model.reset()
        model.R = stimulus((rho, theta))
        model.run(duration=5*second, dt=5*millisecond, epsilon=0.001)
        x,y = decode(model.SC_V)
        D[i] = x,y
        print 'Target at (%d,%d): %f' % (rho,theta, np.sqrt((x-x_)*(x-x_) + (y-y_)*(y-y_)))
    np.save('accuracy.npy', D)
else:
    D = np.load('accuracy.npy')


fig = plt.figure(figsize=(8,8), facecolor='w')
ax1 = plt.subplot(111, aspect=1)
logpolar_frame(ax1)
for i in range(len(D)):
    plt.plot([T[i,0],D[i,0]],[T[i,1],D[i,1]], color='k')
ax1.scatter(T[:,0], T[:,1], s=50, color='k', marker='o')