示例#1
0
def sure_stimulus_duration(trialsfile, plot, saved=None, **kwargs):
    if saved is not None:
        psure_by_duration_by_coh = saved
    else:
        trials, A, R, M, perf = utils.load(trialsfile)

        # Sort
        trials_by_cond = {}
        for n, trial in enumerate(trials):
            if not trial['wager']:
                continue

            cond = trial['coh']
            if perf.choices[n] is not None:
                trials_by_cond.setdefault(cond, {'durations': [], 'sures': []})

                duration = np.ptp(trial['durations']['stimulus'])
                trials_by_cond[cond]['durations'].append(duration)
                trials_by_cond[cond]['sures'].append(perf.choices[n] == 'S')

        # Number of bins
        nbins = kwargs.get('nbins', 10)

        # Average
        psure_by_duration_by_coh = {}
        for coh, v in trials_by_cond.items():
            (xbins, ybins, xedges,
             binsizes) = datatools.partition(v['durations'], v['sures'], nbins=nbins)
            duration = [np.mean(xbin) for xbin in xbins]
            psure = [utils.divide(np.sum(ybin > 0), len(ybin)) for ybin in ybins]
            psure_by_duration_by_coh[coh] = (duration, psure)

    #=====================================================================================
    # Plot
    #=====================================================================================

    lineprop = {'lw':  kwargs.get('lw', 1)}
    dataprop = {'ms':  kwargs.get('ms', 7),
                'mew': kwargs.get('mew', 0)}
    colors = kwargs.get('colors', kiani2009_colors)

    cohs = sorted(psure_by_duration_by_coh)
    for coh in cohs:
        duration, psure = psure_by_duration_by_coh[coh]

        plot.plot(duration, psure, color=colors[coh], label='{}\%'.format(coh), **lineprop)
        plot.plot(duration, psure, 'o', mfc=colors[coh], **dataprop)

    plot.xlim(100, 800)
    plot.ylim(0, 1)

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

    return psure_by_duration_by_coh
示例#2
0
def sure_stimulus_duration(trialsfile, plot, saved=None, **kwargs):
    if saved is not None:
        psure_by_duration_by_coh = saved
    else:
        trials, A, R, M, perf = utils.load(trialsfile)

        # Sort
        trials_by_cond = {}
        for n, trial in enumerate(trials):
            if not trial['wager']:
                continue

            cond = trial['coh']
            if perf.choices[n] is not None:
                trials_by_cond.setdefault(cond, {'durations': [], 'sures': []})

                duration = np.ptp(trial['durations']['stimulus'])
                trials_by_cond[cond]['durations'].append(duration)
                trials_by_cond[cond]['sures'].append(perf.choices[n] == 'S')

        # Number of bins
        nbins = kwargs.get('nbins', 10)

        # Average
        psure_by_duration_by_coh = {}
        for coh, v in trials_by_cond.items():
            (xbins, ybins, xedges,
             binsizes) = datatools.partition(v['durations'], v['sures'], nbins=nbins)
            duration = [np.mean(xbin) for xbin in xbins]
            psure = [utils.divide(np.sum(ybin > 0), len(ybin)) for ybin in ybins]
            psure_by_duration_by_coh[coh] = (duration, psure)

    #=====================================================================================
    # Plot
    #=====================================================================================

    lineprop = {'lw':  kwargs.get('lw', 1)}
    dataprop = {'ms':  kwargs.get('ms', 7),
                'mew': kwargs.get('mew', 0)}
    colors = kwargs.get('colors', kiani2009_colors)

    cohs = sorted(psure_by_duration_by_coh)
    for coh in cohs:
        duration, psure = psure_by_duration_by_coh[coh]

        plot.plot(duration, psure, color=colors[coh], label='{}\%'.format(coh), **lineprop)
        plot.plot(duration, psure, 'o', mfc=colors[coh], **dataprop)

    plot.xlim(100, 800)
    plot.ylim(0, 1)

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

    return psure_by_duration_by_coh
