Пример #1
0
def plot_weights(plot, W):
    w     = np.ravel(W)
    w_exc = w[np.where(w > 0)]
    w_inh = w[np.where(w < 0)]

    plot.hist(w_exc, color=Figure.colors('blue'))
    plot.hist(w_inh, color=Figure.colors('red'))
Пример #2
0
def plot_weights(plot, W):
    w = np.ravel(W)
    w_exc = w[np.where(w > 0)]
    w_inh = w[np.where(w < 0)]

    plot.hist(w_exc, color=Figure.colors('blue'))
    plot.hist(w_inh, color=Figure.colors('red'))
Пример #3
0
def process_trial(plot, n):
    if perf.choices[n] is None:
        print("Trial {}: No decision.".format(n))
        return

    trial = trials[n]
    time = trial['time']
    u = U[:, n]
    z = Z[:, n]

    stimulus = np.asarray(trial['epochs']['stimulus'])
    evidenceL = np.sum(u[stimulus - 1, inputs['LEFT']])
    evidenceR = np.sum(u[stimulus - 1, inputs['RIGHT']])

    decision = np.asarray(trial['epochs']['decision'])
    t_choice = perf.t_choices[n]
    idx = decision[np.where(decision <= t_choice)]
    t0 = time[idx][0]

    pL = z[idx, inputs['LEFT']]
    pR = z[idx, inputs['RIGHT']]
    S = pL + pR

    if perf.choices[n] == 'R':
        ls = '-'
        #else:
        #    ls = '--'
        plot.plot(time[idx] - t0,
                  pL / S,
                  ls,
                  color=Figure.colors('red'),
                  lw=0.5,
                  zorder=5)

    if perf.choices[n] == 'R':
        ls = '-'
        #else:
        #    ls = '--'
        plot.plot(time[idx] - t0,
                  pR / S,
                  ls,
                  color=Figure.colors('blue'),
                  lw=0.5,
                  zorder=5)
Пример #4
0
    def plot_activity(plot, unit):
        yall = [1]

        min_trials = 20

        # Pre-offer
        epoch_by_cond = epochs_by_cond['preoffer']
        color = '0.7'
        if separate_by_choice:
            for choice, marker in zip(['A', 'B'], ['d', 'o']):
                x = []
                y = []
                for i, offer in enumerate(offers):
                    cond = (offer, choice)
                    if cond in n_by_cond and n_by_cond[cond] >= min_trials:
                        y_i = epoch_by_cond[cond][unit]
                        plot.plot(i,
                                  y_i,
                                  marker,
                                  mfc=color,
                                  mec=color,
                                  ms=0.8 * ms,
                                  mew=0.8 * mew,
                                  zorder=10)
                        yall.append(y_i)
                        if i != 0 and i != len(offers) - 1:
                            x.append(i)
                            y.append(y_i)
                plot.plot(x, y, '-', color=color, lw=0.8 * lw, zorder=5)
        else:
            x = []
            y = []
            for i, offer in enumerate(offers):
                y_i = epoch_by_cond[offer][unit]
                plot.plot(i,
                          y_i,
                          'o',
                          mfc=color,
                          mec=color,
                          ms=0.8 * ms,
                          mew=0.8 * mew,
                          zorder=10)
                yall.append(y_i)
                if i != 0 and i != len(offers) - 1:
                    x.append(i)
                    y.append(y_i)
            plot.plot(x, y, '-', color=color, lw=0.8 * lw, zorder=5)

        # Epoch
        epoch_by_cond = epochs_by_cond[epoch]
        if epoch == 'postoffer':
            color = Figure.colors('darkblue')
        elif epoch == 'latedelay':
            color = Figure.colors('darkblue')
        elif epoch == 'prechoice':
            color = Figure.colors('darkblue')
        else:
            raise ValueError(epoch)
        if separate_by_choice:
            for choice, marker, color in zip(
                ['A', 'B'], ['d', 'o'],
                [Figure.colors('red'),
                 Figure.colors('blue')]):
                x = []
                y = []
                for i, offer in enumerate(offers):
                    cond = (offer, choice)
                    if cond in n_by_cond and n_by_cond[cond] >= min_trials:
                        y_i = epoch_by_cond[cond][unit]
                        yall.append(y_i)
                        plot.plot(i,
                                  y_i,
                                  marker,
                                  mfc=color,
                                  mec=color,
                                  ms=ms,
                                  mew=mew,
                                  zorder=10)
                        if i != 0 and i != len(offers) - 1:
                            x.append(i)
                            y.append(y_i)
                plot.plot(x, y, '-', color=color, lw=lw, zorder=5)
        else:
            x = []
            y = []
            for i, offer in enumerate(offers):
                y_i = epoch_by_cond[offer][unit]
                plot.plot(i,
                          y_i,
                          'o',
                          mfc=color,
                          mec=color,
                          ms=ms,
                          mew=mew,
                          zorder=10)
                yall.append(y_i)
                if i != 0 and i != len(offers) - 1:
                    x.append(i)
                    y.append(y_i)
            plot.plot(x, y, '-', color=color, lw=lw, zorder=5)

        plot.xticks(range(len(offers)))
        plot.xticklabels(['{}B:{}A'.format(*offer) for offer in offers],
                         rotation=rotation)

        plot.xlim(0, len(offers) - 1)
        plot.lim('y', yall, lower=0)

        return yall
