PsyScriptIcon.png PsyScript: getting experiments done

$query\n"; } $result = mysql_query($database, $query, $connection) or die("ack! query failed: " ."
  • errorno=".mysql_errno() ."
  • error=".mysql_error() ."
  • query=".$query ); return $result; } $Base = "http://www.maccs.mq.edu.au"; $URL= $PHP_SELF; $connection = mysql_connect('localhost', 'tim', 'connect2'); if (!$connection) { print("Cannot connect to database. Call Tim.
    "); exit(); } $result=safe_db_query("Counters","SELECT * FROM Count WHERE Base='$Base' AND URL='$URL'", $connection); while ($row = mysql_fetch_row($result)) { $ChkBase=$row[0]; $ChkURL=$row[1]; $ChkCount=$row[2]; $Count=$ChkCount; } if ($ChkURL == ""){ safe_db_query("Counters","INSERT INTO Count VALUES ('$Base','$URL','0')", $connection); $Count=0; } $Count++; safe_db_query("Counters","UPDATE Count SET Number='$Count' WHERE Base='$Base' AND URL='$URL'"); $result=safe_db_query("Counters","SELECT * FROM Count WHERE Base='$Base' AND URL='$URL'", $connection); while ($row = mysql_fetch_row($result)) { $Base=$row[0]; $URL=$row[1]; $Count=$row[2]; } echo $Count; */ ?>hits
  • PsyScriptIcon.png PsyScript: getting experiments done

    $query\n"; } $result = mysql_db_query($database, $query, $connection) or die("ack! query failed: " ."
  • errorno=".mysql_errno() ."
  • error=".mysql_error() ."
  • query=".$query ); return $result; } $Base = "http://www.maccs.mq.edu.au"; $URL= $PHP_SELF; $connection = mysql_connect('localhost', 'tim', 'connect2'); if (!$connection) { print("Cannot connect to database. Call Tim.
    "); exit(); } $result=safe_db_query("Counters","SELECT * FROM Count WHERE Base='$Base' AND URL='$URL'", $connection); while ($row = mysql_fetch_row($result)) { $ChkBase=$row[0]; $ChkURL=$row[1]; $ChkCount=$row[2]; $Count=$ChkCount; } if ($ChkURL == ""){ safe_db_query("Counters","INSERT INTO Count VALUES ('$Base','$URL','0')", $connection); $Count=0; } $Count++; safe_db_query("Counters","UPDATE Count SET Number='$Count' WHERE Base='$Base' AND URL='$URL'"); $result=safe_db_query("Counters","SELECT * FROM Count WHERE Base='$Base' AND URL='$URL'", $connection); while ($row = mysql_fetch_row($result)) { $Base=$row[0]; $URL=$row[1]; $Count=$row[2]; } echo $Count; */ ?>hits
  • Staircase Library

    This library allows you to crate a staircase object which will handle adaptive experiments (where you vary some parameter of a trial so that a persona gets 80% of stimuli correct).

    If someone wants to make a QUEST version, that would be cool. I have started so call me if you want to help.

    Contents:

    Using the Library

    An example

    The Library Handlers


     

    Using the Library

    -- 1. Create a staircase with starting parameters
    set yourStairCaseName to load script file ("" & Psyscript base folder & " libraries:stairCase library ")
    tell yourStairCaseName to initialize ({ maxreversals : 10 , maxtrials : 20 , stepSize : 4 , initialDuration : 40 })
    -- 2. Start your trial loop
    Update the staircase after each trial
    update ( gradedResponse ) -- 0 for wrong, 1 for correct
    As necessary, update the stepSize
    updateStepSize ( newStep )
    3 . Get data with:
    getRecord ()
    -- >stairCaseRecord
    getParameters ()
    -- >parameters
    completed ()
    -- >true/false

    -- nb: handlers that begin with "i" are for internal use of the object
    -- you should not be calling them


    An example:


    tell application " PsyScript "

    activate
    begin experiment
    set startingParameters to { maxreversals : 10 , maxtrials : 20 , stepSize : 4 , initialDuration : 40 }
    set myStairCase to load script file ("" & Psyscript base folder & " libraries:stairCase library ")
    tell myStairCase to initialize ( startingParameters )
    set myStairCase to my createStairCase ( startingParameters )
    set goodResponse to " Z "
    set completed to false
    set myDuration to initialDuration of startingParameters
    repeat while not completed
    do 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 }
    if ( subject response = goodResponse ) then
    set gradedResponse to 1
    else
    set gradedResponse to 0
    end if
    set myDuration to update ( gradedResponse ) of myStairCase
    set completed to completed () of myStairCase
    end repeat
    display dialog " that took " & trialCount of getRecord () of myStairCase
    end experiment

    end tell
    return { getRecord () of myStairCase , getParameters () of myStairCase }


     

    The Library Handlers

    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}

    -- try
    iInitializeStairCaseRecord ()
    iSetParameters ( pars )
    set currentDuration of stairCaseRecord to initialDuration of parameters
    (* on error
    error
    end try *)
    end initialize

    to update ( gradedResponse ) -- 0 if wrong, 1 if correct
    -- try
    -- 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 then
    iHandleShift (" up ") -- one wrong, so shift up
    else if last2responses = { 1 , 1 } then
    iHandleShift (" down ") -- that's three correct in a row, so shift down
    else
    iHandleShift (" none ") -- no shift, but update the history
    end if
    return currentDuration of stairCaseRecord
    (* on error
    error "update failed"
    end try *)
    end update

    to updateStepSize ( newStep )
    set stepSize of parameters to newStep
    end updateStepSize

    on getRecord ()
    return stairCaseRecord
    end getRecord

    on getParameters ()
    return parameters
    end getParameters

    on completed ()
    if (( reversals of stairCaseRecord ª maxreversals of parameters ) or ( trialCount of stairCaseRecord ª maxtrials of parameters )) then
    return true
    else
    return false
    end if
    end completed

    -- should never need to call these handlers (they start with an "i" for "internal use only"


    to iSetParameters ( pars )
    set parameters to pars
    end iSetParameters


    to iInitializeStairCaseRecord ()
    set stairCaseRecord to { currentDuration : 0 , history :{ -1 , -1 , -1 }, reversals : 0 , directionList :{}, trialCount : 0 }
    end iInitializeStairCaseRecord

    to iUpDateResponseHistory ( gradedResponse )
    set beginning of history of stairCaseRecord to gradedResponse
    end iUpDateResponseHistory

    to iInitializeResponseHistory ()
    set history of stairCaseRecord to { -1 , -1 , -1 }
    end iInitializeResponseHistory

    to iHandleShift ( direction )
    -- try
    set end of directionList of stairCaseRecord to direction
    if trialCount of stairCaseRecord ¿ 2 then
    -- there is no history yet
    else if direction ° item -2 of directionList of stairCaseRecord then
    set reversals of stairCaseRecord to ( reversals of stairCaseRecord ) + 1
    end if -- no need to update reversals

    if direction is " none " then
    -- nothin but us chickens in here
    else
    if direction = " up " then
    set currentDuration of stairCaseRecord to ( currentDuration of stairCaseRecord ) + ( stepSize of parameters )
    else if direction = " down " then
    set currentDuration of stairCaseRecord to ( currentDuration of stairCaseRecord ) - ( stepSize of parameters )
    else
    error " direction must be up, down, or none "
    end if
    iInitializeResponseHistory ()
    end if
    (* on error
    error "shiftup"
    end try *)

    end iHandleShift

     

    MACCS PsyScriptIcon.png Documentation Downloads FAQ Mailing List
    Last change:
    Advanced Search

    Applescript in a Nutshell : A Desktop Quick Reference

    AppleScript for Applications: Visual QuickStart Guide

    AppleScript For Dummies

    Applescript for the Internet Visual Quickstart Guide

    Applescript Language Guide; English Dialect

    Danny Goodman's Applescript Handbook
    MACCS PsyScriptIcon.png Documentation Downloads FAQ Mailing List
    Last change:
    Advanced Search

    Applescript in a Nutshell : A Desktop Quick Reference

    AppleScript for Applications: Visual QuickStart Guide

    AppleScript For Dummies

    Applescript for the Internet Visual Quickstart Guide

    Applescript Language Guide; English Dialect

    Danny Goodman's Applescript Handbook