示例#3
0
def correct_stimulus_duration(trialsfile, plot, saved=None, **kwargs):
    if saved is not None:
        pcorrect_by_duration_by_coh, pcorrect_by_duration_by_coh_wager = saved
    else:
        trials, A, R, M, perf = utils.load(trialsfile)

        # Sort
        trials_by_cond       = {}
        trials_by_cond_wager = {}
        for n, trial in enumerate(trials):
            coh = trial['coh']
            if coh == 0 or perf.choices[n] not in ['L', 'R']:
                continue

            cond     = coh
            duration = np.ptp(trial['durations']['stimulus'])
            if trial['wager']:
                trials_by_cond_wager.setdefault(cond, {'durations': [], 'corrects': []})
                trials_by_cond_wager[cond]['durations'].append(duration)
                trials_by_cond_wager[cond]['corrects'].append(perf.corrects[n])
            else:
                trials_by_cond.setdefault(cond, {'durations': [], 'corrects': []})
                trials_by_cond[cond]['durations'].append(duration)
                trials_by_cond[cond]['corrects'].append(perf.corrects[n])

        # Number of bins
        nbins = kwargs.get('nbins', 10)

        # Average no-wager trials
        pcorrect_by_duration_by_coh = {}
        for coh, v in trials_by_cond.items():
            (xbins, ybins, xedges,
             binsizes) = datatools.partition(v['durations'], v['corrects'], nbins=nbins)
            duration = [np.mean(xbin) for xbin in xbins]
            pcorrect = [utils.divide(np.sum(ybin > 0), len(ybin)) for ybin in ybins]
            pcorrect_by_duration_by_coh[coh] = (duration, pcorrect)

        # Average wager trials
        pcorrect_by_duration_by_coh_wager = {}
        for coh, v in trials_by_cond_wager.items():
            (xbins, ybins, xedges,
             binsizes) = datatools.partition(v['durations'], v['corrects'], nbins=nbins)
            duration = [np.mean(xbin) for xbin in xbins]
            pcorrect = [utils.divide(np.sum(ybin > 0), len(ybin)) for ybin in ybins]
            pcorrect_by_duration_by_coh_wager[coh] = (duration, pcorrect)

    #=====================================================================================
    # Plot
    #=====================================================================================

    lineprop = {'ls':     '--',
                'lw':     kwargs.get('lw', 1),
                'dashes': kwargs.get('dashes', [9, 4])}
    dataprop = {'mew': kwargs.get('mew', 1)}
    dataprop['ms'] = kwargs.get('ms', 6) + dataprop['mew']/2

    lineprop_wager = {'lw':  kwargs.get('lw', 1)}
    dataprop_wager = {'ms':  kwargs.get('ms', 7),
                      'mew': kwargs.get('mew', 0)}

    colors = kwargs.get('colors', kiani2009_colors)

    # No-wager trials
    cohs = sorted(pcorrect_by_duration_by_coh)
    for coh in cohs:
        duration, pcorrect = pcorrect_by_duration_by_coh[coh]

        plot.plot(duration, pcorrect, color=colors[coh], zorder=10, **lineprop)
        plot.plot(duration, pcorrect, 'o', mfc='w', mec=colors[coh],
                  zorder=10, **dataprop)

    # Wager trials
    cohs = sorted(pcorrect_by_duration_by_coh_wager)
    for coh in cohs:
        duration, pcorrect = pcorrect_by_duration_by_coh_wager[coh]

        plot.plot(duration, pcorrect, color=colors[coh], zorder=5, **lineprop_wager)
        plot.plot(duration, pcorrect, 'o', mfc=colors[coh], mec=colors[coh],
                  zorder=5, **dataprop_wager)

    plot.xlim(100, 800)
    plot.ylim(0.5, 1)

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

    return pcorrect_by_duration_by_coh, pcorrect_by_duration_by_coh_wager