Пример #5
0
              mew=0)
    #plot.plot(ntrials, 100*pcorrects, 'o', color=color, ms=6, mew=0)

plot = fig['reward']
plot.xlim(0, max([max(x) for x in xall]))
plot.ylim(-1, 1)
plot.xlabel(r'Number of trials ($\times$' + '{})'.format(T))
plot.ylabel('Reward per trial')

if len(num_trials) > 1:
    mean = np.mean(num_trials)
    sd = np.std(num_trials, ddof=1)
    plot.text_lower_right(r'{:.1f} $\pm$ {:.1f} trials'.format(mean, sd),
                          dy=0.03,
                          fontsize=10,
                          color=Figure.colors('green'))
else:
    mean = int(num_trials[0])
    plot.text_lower_right('{} trials'.format(mean),
                          dy=0.03,
                          fontsize=10,
                          color=Figure.colors('green'))

plot = fig['correct']
plot.xlim(0, max([max(x) for x in xall]))
plot.ylim(40, 100)
plot.ylabel('Percent correct\n(decision trials)')

target_color = Figure.colors('red')

plot = fig['correct']
Пример #6
0
    #plot.plot(ntrials[w1], 100*pcorrects[w1], '--', color=color, lw=lw)
    plot.plot(ntrials[w2], 100*pcorrects[w2], color=color, lw=lw)
    plot.plot(ntrials[w2][-1], 100*pcorrects[w2][-1], 'o', mfc=color, ms=4, mew=0)
    #plot.plot(ntrials, 100*pcorrects, 'o', color=color, ms=6, mew=0)

plot = fig['reward']
plot.xlim(0, max([max(x) for x in xall]))
plot.ylim(-1, 1)
plot.xlabel(r'Number of trials ($\times$' + '{})'.format(T))
plot.ylabel('Reward per trial')

if len(num_trials) > 1:
    mean = np.mean(num_trials)
    sd   = np.std(num_trials, ddof=1)
    plot.text_lower_right(r'{:.1f} $\pm$ {:.1f} trials'.format(mean, sd), dy=0.03,
                          fontsize=10, color=Figure.colors('green'))
else:
    mean = int(num_trials[0])
    plot.text_lower_right('{} trials'.format(mean), dy=0.03,
                          fontsize=10, color=Figure.colors('green'))

