Using the Library
An example
The Library Handlers
tell yourStairCaseName to initialize ({ maxreversals : 10 , maxtrials : 20 , stepSize : 4 , initialDuration : 40 })-- 1. Create a staircase with starting parametersset yourStairCaseName to load script file ("" & Psyscript base folder & " libraries:stairCase library ")
-- 2. Start your trial loop
Update the staircase after each trial3 . Get data with:update ( gradedResponse ) -- 0 for wrong, 1 for correctAs necessary, update the stepSizeupdateStepSize ( newStep )getRecord ()-- >stairCaseRecordgetParameters ()
-- >parameters
completed ()-- >true/false
-- nb: handlers that begin with "i" are for internal use of the object
-- you should not be calling them
activateset myStairCase to load script file ("" & Psyscript base folder & " libraries:stairCase library ")
begin experiment
set startingParameters to { maxreversals : 10 , maxtrials : 20 , stepSize : 4 , initialDuration : 40 }
set myStairCase to my createStairCase ( startingParameters )
set goodResponse to " Z "
set completed to false
set myDuration to initialDuration of startingParameters
repeat while not completeddo trial " !e + #100 !e 'duration = ?1 screen refreshes' !v?1 'Push ¯zå to get this correct, any other to get it wrong' !t(2000) " given { myDuration }end repeat
if ( subject response = goodResponse ) thenset gradedResponse to 1elseset gradedResponse to 0end if
set myDuration to update ( gradedResponse ) of myStairCase
set completed to completed () of myStairCase
display dialog " that took " & trialCount of getRecord () of myStairCase
end experiment
end tell
return { getRecord ()
of myStairCase , getParameters
() of myStairCase }
property parameters
: { maxreversals : 0 , maxtrials
: 0 , stepSize : 1
, initialDuration : 10 }
property stairCaseRecord
: { currentDuration : 10
, history :{ -1 , -1
, -1 }, reversals : 0
, directionList :{}, trialCount
: 0 }
-- currentDuration = the variable being staircased.
-- history: a history as deep as is needed
-- reversals: count of reversals
-- directionList: history of directions
-- valid directions = "up" "down" and "none"
-- trialCount: speaks for itself
-- assumptions: that you run the duration that it gives
you
to initialize ( pars
) -- pars must be a valid parameter record, i.e., {maxreversals:5,
maxtrials:3, stepSize:1, initialDuration:10}
-- tryend initialize
iInitializeStairCaseRecord ()
iSetParameters ( pars )
set currentDuration of stairCaseRecord to initialDuration of parameters
(* on errorerrorend try *)
-- tryend update
-- update history and trial count
set trialCount of stairCaseRecord to ( trialCount of stairCaseRecord ) + 1
set gradedResponse to gradedResponse as integer
iUpDateResponseHistory ( gradedResponse )
set last2responses to items 2 thru 3 of history of stairCaseRecord
if gradedResponse = 0 theniHandleShift (" up ") -- one wrong, so shift upelse if last2responses = { 1 , 1 } theniHandleShift (" down ") -- that's three correct in a row, so shift downelseiHandleShift (" none ") -- no shift, but update the historyend if
return currentDuration of stairCaseRecord
(* on errorerror "update failed"end try *)
set stepSize of parameters to newStepend updateStepSize
return stairCaseRecordend getRecord
return parametersend getParameters
if (( reversals of stairCaseRecord ª maxreversals of parameters ) or ( trialCount of stairCaseRecord ª maxtrials of parameters )) thenend completedreturn trueelsereturn falseend if
set parameters to parsend iSetParameters
set stairCaseRecord to { currentDuration : 0 , history :{ -1 , -1 , -1 }, reversals : 0 , directionList :{}, trialCount : 0 }end iInitializeStairCaseRecord
set beginning of history of stairCaseRecord to gradedResponseend iUpDateResponseHistory
set history of stairCaseRecord to { -1 , -1 , -1 }end iInitializeResponseHistory
-- try
set end of directionList of stairCaseRecord to direction
if trialCount of stairCaseRecord ¿ 2 then-- there is no history yetelse if direction ° item -2 of directionList of stairCaseRecord thenset reversals of stairCaseRecord to ( reversals of stairCaseRecord ) + 1end if -- no need to update reversals
if direction is " none " then-- nothin but us chickens in hereelseif direction = " up " thenend ifset currentDuration of stairCaseRecord to ( currentDuration of stairCaseRecord ) + ( stepSize of parameters )else if direction = " down " thenset currentDuration of stairCaseRecord to ( currentDuration of stairCaseRecord ) - ( stepSize of parameters )elseerror " direction must be up, down, or none "end if
iInitializeResponseHistory ()
(* on errorerror "shiftup"end try *)
end iHandleShift
| MACCS | |
Documentation | Downloads | FAQ | Mailing List | Last change: echo date( "F d Y.", getlastmod() ); ?> |
| Advanced Search |