示例#4
0
def value_stimulus_duration(trialsfile, plot, saved=None, **kwargs):
    if saved is not None:
        value_by_duration_by_coh, value_by_duration_by_coh_wager = saved
    else:
        # Load trials
        trials, U, Z, Z_b, A, P, M, perf, r_p, r_v = utils.load(trialsfile)

        # Time
        time = trials[0]['time']

        # Sort
        trials_by_cond       = {}
        trials_by_cond_wager = {}
        for n, trial in enumerate(trials):
            coh = trial['coh']
            if coh == 0 or perf.choices[n] not in ['L', 'R']:
                continue

            cond     = coh
            duration = np.ptp(trial['durations']['stimulus'])

            delay_start, _ = trial['durations']['delay']
            before_sure,   = np.where((delay_start <= time) & (time < delay_start+500))
            value          = np.mean(Z_b[before_sure,n])
            if trial['wager']:
                trials_by_cond_wager.setdefault(cond, {'durations': [], 'values': []})
                trials_by_cond_wager[cond]['durations'].append(duration)
                trials_by_cond_wager[cond]['values'].append(value)
            else:
                trials_by_cond.setdefault(cond, {'durations': [], 'values': []})
                trials_by_cond[cond]['durations'].append(duration)
                trials_by_cond[cond]['values'].append(value)

        # Number of bins
        nbins = kwargs.get('nbins', 10)

        # Average no-wager trials
        value_by_duration_by_coh = {}
        for coh, v in trials_by_cond.items():
            (xbins, ybins, xedges,
             binsizes) = datatools.partition(v['durations'], v['values'], nbins=nbins)
            duration = [np.mean(xbin) for xbin in xbins]
            value    = [np.mean(ybin) for ybin in ybins]
            value_by_duration_by_coh[coh] = (duration, value)

        # Average wager trials
        value_by_duration_by_coh_wager = {}
        for coh, v in trials_by_cond_wager.items():
            (xbins, ybins, xedges,
             binsizes) = datatools.partition(v['durations'], v['values'], nbins=nbins)
            duration = [np.mean(xbin) for xbin in xbins]
            value    = [np.mean(ybin) for ybin in ybins]
            value_by_duration_by_coh_wager[coh] = (duration, value)

    #=====================================================================================
    # Plot
    #=====================================================================================

    lineprop = {'ls':     '--',
                'lw':     kwargs.get('lw', 1),
                'dashes': kwargs.get('dashes', [9, 4])}
    dataprop = {'mew': kwargs.get('mew', 1)}
    dataprop['ms'] = kwargs.get('ms', 6) + dataprop['mew']/2

    lineprop_wager = {'lw':  kwargs.get('lw', 1)}
    dataprop_wager = {'ms':  kwargs.get('ms', 7),
                      'mew': kwargs.get('mew', 0)}

    colors = kwargs.get('colors', kiani2009_colors)

    # No-wager trials
    cohs = sorted(value_by_duration_by_coh)
    for coh in cohs:
        duration, value = value_by_duration_by_coh[coh]

        plot.plot(duration, value, color=colors[coh], zorder=10, **lineprop)
        plot.plot(duration, value, 'o', mfc='w', mec=colors[coh],
                  zorder=10, **dataprop)

    # Wager trials
    cohs = sorted(value_by_duration_by_coh_wager)
    for coh in cohs:
        duration, value = value_by_duration_by_coh_wager[coh]

        plot.plot(duration, value, color=colors[coh], zorder=5, **lineprop_wager)
        plot.plot(duration, value, 'o', mfc=colors[coh], mec=colors[coh],
                  zorder=5, **dataprop_wager)

    plot.xlim(100, 800)
    #plot.ylim(0.5, 1)

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

    return value_by_duration_by_coh, value_by_duration_by_coh_wager
示例#5
0
def correct_stimulus_duration(trialsfile, plot, saved=None, **kwargs):
    if saved is not None:
        pcorrect_by_duration_by_coh, pcorrect_by_duration_by_coh_wager = saved
    else:
        trials, A, R, M, perf = utils.load(trialsfile)

        # Sort
        trials_by_cond       = {}
        trials_by_cond_wager = {}
        for n, trial in enumerate(trials):
            coh = trial['coh']
            if coh == 0 or perf.choices[n] not in ['L', 'R']:
                continue

            cond     = coh
            duration = np.ptp(trial['durations']['stimulus'])
            if trial['wager']:
                trials_by_cond_wager.setdefault(cond, {'durations': [], 'corrects': []})
                trials_by_cond_wager[cond]['durations'].append(duration)
                trials_by_cond_wager[cond]['corrects'].append(perf.corrects[n])
            else:
                trials_by_cond.setdefault(cond, {'durations': [], 'corrects': []})
                trials_by_cond[cond]['durations'].append(duration)
                trials_by_cond[cond]['corrects'].append(perf.corrects[n])

        # Number of bins
        nbins = kwargs.get('nbins', 10)

        # Average no-wager trials
        pcorrect_by_duration_by_coh = {}
        for coh, v in trials_by_cond.items():
            (xbins, ybins, xedges,
             binsizes) = datatools.partition(v['durations'], v['corrects'], nbins=nbins)
            duration = [np.mean(xbin) for xbin in xbins]
            pcorrect = [utils.divide(np.sum(ybin > 0), len(ybin)) for ybin in ybins]
            pcorrect_by_duration_by_coh[coh] = (duration, pcorrect)

        # Average wager trials
        pcorrect_by_duration_by_coh_wager = {}
        for coh, v in trials_by_cond_wager.items():
            (xbins, ybins, xedges,
             binsizes) = datatools.partition(v['durations'], v['corrects'], nbins=nbins)
            duration = [np.mean(xbin) for xbin in xbins]
            pcorrect = [utils.divide(np.sum(ybin > 0), len(ybin)) for ybin in ybins]
            pcorrect_by_duration_by_coh_wager[coh] = (duration, pcorrect)

    #=====================================================================================
    # Plot
    #=====================================================================================

    lineprop = {'ls':     '--',
                'lw':     kwargs.get('lw', 1),
                'dashes': kwargs.get('dashes', [9, 4])}
    dataprop = {'mew': kwargs.get('mew', 1)}
    dataprop['ms'] = kwargs.get('ms', 6) + dataprop['mew']/2

    lineprop_wager = {'lw':  kwargs.get('lw', 1)}
    dataprop_wager = {'ms':  kwargs.get('ms', 7),
                      'mew': kwargs.get('mew', 0)}

    colors = kwargs.get('colors', kiani2009_colors)

    # No-wager trials
    cohs = sorted(pcorrect_by_duration_by_coh)
    for coh in cohs:
        duration, pcorrect = pcorrect_by_duration_by_coh[coh]

        plot.plot(duration, pcorrect, color=colors[coh], zorder=10, **lineprop)
        plot.plot(duration, pcorrect, 'o', mfc='w', mec=colors[coh],
                  zorder=10, **dataprop)

    # Wager trials
    cohs = sorted(pcorrect_by_duration_by_coh_wager)
    for coh in cohs:
        duration, pcorrect = pcorrect_by_duration_by_coh_wager[coh]

        plot.plot(duration, pcorrect, color=colors[coh], zorder=5, **lineprop_wager)
        plot.plot(duration, pcorrect, 'o', mfc=colors[coh], mec=colors[coh],
                  zorder=5, **dataprop_wager)

    plot.xlim(100, 800)
    plot.ylim(0.5, 1)

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

    return pcorrect_by_duration_by_coh, pcorrect_by_duration_by_coh_wager