plot = fig['correct']
plot.xlim(0, max([max(x) for x in xall]))
plot.ylim(40, 100)
plot.ylabel('Percent correct\n(decision trials)')

target_color = Figure.colors('red')

plot = fig['correct']
if modelname.startswith('rdm_fixed'):
    target = 80
Пример #7
0
    'stimulus': (600, 2000)
    }

tmax = durations['stimulus'][-1]
time = np.linspace(0, tmax, 151)[1:]

#=========================================================================================

plot = fig['fixation']
plot.axis_off('bottom')

fixation = np.zeros_like(time)
for i, t in enumerate(time):
    if t < durations['stimulus'][0]:
        fixation[i] = 1
plot.plot(time, fixation, color=Figure.colors('magenta'), lw=lw)

plot.yticks([0, 1])
plot.yticklabels(['OFF', 'ON'], fontsize=5.5)

plot.xlim(0, tmax)
plot.ylim(0, 1)

plot.text(durations['stimulus'][0], 1.1, '\"Go\"', ha='left', va='bottom', fontsize=7)

#=========================================================================================

plot = fig['stimulus']
plot.axis_off('bottom')

# Stimulus
Пример #8
0
              transform=plot.transAxes)
    plot.text(-1.25,
              0.5 - 0.13,
              s2,
              ha='center',
              va='center',
              fontsize=7,
              color=color2,
              transform=plot.transAxes)


custom_axislabel('mante-choice-0', 'choice', r'\textit{all trials}')
custom_axislabel('mante-motion-choice-0', 'motion \& choice',
                 r'\textbf{motion context}', 'k')
custom_axislabel('mante-color-choice-0', 'color \& choice',
                 r'\textbf{color context}', Figure.colors('darkblue'))
custom_axislabel('mante-context-choice-0', 'context \& choice',
                 r'\textit{all trials}')

#=========================================================================================

plot = fig['ms-behavior']

kwargs = dict(ms=4, lw=1)
multisensory_analysis.psychometric(multisensory_behavior, fig['ms-behavior'],
                                   **kwargs)

