Responding across time

MEDState Notation Repository Forums Coding Help Archive Responding across time

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #12730
    Med_Support
    Moderator
    andersem

    Hi there, I am interested in obtaining the responses across time in say, one minute time bins. How would I go about coding that? Would it come out in the data back up then? Below is the current code we are using.

     

    \ Inputs
    ^LeftLever = 1
    ^RightLever =3
    \ Outputs
    ^Pellet = 3
    ^LeftLight = 4
    ^LeftLeverOperate= 1
    ^HouseLight = 7
    ^Fan = 9
    ^RightLight = 5
    ^RightLeverOperate = 2
    
    
    \ A() = Control Variables with Assigned Aliases as Defined
    Var_Alias Session Length (min) = A(0) \ Default = 300 minutes
    Var_Alias Correct Lever (1=Left 2=Right) = A(1) \ Default = 1-Left
    Var_Alias Reward Device (1=Pellet 2=Dipper 3=Pump) = A(2) \ Default = 1-Pellet
    Var_Alias Reward Time (sec) = A(3) \ Default = 0.05 seconds
    Var_Alias Time Out Following Reward (sec) = A(4) \ Default = 20 seconds
    Var_Alias SoftCR Data Array (1=Yes 0=No) = A(5) \ Default = 1-Yes
    
    ^Session = 0
    ^CorrectLev = 1
    ^RewardDevice = 2
    ^RewardTime = 3
    ^TimeOut = 4
    ^SoftCR = 5
    ^RewardTicks = 6
    ^TimeOutTicks = 7
    
    
    \ List Data Variables Here
    \ B() = Response Counts
    \ B(0) = Total Responses
    \ B(1) = Total Correct Response Count
    \ B(2) = Total Incorrect Response Count
    \ B(3) = Total Rewards
    \ B(4) = % Correct
    \ B(5) = % Incorrect
    \ B(6) = Last PR Value that was Met
    
    
    \ List Working Variables Here
    \ I = Subscript for the IRT Array C
    \ P = Current PR Value
    \ R = Ratio Response Counter
    \ S = Elapsed Time in Session
    \ X = Subscript for Progressive Ratio List Z
    \ Z() = Progressive Ratio Default List
    
    
    DIM A = 7
    DIM B = 6
    
    LIST Z = 1, 2, 4, 6, 9, 12, 15, 20, 25, 32, 40, 50, 62, 77, 95, 118, 145, 178, 219, 268, 328, 402, 492, 603, 737, 901, 1102, 1347, 1646, 2012
    \ Z-Pulses Used in this Program
    ^Z_Pellet = 1 \ Signal Pellet Reinforcement
    ^Z_Dipper = 2 \ Signal Dipper Reinforcement
    ^Z_Pump = 3 \ Signal Pump Reinforcement
    ^Z_EndReward = 4 \ Signal End of Reward
    ^Z_End = 32 \ Signal End of Session
    
    
    \***************************************************
    \ Progressive Ratio Schedule
    \ S1 - Set Default Values
    \ Session Length (300 minutes)
    \ Correct Lever (1-Left)
    \ Reward Device (1-Pellet)
    \ Reward Time (0.05 seconds)
    \ Time Out Following Reward (20 seconds)
    \ SoftCR Data Array (1-Yes)
    \***************************************************
    S.S.1,
    S1,
    0.01": SET A(^Session) = 300, A(^CorrectLev) = 1, A(^RewardDevice) = 1;
    SET A(^RewardTime) = 0.05, A(^TimeOut) = 20, A(^SoftCR) = 1 ---> S2
    S2,
    0.001": ON ^fan ---> S3
    S3, \ First Statement: Wait for START signal, turn HouseLight ON
    \ and turn associated stimulus ON.
    \
    \ Second Statement: Update screen display with default values
    \ for Control Variables. This will show any changes made via
    \ the "Configure | Change Variables" Window prior to START.
    #START: CLEAR 1,200;
    SET A(^RewardTicks) = A(^RewardTime) * 1";
    SET A(^TimeOutTicks) = A(^TimeOut) * 1";
    ON ^HouseLight, ^LeftLight, ^LeftLever, ^RightLeverOperate;
    SHOW 1,Session,S ---> S4
    1": SHOW 1,Session Length,A(^Session), 2,Correct Lever,A(^CorrectLev), 3,Reward Device,A(^RewardDevice);
    SHOW 4,Reward Time,A(^RewardTime), 5,Time Out,A(^TimeOut), 6,SoftCR Code,A(^SoftCR) ---> SX
    
    S4, \ Time Session Length
    0.01": SET S = S + 0.01;
    SHOW 1,Session,S;
    IF S/60 >= A(^Session) [@EndSession, @ContinueTiming]
    @End: Z^Z_End ---> S5
    @Cont: ---> SX
    
    S5, \ Wait for Screen Update and end with
    \ STOPABORTFLUSH for Automatic Data Saving
    2": ---> STOPABORTFLUSH
    
    
    \***************************************************
    \ MAIN PROGRAM
    \***************************************************
    S.S.2,
    S1, \ Draw first Progressive Ratio from List Z
    #START: LIST P = Z(X) ---> S2
    
    S2, \ Test for Correct Lever
    #RA(^CorrectLev): ADD B(0), B(1), R;
    IF R >= P [@PR_Value_Met, @False]
    @PR_Met: ADD B(3);
    SET B(6) = P, R = 0;
    ZA(^RewardDevice) ---> S3
    @False: ---> SX
    #R^RightLever: ADD B(0), B(2) ---> SX
    #Z^Z_End: ---> S5
    
    S3, \ Wait for End of Reward Signal
    #Z^Z_End: ---> S5
    #Z^Z_EndReward: ---> S4
    
    S4, \ Time Out Interval Following Reward
    \ Update Progressive Ratio P from LIST Z
    A(^TimeOutTicks)#T: ON ^HouseLight, ^LeftLight, ^LeftLeverOperate, ^RightLeverOperate;
    LIST P = Z(X) ---> S2
    #Z^Z_End: ---> S5
    
    S5, \ End of Session - Turn Lights Off
    \ Calculate % Correct and % Incorrect
    0.01": OFF ^HouseLight, ^LeftLight, ^LeftLeverOperate, ^RightLeverOperate;
    IF B(0) = 0 [@NoCalc, @Calculate]
    @NoCalc: ---> S6
    @Calculate: SET B(4) = B(1) / B(0) * 100;
    SET B(5) = B(2) / B(0) * 100;
    SHOW 7,% Correct,B(4), 8,% Incorrect,B(5), 10,Last PR Met,B(6) ---> S6
    
    S6, \ Holding State at End of Session
    1': ---> SX
    
    
    \***************************************************
    \ REWARD CONTROL TIMER
    \***************************************************
    
    S.S.3,
    S1,
    60': Z^Z_End ---> STOPABORTFLUSH \ End if no reward received in 60 minutes
    #Z^Z_Pellet: ON ^Pellet;
    OFF ^HouseLight, ^LeftLeverOperate, ^LeftLight, ^RightLeverOperate ---> S2
    
    S2, \ Time Reward Device for A(^RewardTime) seconds
    \ Default value set in S.S.1, S1 & S2
    A(^RewardTicks)#T: OFF ^Pellet;
    Z^Z_EndReward ---> S1
    
    \***************************************************
    \ UPDATE DISPLAY
    \***************************************************
    
    S.S.4,
    S1,
    #START: SHOW 2,Correct Rsp,B(1), 3,Incorrect Rsp,B(2), 4,Rewards,B(3), 5,PR Value,P ---> S2
    
    S2,
    1": SHOW 2,Correct Rsp,B(1), 3,Incorrect Rsp,B(2), 4,Rewards,B(3), 5,PR Value,P ---> S2
    
    \***************************************************
    \ LAST REWARD TIMER
    \***************************************************
    S.S.5,
    S1,
    #ZA(^RewardDevice): ---> S2
    
    
    S2,
    #ZA(^RewardDevice): Set Y = 0 --->S2
    0.1": SET Y = Y + 0.1;
    SHOW 6,Last Reward,Y ---> S2
    
    #12729
    Med_Support
    Moderator
    Gary Bamberger

    Hello,

    The following might work for you.

    Gary

     

    DIM D = 5000
    \ D(0)   = Total Responses on Left  Lever
    \ D(1)   = Total Responses on Right Lever
    \ D(J)   = Responses on Left  Lever this Time Bin
    \ D(J+1) = Responses on Right Lever this Time Bin

    \ J = Index into Time Bin Array D

     

    \***************************************************
    \                 TIME BIN CONTROL
    \***************************************************
    S.S.6,
    S1,
    0.01″: SET D(J) = -987.987 —> S2

    S2,
    #START: SET D(J) = 0, J = 2, D(J+2) = -987.987 —> S3

    S3,     \ Every 1 minutes increment the index
    \ into the Time Bin Array
    1′: SET J = J + 2, D(J) = 0, D(J+2) = -987.987 —> SX

     

    \***************************************************
    \         RECORD LEFT/RIGHT LEVER RESPONSES
    \***************************************************
    S.S.7,
    S1,
    #START: —> S2

    S2,     \ Record the Total Responses and the
    \ number of Responses this Time Bin
    #R^LeftLever:  ADD D(0), D(J)   —> S2
    #R^RightLever: ADD D(1), D(J+1) —> S2

     

    #12733
    Med_Support
    Moderator
    andersem

    It seems to be combining the responses of both the right and the left lever across time. Any ideas? Below is the output.

     

    File: C:\MED-PC IV\DATA\!2016-04-13
    
     
    
     
    
     
    
    Start Date: 04/13/16
    End Date: 04/13/16
    Subject: 0
    Experiment: 0
    Group: 0
    Box: 12
    Start Time: 9:45:25
    End Time: 9:58:46
    MSN: PR L Active timed
    C: 0.000
    E: 0.000
    F: 0.000
    G: 0.000
    H: 0.000
    I: 0.000
    J: 28.000
    K: 0.000
    L: 0.000
    M: 0.000
    N: 0.000
    O: 0.000
    P: 6.000
    Q: 0.000
    R: 0.000
    S: 793.390
    T: 0.000
    U: 0.000
    V: 0.000
    W: 0.000
    X: 4.000
    Y: 15.900
    A:
    0: 300.000 1.000 1.000 0.050 20.000
    5: 1.000 5.000 2000.000
    B:
    0: 71.000 13.000 58.000 4.000 0.000
    5: 0.000 6.000
    D:
    0: 13.000 58.000 1.000 48.000 6.000
    5: 0.000 0.000 0.000 0.000 0.000
    10: 0.000 0.000 0.000 0.000 0.000
    15: 0.000 0.000 0.000 0.000 0.000
    20: 0.000 0.000 0.000 0.000 0.000
    25: 0.000 6.000 10.000 0.000 0.000
    Z:
    0: 1.000 2.000 4.000 6.000 9.000
    5: 12.000 15.000 20.000 25.000 32.000
    10: 40.000 50.000 62.000 77.000 95.000
    15: 118.000 145.000 178.000 219.000 268.000
    20: 328.000 402.000 492.000 603.000 737.000
    25: 901.000 1102.000 1347.000 1646.000 2012.000
    
    #12735
    Med_Support
    Moderator
    Gary Bamberger

    The data looks fine to me

    \ D(0) = Total Responses on Left Lever
     \ D(1) = Total Responses on Right Lever
     \ D(J) = Responses on Left Lever this Time Bin
     \ D(J+1) = Responses on Right Lever this Time Bin
    
    \ Left Lever Right Lever
     D:
     0: 13.000 58.000 \ Total
     2: 1.000 48.000 \ 1st minute
     4: 6.000 0.000 \ 2nd minute
     6: 0.000 0.000 \ 3rd minute
     8: 0.000 0.000 \ 4th minute
     10: 0.000 0.000 \ 5th minute
     12: 0.000 0.000 \ 6th minute
     14: 0.000 0.000 \ 7th minute
     16: 0.000 0.000 \ 8th minute
     18: 0.000 0.000 \ 9th minute
     20: 0.000 0.000 \ 10th minute
     22: 0.000 0.000 \ 11th minute
     24: 0.000 0.000 \ 12th minute
     26: 6.000 10.000 \ 13th minute
     28: 0.000 0.000 \ 14th minute
    #12737
    Med_Support
    Moderator
    andersem

    Thank you for the help!

    This might be a silly question again. I am doing the exact same thing with the same program just using the R lever as the active lever. It seems to be adding a count to the Right lever counts. Here is the code:

     

    \ Inputs
    ^LeftLever = 1
    ^RightLever =3
    \ Outputs
    ^Pellet = 3
    ^LeftLight = 4
    ^LeftLeverOperate= 1
    ^HouseLight = 7
    ^Fan = 9
    ^RightLight = 5
    ^RightLeverOperate = 2

    \ A() = Control Variables with Assigned Aliases as Defined
    Var_Alias Session Length (min) = A(0) \ Default = 300 minutes
    Var_Alias Correct Lever (1=Left 2=Right) = A(1) \ Default = 2-Right
    Var_Alias Reward Device (1=Pellet 2=Dipper 3=Pump) = A(2) \ Default = 1-Pellet
    Var_Alias Reward Time (sec) = A(3) \ Default = 0.05 seconds
    Var_Alias Time Out Following Reward (sec) = A(4) \ Default = 20 seconds
    Var_Alias SoftCR Data Array (1=Yes 0=No) = A(5) \ Default = 1-Yes

    ^Session = 0
    ^CorrectLev = 2
    ^RewardDevice = 1
    ^RewardTime = 3
    ^TimeOut = 4
    ^SoftCR = 5
    ^RewardTicks = 6
    ^TimeOutTicks = 7

    \ List Data Variables Here
    \ B() = Response Counts
    \ B(0) = Total Responses
    \ B(1) = Total Correct Response Count
    \ B(2) = Total Incorrect Response Count
    \ B(3) = Total Rewards
    \ B(4) = % Correct
    \ B(5) = % Incorrect
    \ B(6) = Last PR Value that was Met

    \ List Working Variables Here
    \ I = Subscript for the IRT Array C
    \ P = Current PR Value
    \ R = Ratio Response Counter
    \ S = Elapsed Time in Session
    \ X = Subscript for Progressive Ratio List Z
    \ Z() = Progressive Ratio Default List

    DIM A = 7
    DIM B = 6

    LIST Z = 1, 2, 4, 6, 9, 12, 15, 20, 25, 32, 40, 50, 62, 77, 95, 118, 145, 178, 219, 268, 328, 402, 492, 603, 737, 901, 1102, 1347, 1646, 2012
    \ Z-Pulses Used in this Program
    ^Z_Pellet = 1 \ Signal Pellet Reinforcement
    ^Z_Dipper = 2 \ Signal Dipper Reinforcement
    ^Z_Pump = 3 \ Signal Pump Reinforcement
    ^Z_EndReward = 4 \ Signal End of Reward
    ^Z_End = 32 \ Signal End of Session

    DIM D = 5000
    \ D(0) = Total Responses on Left Lever
    \ D(1) = Total Responses on Right Lever
    \ D(J) = Responses on Left Lever this Time Bin
    \ D(J+1) = Responses on Right Lever this Time Bin

    \ J = Index into Time Bin Array D

    \***************************************************
    \ Progressive Ratio Schedule
    \ S1 – Set Default Values
    \ Session Length (300 minutes)
    \ Correct Lever (1-Left)
    \ Reward Device (1-Pellet)
    \ Reward Time (0.05 seconds)
    \ Time Out Following Reward (20 seconds)
    \ SoftCR Data Array (1-Yes)
    \***************************************************
    S.S.1,
    S1,
    0.01″: SET A(^Session) = 300, A(^CorrectLev) = 2, A(^RewardDevice) = 1;
    SET A(^RewardTime) = 0.05, A(^TimeOut) = 20, A(^SoftCR) = 1 —> S2
    S2,
    0.001″: ON ^fan —> S3
    S3, \ First Statement: Wait for START signal, turn HouseLight ON
    \ and turn associated stimulus ON.
    \
    \ Second Statement: Update screen display with default values
    \ for Control Variables. This will show any changes made via
    \ the “Configure | Change Variables” Window prior to START.
    #START: CLEAR 1,200;
    SET A(^RewardTicks) = A(^RewardTime) * 1″;
    SET A(^TimeOutTicks) = A(^TimeOut) * 1″;
    ON ^HouseLight, ^RightLight, ^LeftLever, ^RightLeverOperate;
    SHOW 1,Session,S —> S4
    1″: SHOW 1,Session Length,A(^Session), 2,Correct Lever,A(^CorrectLev), 3,Reward Device,A(^RewardDevice);
    SHOW 4,Reward Time,A(^RewardTime), 5,Time Out,A(^TimeOut), 6,SoftCR Code,A(^SoftCR) —> SX

    S4, \ Time Session Length
    0.01″: SET S = S + 0.01;
    SHOW 1,Session,S;
    IF S/60 >= A(^Session) [@EndSession, @ContinueTiming]
    @End: Z^Z_End —> S5
    @Cont: —> SX

    S5, \ Wait for Screen Update and end with
    \ STOPABORTFLUSH for Automatic Data Saving
    2″: —> STOPABORTFLUSH

    \***************************************************
    \ MAIN PROGRAM
    \***************************************************
    S.S.2,
    S1, \ Draw first Progressive Ratio from List Z
    #START: LIST P = Z(X) —> S2

    S2, \ Test for Correct Lever
    #R(^Rightlever): ADD B(0), B(1), R;
    IF R >= P [@PR_Value_Met, @False]
    @PR_Met: ADD B(3);
    SET B(6) = P, R = 0;
    ZA(^RewardDevice) —> S3
    @False: —> SX
    #R^leftLever: ADD B(0), B(2) —> SX
    #Z^Z_End: —> S5

    S3, \ Wait for End of Reward Signal
    #Z^Z_End: —> S5
    #Z^Z_EndReward: —> S4

    S4, \ Time Out Interval Following Reward
    \ Update Progressive Ratio P from LIST Z
    A(^TimeOutTicks)#T: ON ^HouseLight, ^RightLight, ^LeftLeverOperate, ^RightLeverOperate;
    LIST P = Z(X) —> S2
    #Z^Z_End: —> S5

    S5, \ End of Session – Turn Lights Off
    \ Calculate % Correct and % Incorrect
    0.01″: OFF ^HouseLight, ^RightLight, ^LeftLeverOperate, ^RightLeverOperate;
    IF B(0) = 0 [@NoCalc, @Calculate]
    @NoCalc: —> S6
    @Calculate: SET B(4) = B(1) / B(0) * 100;
    SET B(5) = B(2) / B(0) * 100;
    SHOW 7,% Correct,B(4), 8,% Incorrect,B(5), 10,Last PR Met,B(6) —> S6

    S6, \ Holding State at End of Session
    1′: —> SX

    \***************************************************
    \ REWARD CONTROL TIMER
    \***************************************************

    S.S.3,
    S1,
    60′: Z^Z_End —> STOPABORTFLUSH \ End if no reward received in 60 minutes
    #Z^Z_Pellet: ON ^Pellet;
    OFF ^HouseLight, ^LeftLeverOperate, ^RightLight, ^RightLeverOperate —> S2

    S2, \ Time Reward Device for A(^RewardTime) seconds
    \ Default value set in S.S.1, S1 & S2
    A(^RewardTicks)#T: OFF ^Pellet;
    Z^Z_EndReward —> S1

    \***************************************************
    \ UPDATE DISPLAY
    \***************************************************

    S.S.4,
    S1,
    #START: SHOW 2,Correct Rsp,B(1), 3,Incorrect Rsp,B(2), 4,Rewards,B(3), 5,PR Value,P —> S2

    S2,
    1″: SHOW 2,Correct Rsp,B(1), 3,Incorrect Rsp,B(2), 4,Rewards,B(3), 5,PR Value,P —> S2

    \***************************************************
    \ LAST REWARD TIMER
    \***************************************************
    S.S.5,
    S1,
    #ZA(^RewardDevice): —> S2

    S2,
    #ZA(^RewardDevice): Set Y = 0 —>S2
    0.1″: SET Y = Y + 0.1;
    SHOW 6,Last Reward,Y —> S2

    \***************************************************
    \ TIME BIN CONTROL
    \***************************************************
    S.S.6,
    S1,
    0.01″: SET D(J) = -987.987 —> S2

    S2,
    #START: SET D(J) = 0, J = 2, D(J+2) = -987.987 —> S3

    S3, \ Every 1 minutes increment the index
    \ into the Time Bin Array
    1′: SET J = J + 2, D(J) = 0, D(J+2) = -987.987 —> SX

    \***************************************************
    \ RECORD LEFT/RIGHT LEVER RESPONSES
    \***************************************************
    S.S.7,
    S1,
    #START: —> S2

    S2, \ Record the Total Responses and the
    \ number of Responses this Time Bin
    #R^LeftLever: ADD D(0), D(J) —> S2
    #R^RightLever: ADD D(1), D(J+1) —> S2

     

    I pressed the L lever 6 times and the R lever 3 times in the first minute. In the second minute the L lever was pressed 4 times and the R lever was pressed 10 times. Thanks again for the continued help. Below is the output that I received:

     

    Start Date: 06/28/16
    End Date: 06/28/16
    Subject: 0
    Experiment: 0
    Group: 0
    Box: 12
    Start Time: 9:08:14
    End Time: 9:10:09
    MSN: PR R Active timed
    C: 0.000
    E: 0.000
    F: 0.000
    G: 0.000
    H: 0.000
    I: 0.000
    J: 4.000
    K: 0.000
    L: 0.000
    M: 0.000
    N: 0.000
    O: 0.000
    P: 6.000
    Q: 0.000
    R: 0.000
    S: 109.320
    T: 0.000
    U: 0.000
    V: 0.000
    W: 0.000
    X: 4.000
    Y: 13.400
    A:
    0: 300.000 1.000 2.000 0.050 20.000
    5: 1.000 5.000 2000.000
    B:
    0: 23.000 13.000 10.000 4.000 0.000
    5: 0.000 6.000
    D:
    0: 10.000 15.000 6.000 4.000 4.000
    5: 11.000
    Z:
    0: 1.000 2.000 4.000 6.000 9.000
    5: 12.000 15.000 20.000 25.000 32.000
    10: 40.000 50.000 62.000 77.000 95.000
    15: 118.000 145.000 178.000 219.000 268.000
    20: 328.000 402.000 492.000 603.000 737.000
    25: 901.000 1102.000 1347.000 1646.000 2012.000

    #12739
    Med_Support
    Moderator
    Gary Bamberger

    The data looks fine to me:

    \  B() = Response Counts
    \  B(0) = Total Responses
    \  B(1) = Total Correct   Response Count
    \  B(2) = Total Incorrect Response Count
    \  B(3) = Total Rewards
    \  B(4) = % Correct
    \  B(5) = % Incorrect
    \  B(6) = Last PR Value that was Met

    \ D(0)   = Total Responses on Left  Lever
    \ D(1)   = Total Responses on Right Lever
    \ D(J)   = Responses on Left  Lever this Time Bin
    \ D(J+1) = Responses on Right Lever this Time Bin

    B:
    0:       23.000       13.000     \ 23 Total Responses             13 Correct Right Responses
    2:       10.000        4.000     \ 10 Incorrect Left Responses     4 Rewards Earned
    4:        0.000        0.000
    6:        6.000                  \ 6 = Last Progressive Ratio value that was met

     

    \           Left Lever  Right Lever
    D:
    0:       10.000       15.000  \ Totals
    2:        6.000        4.000  \ 1st Minute
    4:        4.000       11.000  \ 2nd Minute

    The reason that the total is higher in the D Array is that there must have been 2 responses on the right lever during the reward (S.S.2, S3) or Timeout (S.S.2, S4).

    S.S.7 does not care what State S.S.2 is in.  It just counts all responses.

     

    I hope that this information helps.

    Best Regards,
    Gary

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.