示例#6
0
def value_stimulus_duration(trialsfile, plot, saved=None, **kwargs):
    if saved is not None:
        value_by_duration_by_coh, value_by_duration_by_coh_wager = saved
    else:
        # Load trials
        trials, U, Z, Z_b, A, P, M, perf, r_p, r_v = utils.load(trialsfile)

        # Time
        time = trials[0]['time']

        # Sort
        trials_by_cond       = {}
        trials_by_cond_wager = {}
        for n, trial in enumerate(trials):
            coh = trial['coh']
            if coh == 0 or perf.choices[n] not in ['L', 'R']:
                continue

            cond     = coh
            duration = np.ptp(trial['durations']['stimulus'])

            delay_start, _ = trial['durations']['delay']
            before_sure,   = np.where((delay_start <= time) & (time < delay_start+500))
            value          = np.mean(Z_b[before_sure,n])
            if trial['wager']:
                trials_by_cond_wager.setdefault(cond, {'durations': [], 'values': []})
                trials_by_cond_wager[cond]['durations'].append(duration)
                trials_by_cond_wager[cond]['values'].append(value)
            else:
                trials_by_cond.setdefault(cond, {'durations': [], 'values': []})
                trials_by_cond[cond]['durations'].append(duration)
                trials_by_cond[cond]['values'].append(value)

        # Number of bins
        nbins = kwargs.get('nbins', 10)

        # Average no-wager trials
        value_by_duration_by_coh = {}
        for coh, v in trials_by_cond.items():
            (xbins, ybins, xedges,
             binsizes) = datatools.partition(v['durations'], v['values'], nbins=nbins)
            duration = [np.mean(xbin) for xbin in xbins]
            value    = [np.mean(ybin) for ybin in ybins]
            value_by_duration_by_coh[coh] = (duration, value)

        # Average wager trials
        value_by_duration_by_coh_wager = {}
        for coh, v in trials_by_cond_wager.items():
            (xbins, ybins, xedges,
             binsizes) = datatools.partition(v['durations'], v['values'], nbins=nbins)
            duration = [np.mean(xbin) for xbin in xbins]
            value    = [np.mean(ybin) for ybin in ybins]
            value_by_duration_by_coh_wager[coh] = (duration, value)

    #=====================================================================================
    # Plot
    #=====================================================================================

    lineprop = {'ls':     '--',
                'lw':     kwargs.get('lw', 1),
                'dashes': kwargs.get('dashes', [9, 4])}
    dataprop = {'mew': kwargs.get('mew', 1)}
    dataprop['ms'] = kwargs.get('ms', 6) + dataprop['mew']/2

    lineprop_wager = {'lw':  kwargs.get('lw', 1)}
    dataprop_wager = {'ms':  kwargs.get('ms', 7),
                      'mew': kwargs.get('mew', 0)}

    colors = kwargs.get('colors', kiani2009_colors)

    # No-wager trials
    cohs = sorted(value_by_duration_by_coh)
    for coh in cohs:
        duration, value = value_by_duration_by_coh[coh]

        plot.plot(duration, value, color=colors[coh], zorder=10, **lineprop)
        plot.plot(duration, value, 'o', mfc='w', mec=colors[coh],
                  zorder=10, **dataprop)

    # Wager trials
    cohs = sorted(value_by_duration_by_coh_wager)
    for coh in cohs:
        duration, value = value_by_duration_by_coh_wager[coh]

        plot.plot(duration, value, color=colors[coh], zorder=5, **lineprop_wager)
        plot.plot(duration, value, 'o', mfc=colors[coh], mec=colors[coh],
                  zorder=5, **dataprop_wager)

    plot.xlim(100, 800)
    #plot.ylim(0.5, 1)

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

    return value_by_duration_by_coh, value_by_duration_by_coh_wager