# Legend
props = {
    'prop': {
        'size': 6
Пример #9
0
def sort(trialsfile, plots, units=None, network='p', **kwargs):
    """
    Sort trials.

    """
    # Load trials
    data = utils.load(trialsfile)
    trials, U, Z, Z_b, A, P, M, perf, r_p, r_v = data

    # Which network?
    if network == 'p':
        r = r_p
    else:
        r = r_v

    # Number of units
    N = r.shape[-1]

    # Same for every trial
    time = trials[0]['time']
    Ntime = len(time)

    # Aligned time
    time_a = np.concatenate((-time[1:][::-1], time))
    Ntime_a = len(time_a)

    #=====================================================================================
    # Aligned to stimulus onset
    #=====================================================================================

    r_by_cond_stimulus = {}
    n_r_by_cond_stimulus = {}
    for n, trial in enumerate(trials):
        if not perf.decisions[n]:
            continue

        if trial['mod'] == 'va':
            continue
        assert trial['mod'] == 'v' or trial['mod'] == 'a'

        if not perf.corrects[n]:
            continue

        # Condition
        mod = trial['mod']
        choice = perf.choices[n]
        cond = (mod, choice)

        # Storage
        r_by_cond_stimulus.setdefault(cond, np.zeros((Ntime_a, N)))
        n_r_by_cond_stimulus.setdefault(cond, np.zeros((Ntime_a, N)))

        # Firing rates
        Mn = np.tile(M[:, n], (N, 1)).T
        Rn = r[:, n] * Mn

        # Align point
        t0 = trial['epochs']['stimulus'][0] - 1

        # Before
        n_b = Rn[:t0].shape[0]
        r_by_cond_stimulus[cond][Ntime - 1 - n_b:Ntime - 1] += Rn[:t0]
        n_r_by_cond_stimulus[cond][Ntime - 1 - n_b:Ntime - 1] += Mn[:t0]

        # After
        n_a = Rn[t0:].shape[0]
        r_by_cond_stimulus[cond][Ntime - 1:Ntime - 1 + n_a] += Rn[t0:]
        n_r_by_cond_stimulus[cond][Ntime - 1:Ntime - 1 + n_a] += Mn[t0:]

    for cond in r_by_cond_stimulus:
        r_by_cond_stimulus[cond] = utils.div(r_by_cond_stimulus[cond],
                                             n_r_by_cond_stimulus[cond])

    #-------------------------------------------------------------------------------------
    # Plot
    #-------------------------------------------------------------------------------------

    lw = kwargs.get('lw', 1.5)
    dashes = kwargs.get('dashes', [3, 2])

    vline_props = {'lw': kwargs.get('lw_vline', 0.5)}
    if 'dashes_vline' in kwargs:
        vline_props['linestyle'] = '--'
        vline_props['dashes'] = dashes

    colors_by_mod = {'v': Figure.colors('blue'), 'a': Figure.colors('green')}
    linestyle_by_choice = {'L': '-', 'H': '--'}
    lineprops = dict(lw=lw)

    def plot_sorted(plot, unit, w, r_sorted):
        t = time_a[w]
        yall = [[1]]
        for cond in [('v', 'H'), ('v', 'L'), ('a', 'H'), ('a', 'L')]:
            mod, choice = cond

            if mod == 'v':
                label = 'Vis, '
            elif mod == 'a':
                label = 'Aud, '
            else:
                raise ValueError(mod)

            if choice == 'H':
                label += 'high'
            elif choice == 'L':
                label += 'low'
            else:
                raise ValueError(choice)

            linestyle = linestyle_by_choice[choice]
            if linestyle == '-':
                lineprops = dict(linestyle=linestyle, lw=lw)
            else:
                lineprops = dict(linestyle=linestyle, lw=lw, dashes=dashes)
            plot.plot(t,
                      r_sorted[cond][w, unit],
                      color=colors_by_mod[mod],
                      label=label,
                      **lineprops)
            yall.append(r_sorted[cond][w, unit])

        return t, yall

    def on_stimulus(plot, unit):
        w, = np.where((time_a >= -300) & (time_a <= 1000))
        t, yall = plot_sorted(plot, unit, w, r_by_cond_stimulus)

        plot.xlim(t[0], t[-1])

        return yall

    if units is not None:
        for plot, unit in zip(plots, units):
            on_stimulus(plot, unit)
    else:
        figspath, name = plots
        for unit in xrange(N):
            fig = Figure()
            plot = fig.add()

            #-----------------------------------------------------------------------------

            yall = []
            yall += on_stimulus(plot, unit)

            plot.lim('y', yall, lower=0)
            plot.vline(0)

            plot.xlabel('Time (ms)')
            plot.ylabel('Firing rate (a.u.)')

            #-----------------------------------------------------------------------------

            fig.save(path=figspath,
                     name=name + '_{}{:03d}'.format(network, unit))
            fig.close()
Пример #10
0
fixation = np.zeros_like(trial_t)
w, = np.where((0 <= trial_t) & (trial_t <= durations['decision'][0]))
fixation[w] = 1


def rescale(y):
    return y_fixation + 0.2 * y


fake_left_axis(rescale(0),
               rescale(1),
               thickness,
               ticklabels=['OFF', 'ON'],
               axislabel='Fixation cue')
plot.plot(trial_t, rescale(fixation), color=Figure.colors('darkgreen'), lw=lw)

#-----------------------------------------------------------------------------------------
# Plot stimulus
#-----------------------------------------------------------------------------------------

coh = 25.6

stimulus_L = np.zeros_like(trial_t)
stimulus_R = np.zeros_like(trial_t)

w, = np.where((durations['stimulus'][0] < trial_t)
              & (trial_t <= durations['stimulus'][1]))
stimulus_L[w] = model.scale(-coh) + rng.normal(scale=0.15, size=len(w))
stimulus_R[w] = model.scale(+coh) + rng.normal(scale=0.15, size=len(w))
Пример #11
0
        plot = fig['mante-{}-{}'.format(k, i)]
        plot.ylim(lims[i][j])
        plot.yticks(ticks[i][j])

def custom_axislabel(name, s1, s2, color2='k'):
    plot = fig[name]
    plot.text(-1.25, 0.5+0.13, s1, ha='center', va='center', fontsize=7,
              transform=plot.transAxes)
    plot.text(-1.25, 0.5-0.13, s2, ha='center', va='center', fontsize=7, color=color2,
              transform=plot.transAxes)

custom_axislabel('mante-choice-0', 'choice', r'\textit{all trials}')
custom_axislabel('mante-motion-choice-0', 'motion \& choice', r'\textbf{motion context}',
                 'k')
custom_axislabel('mante-color-choice-0', 'color \& choice', r'\textbf{color context}',
                 Figure.colors('darkblue'))
custom_axislabel('mante-context-choice-0', 'context \& choice', r'\textit{all trials}')

#=========================================================================================

plot = fig['ms-behavior']

kwargs = dict(ms=4, lw=1)
multisensory_analysis.psychometric(multisensory_behavior, fig['ms-behavior'], **kwargs)

# Legend
props = {'prop': {'size': 6}, 'handlelength': 1,
         'handletextpad': 0.9, 'labelspacing': 0.5}
plot.legend(bbox_to_anchor=(0.605, 1.15), **props)

plot.xlabel('Rate (events/s)')
Пример #12
0
                         ha='right', va='center', fontsize=4.5)

#-----------------------------------------------------------------------------------------
# Plot fixation
#-----------------------------------------------------------------------------------------

fixation = np.zeros_like(trial_t)
w, = np.where((0 <= trial_t) & (trial_t <= durations['decision'][0]))
fixation[w] = 1

def rescale(y):
    return y_fixation + 0.2*y

fake_left_axis(rescale(0), rescale(1), thickness, ticklabels=['OFF', 'ON'],
               axislabel='Fixation cue')
plot.plot(trial_t, rescale(fixation), color=Figure.colors('darkgreen'), lw=lw)

#-----------------------------------------------------------------------------------------
# Plot stimulus
#-----------------------------------------------------------------------------------------

coh = 25.6

stimulus_L = np.zeros_like(trial_t)
stimulus_R = np.zeros_like(trial_t)

w, = np.where((durations['stimulus'][0] < trial_t) & (trial_t <= durations['stimulus'][1]))
stimulus_L[w] = model.scale(-coh) + rng.normal(scale=0.15, size=len(w))
stimulus_R[w] = model.scale(+coh) + rng.normal(scale=0.15, size=len(w))

def rescale(y):
Пример #13
0
def sort(trialsfile, plots, units=None, network='p', **kwargs):
    """
    Sort trials.

    """
    # Load trials
    data = utils.load(trialsfile)
    trials, U, Z, Z_b, A, P, M, perf, r_p, r_v = data

    # Which network?
    if network == 'p':
        r = r_p
    else:
        r = r_v

    # Number of units
    N = r.shape[-1]

    # Same for every trial
    time  = trials[0]['time']
    Ntime = len(time)

    # Aligned time
    time_a  = np.concatenate((-time[1:][::-1], time))
    Ntime_a = len(time_a)

    #=====================================================================================
    # Aligned to stimulus onset
    #=====================================================================================

    r_by_cond_stimulus   = {}
    n_r_by_cond_stimulus = {}
    for n, trial in enumerate(trials):
        if not perf.decisions[n]:
            continue

        if trial['mod'] == 'va':
            continue
        assert trial['mod'] == 'v' or trial['mod'] == 'a'

        if not perf.corrects[n]:
            continue

        # Condition
        mod    = trial['mod']
        choice = perf.choices[n]
        cond   = (mod, choice)

        # Storage
        r_by_cond_stimulus.setdefault(cond, np.zeros((Ntime_a, N)))
        n_r_by_cond_stimulus.setdefault(cond, np.zeros((Ntime_a, N)))

        # Firing rates
        Mn = np.tile(M[:,n], (N,1)).T
        Rn = r[:,n]*Mn

        # Align point
        t0 = trial['epochs']['stimulus'][0] - 1

        # Before
        n_b = Rn[:t0].shape[0]
        r_by_cond_stimulus[cond][Ntime-1-n_b:Ntime-1]   += Rn[:t0]
        n_r_by_cond_stimulus[cond][Ntime-1-n_b:Ntime-1] += Mn[:t0]

        # After
        n_a = Rn[t0:].shape[0]
        r_by_cond_stimulus[cond][Ntime-1:Ntime-1+n_a]   += Rn[t0:]
        n_r_by_cond_stimulus[cond][Ntime-1:Ntime-1+n_a] += Mn[t0:]

    for cond in r_by_cond_stimulus:
        r_by_cond_stimulus[cond] = utils.div(r_by_cond_stimulus[cond],
                                             n_r_by_cond_stimulus[cond])

    #-------------------------------------------------------------------------------------
    # Plot
    #-------------------------------------------------------------------------------------

    lw     = kwargs.get('lw', 1.5)
    dashes = kwargs.get('dashes', [3, 2])

    vline_props = {'lw': kwargs.get('lw_vline', 0.5)}
    if 'dashes_vline' in kwargs:
        vline_props['linestyle'] = '--'
        vline_props['dashes']    = dashes

    colors_by_mod = {
        'v': Figure.colors('blue'),
        'a': Figure.colors('green')
        }
    linestyle_by_choice = {
        'L': '-',
        'H': '--'
        }
    lineprops = dict(lw=lw)

    def plot_sorted(plot, unit, w, r_sorted):
        t = time_a[w]
        yall = [[1]]
        for cond in [('v', 'H'), ('v', 'L'), ('a', 'H'), ('a', 'L')]:
            mod, choice = cond

            if mod == 'v':
                label = 'Vis, '
            elif mod == 'a':
                label = 'Aud, '
            else:
                raise ValueError(mod)

            if choice == 'H':
                label += 'high'
            elif choice == 'L':
                label += 'low'
            else:
                raise ValueError(choice)

            linestyle = linestyle_by_choice[choice]
            if linestyle == '-':
                lineprops = dict(linestyle=linestyle, lw=lw)
            else:
                lineprops = dict(linestyle=linestyle, lw=lw, dashes=dashes)
            plot.plot(t, r_sorted[cond][w,unit],
                      color=colors_by_mod[mod],
                      label=label,
                      **lineprops)
            yall.append(r_sorted[cond][w,unit])

        return t, yall

    def on_stimulus(plot, unit):
        w, = np.where((time_a >= -300) & (time_a <= 1000))
        t, yall = plot_sorted(plot, unit, w, r_by_cond_stimulus)

        plot.xlim(t[0], t[-1])

        return yall

    if units is not None:
        for plot, unit in zip(plots, units):
            on_stimulus(plot, unit)
    else:
        figspath, name = plots
        for unit in xrange(N):
            fig  = Figure()
            plot = fig.add()

            #-----------------------------------------------------------------------------

            yall = []
            yall += on_stimulus(plot, unit)

            plot.lim('y', yall, lower=0)
            plot.vline(0)

            plot.xlabel('Time (ms)')
            plot.ylabel('Firing rate (a.u.)')

            #-----------------------------------------------------------------------------

            fig.save(path=figspath, name=name+'_{}{:03d}'.format(network, unit))
            fig.close()
Пример #14
0
from __future__ import absolute_import, division

import os

import numpy as np

from pyrl          import fittools, runtools, tasktools, utils
from pyrl.figtools import Figure

#/////////////////////////////////////////////////////////////////////////////////////////

colors = {
    'v':  Figure.colors('blue'),
    'a':  Figure.colors('green'),
    'va': Figure.colors('orange')
    }

#/////////////////////////////////////////////////////////////////////////////////////////

def psychometric(trialsfile, plot, **kwargs):
    # Load trials
    trials, A, R, M, perf = utils.load(trialsfile)

    decision_by_freq = {}
    high_by_freq     = {}
    for n, trial in enumerate(trials):
        mod  = trial['mod']
        freq = trial['freq']
        decision_by_freq.setdefault(mod, {})
        high_by_freq.setdefault(mod, {})
        decision_by_freq[mod].setdefault(freq, [])
Пример #15
0
    'stimulus': (600, 2000)
    }

