示例#1
0
 def setUp(self):
     self.proc = ud.UpDownMethod(stepSize=[4, 4, 2, 2, 1, 1])
     self.proc(False)
     self.proc(False)
     self.proc(True)
     self.proc(True)
     self.proc(True)
     self.proc(True)
     self.proc(False)
     self.proc(False)
     self.proc(True)
     self.proc(True)
     self.proc(True)
     self.proc(True)
     self.proc(False)
     self.proc(False)
     self.proc(True)
     self.proc(True)
     self.proc(True)
     self.proc(True)
     self.proc(False)
     self.proc(False)
     self.proc(True)
     self.proc(True)
     self.proc(False)
     self.proc(False)
     self.proc(True)
     self.proc(True)
     self.proc(False)
     self.proc(False)
     self.proc(True)
     self.proc(True)
 def test_runs(self):
     runs = ud.runs(self.results)
     self.assertIsNone(
         np.testing.assert_array_equal(runs["Start"].values,
                                       [1, 3, 7, 9, 12, 17, 20, 22]))
     self.assertIsNone(
         np.testing.assert_array_equal(runs["Finish"].values,
                                       [3, 7, 9, 12, 17, 20, 22, 24]))
示例#3
0
    def __call__(self, resp):

        if self.nextValue is not None:

            if (len(ud.reversals(self.results)) < self.reversals) & \
                    (len(self.results) < self.maxTrials):

                self.nextValue, self.results = \
                    ud.append_result(self.results, resp, self.down,
                                     self.up, self.stepSize, self.nextValue)

                if (self.nextValue > self.maxValue) | \
                   (self.nextValue < self.minValue):

                    self.nextValue = None
            else:
                self.nextValue = None

        return self.nextValue
 def test_reversals(self):
     revs = ud.reversals(self.results)
     self.assertIsNone(
         np.testing.assert_array_equal(revs["Reversal"].values,
                                       [1, 2, 3, 4, 5, 6, 7]))
     self.assertIsNone(
         np.testing.assert_array_equal(revs["Trial"].values,
                                       [3, 7, 9, 12, 17, 20, 22]))
     self.assertIsNone(
         np.testing.assert_array_equal(revs["Value"].values,
                                       [-2, 2, 0, 3, -2, 1, -1]))
示例#5
0
    def __init__(self,
                 down=2,
                 up=1,
                 stepSize=2,
                 initialValue=0,
                 maxValue=float("inf"),
                 minValue=-float("inf"),
                 reversals=float("inf"),
                 trials=float("inf")):

        self.results = ud.initiate_procedure()
        self.down = down
        self.up = up
        self.stepSize = stepSize
        self.nextValue = initialValue
        self.reversals = reversals
        self.maxValue = maxValue
        self.minValue = minValue
        self.maxTrials = trials
示例#6
0
 def test_Levitt_fig4(self):
     self.stim1 = ud.UpDownMethod(down=1, up=1, stepSize=1, initialValue=0)
     for resp in resp1:
         self.stim1(resp)
     est = ud.estimate_reversals(self.stim1.results)
     self.assertEqual(est, 0)
 def test_estimate_reversals(self):
     est = ud.estimate_reversals(self.results)
     self.assertEqual(est, 0)
     est = ud.estimate_reversals(self.results, num=4)
     self.assertEqual(est, 0.25)
 def test_plotResults(self):
     ud.plot_results(self.results, midpoints=True)
     plt.savefig('doc/images/Levitt-Fig4.png', bbox_inches='tight')
 def test_calculateMidpoints(self):
     mids = ud.midpoints(self.results)
     mids = mids["Midpoint"]
     mids = mids[[1, 3, 5]].values  # Runs 2, 4, 6
     self.assertIsNone(np.testing.assert_array_equal(mids, [0., 1.5, -0.5]))
 def test_initiateResults(self):
     self.results = ud.initiate_procedure()
     self.assertIs(len(self.results), 0)
 def setUp(self):
     self.results = ud.initiate_procedure()
     nextValue, self.results = ud.append_result(self.results, responses[0],
                                                down, up, stepSize,
                                                initalValue)
     for resp in responses[1:]:
         nextValue, self.results = ud.append_result(self.results, resp,
                                                    down, up, stepSize,
                                                    nextValue)
         ud.midpoints(self.results)
         ud.reversals(self.results)
         ud.estimate_reversals(self.results)
         ud.runs(self.results)
示例#12
0
def plot_results(results,
                 midpoints=False,
                 figure=None,
                 estimate=False,
                 reversals=False,
                 runs=True):

    if figure is None:
        figure = plt.figure()

    figure.clf()

    figure.add_subplot(111)
    plt.hold(True)

    # Plot correct responses
    corr = results[results['Responses'] == True]
    if len(corr) > 0:
        plt.scatter(corr.index + 1, corr.Value, s=50, marker='+', c='k')

    # Plot incorrect responses
    incorr = results[results['Responses'] == False]
    if len(incorr) > 0:
        plt.scatter(incorr.index + 1, incorr.Value, s=50, marker='_', c='k')

    # Indicate reversals
    if reversals:
        reversal = results[results['Reversal'] == True]
        if len(reversal) > 0:
            plt.scatter(reversal.index + 1,
                        reversal.Value,
                        facecolors='none',
                        edgecolors='k',
                        s=200)

    # Track the runs
    if runs is not False:
        runs = ud.runs(results)
        for i in range(len(runs)):

            r = runs.iloc[[i]]

            start = r["Start"]
            end = r["Finish"]
            mid = start + (end - start) / 2

            runY = min(results.Value) - 1

            plt.errorbar(mid, runY, xerr=(end - start) / 2, c='k')
            plt.annotate(str(int(i + 1)),
                         xy=(mid, runY - 0.5),
                         xytext=(mid, runY - 0.5))

    if estimate is not False:
        est = ud.estimate_reversals(results, num=estimate)
        if est is not None:
            plt.axhline(y=est, ls='--')
            plt.text(0, est + 0.05, "Estimate = " + str(est), fontsize=12)

    if midpoints:
        mids = ud.midpoints(results)
        for i in range(len(mids)):
            plt.scatter(mids['CentreTrial'].values[i],
                        mids['Midpoint'].values[i],
                        c='r')

    if len(results) > 0:
        plt.xlim(-0.5, max(results.index) + 2.5)
    plt.ylabel('Stimulus Value', fontsize=14)
    plt.xlabel('Trial Number', fontsize=14)

    return figure
示例#13
0
 def test_Levitt_fig5(self):
     self.stim2 = ud.UpDownMethod(down=2, up=1, stepSize=1, initialValue=0)
     for resp in resp2:
         self.stim2(resp)
     est = ud.estimate_reversals(self.stim2.results)
     self.assertEqual(est, 1.5)
示例#14
0
 def setUp(self):
     self.results = ud.initiate_procedure()
示例#15
0
 def test_estimate_reversals(self):
     est = ud.estimate_reversals(self.results)
     self.assertIsNone(est)
示例#16
0
 def test_reversals(self):
     revs = ud.reversals(self.results)
     self.assertIs(len(revs), 0)
示例#17
0
 def test_runs(self):
     runs = ud.runs(self.results)
     self.assertIs(len(runs), 0)
示例#18
0
 def test_calculateMidpoints(self):
     mids = ud.midpoints(self.results)
     self.assertIs(len(mids), 0)