tmax = durations['stimulus'][-1]
time = np.linspace(0, tmax, 151)[1:]

#=========================================================================================

plot = fig['fixation']
plot.axis_off('bottom')

fixation = np.zeros_like(time)
for i, t in enumerate(time):
    if t < durations['stimulus'][0]:
        fixation[i] = 1
plot.plot(time, fixation, color=Figure.colors('magenta'), lw=lw)

plot.yticks([0, 1])
plot.yticklabels(['OFF', 'ON'], fontsize=5.5)

plot.xlim(0, tmax)
plot.ylim(0, 1)

plot.text(durations['stimulus'][0], 1.1, '\"Go\"', ha='left', va='bottom', fontsize=7)

#=========================================================================================

plot = fig['stimulus']
plot.axis_off('bottom')

# Stimulus
Пример #16
0
from __future__ import absolute_import, division

import os

import numpy as np

from pyrl import fittools, runtools, tasktools, utils
from pyrl.figtools import Figure

#/////////////////////////////////////////////////////////////////////////////////////////

colors = {
    'v': Figure.colors('blue'),
    'a': Figure.colors('green'),
    'va': Figure.colors('orange')
}

#/////////////////////////////////////////////////////////////////////////////////////////


def psychometric(trialsfile, plot, **kwargs):
    # Load trials
    trials, A, R, M, perf = utils.load(trialsfile)

    decision_by_freq = {}
    high_by_freq = {}
    for n, trial in enumerate(trials):
        mod = trial['mod']
        freq = trial['freq']
        decision_by_freq.setdefault(mod, {})
        high_by_freq.setdefault(mod, {})
Пример #17
0
plotlabels = {'A': (0.01, 0.935), 'B': (0.28, 0.935)}
fig.plotlabels(plotlabels)

#=========================================================================================

plot = fig['choice-upper']

kwargs = {'ms': 4.5, 'lw': 1.25}
analysis.choice_pattern(trialsfile_b, model.offers, plot, **kwargs)

plot.yticks([0, 50, 100])

plot.text_upper_left('1A = {}B'.format(model.A_to_B),
                     fontsize=7.5,
                     color=Figure.colors('green'))

#=========================================================================================

plot = fig['choice-lower']

kwargs = {'ms': 4.5, 'lw': 1.25}
analysis.choice_pattern(trialsfile2_b, model2.offers, plot, **kwargs)

plot.yticks([0, 50, 100])

plot.xlabel('Offer (\#B : \#A)')
plot.ylabel('Percent choice B')

plot.text_upper_left('1A = {}B'.format(model2.A_to_B),
                     fontsize=7.5,
Пример #18
0
    def plot_activity(plot, unit):
        yall = [1]

        min_trials = 20

        # Pre-offer
        epoch_by_cond = epochs_by_cond['preoffer']
        color = '0.7'
        if separate_by_choice:
            for choice, marker in zip(['A', 'B'], ['d', 'o']):
                x = []
                y = []
                for i, offer in enumerate(offers):
                    cond = (offer, choice)
                    if cond in n_by_cond and n_by_cond[cond] >= min_trials:
                        y_i = epoch_by_cond[cond][unit]
                        plot.plot(i, y_i, marker, mfc=color, mec=color, ms=0.8*ms,
                                  mew=0.8*mew, zorder=10)
                        yall.append(y_i)
                        if i != 0 and i != len(offers)-1:
                            x.append(i)
                            y.append(y_i)
                plot.plot(x, y, '-', color=color, lw=0.8*lw, zorder=5)
        else:
            x = []
            y = []
            for i, offer in enumerate(offers):
                y_i = epoch_by_cond[offer][unit]
                plot.plot(i, y_i, 'o', mfc=color, mec=color, ms=0.8*ms,
                          mew=0.8*mew, zorder=10)
                yall.append(y_i)
                if i != 0 and i != len(offers)-1:
                    x.append(i)
                    y.append(y_i)
            plot.plot(x, y, '-', color=color, lw=0.8*lw, zorder=5)

        # Epoch
        epoch_by_cond = epochs_by_cond[epoch]
        if epoch == 'postoffer':
            color = Figure.colors('darkblue')
        elif epoch == 'latedelay':
            color = Figure.colors('darkblue')
        elif epoch == 'prechoice':
            color = Figure.colors('darkblue')
        else:
            raise ValueError(epoch)
        if separate_by_choice:
            for choice, marker, color in zip(['A', 'B'], ['d', 'o'], [Figure.colors('red'), Figure.colors('blue')]):
                x = []
                y = []
                for i, offer in enumerate(offers):
                    cond = (offer, choice)
                    if cond in n_by_cond and n_by_cond[cond] >= min_trials:
                        y_i = epoch_by_cond[cond][unit]
                        yall.append(y_i)
                        plot.plot(i, y_i, marker, mfc=color, mec=color, ms=ms, mew=mew, zorder=10)
                        if i != 0 and i != len(offers)-1:
                            x.append(i)
                            y.append(y_i)
                plot.plot(x, y, '-', color=color, lw=lw, zorder=5)
        else:
            x = []
            y = []
            for i, offer in enumerate(offers):
                y_i = epoch_by_cond[offer][unit]
                plot.plot(i, y_i, 'o', mfc=color, mec=color, ms=ms, mew=mew, zorder=10)
                yall.append(y_i)
                if i != 0 and i != len(offers)-1:
                    x.append(i)
                    y.append(y_i)
            plot.plot(x, y, '-', color=color, lw=lw, zorder=5)

        plot.xticks(range(len(offers)))
        plot.xticklabels(['{}B:{}A'.format(*offer) for offer in offers],
                         rotation=rotation)

        plot.xlim(0, len(offers)-1)
        plot.lim('y', yall, lower=0)

        return yall
Пример #19
0
    'A': (0.01, 0.935),
    'B': (0.28,  0.935)
    }
fig.plotlabels(plotlabels)

#=========================================================================================

plot = fig['choice-upper']

kwargs = {'ms': 4.5, 'lw': 1.25}
analysis.choice_pattern(trialsfile_b, model.offers, plot, **kwargs)

plot.yticks([0, 50, 100])

plot.text_upper_left('1A = {}B'.format(model.A_to_B), fontsize=7.5,
                     color=Figure.colors('green'))

#=========================================================================================

plot = fig['choice-lower']

kwargs = {'ms': 4.5, 'lw': 1.25}
analysis.choice_pattern(trialsfile2_b, model2.offers, plot, **kwargs)

plot.yticks([0, 50, 100])

plot.xlabel('Offer (\#B : \#A)')
plot.ylabel('Percent choice B')

plot.text_upper_left('1A = {}B'.format(model2.A_to_B), fontsize=7.5,
                     color=Figure.colors('green'))