PR coding help
MEDState Notation Repository › Forums › Coding Help Archive › PR coding help
- This topic has 7 replies, 1 voice, and was last updated 8 years, 9 months ago by
Med_Support.
-
AuthorPosts
-
August 27, 2014 at 12:05 pm #12985
Med_Support
Moderatorandersem
Hi there, I have a very simple PR code that I need help with. The PR code works fine, but I need the program to end after a total of 5 hours or if a reward has not been received in an hour (regardless of how many lever presses occurred between the last reward). Below is the code that I have edited from the uploaded codes on med state board. Any help would be appreciated!
\ Copyright (c) 2013 MEDState Notation Repository, All rights reserved. \ ProgressiveRatio_v2.mpc \ \ When the program is started it will turn on the HouseLight and the lights over \ both Levers, and the current PR Value will be set to the first value drawn in \ order from List Z. The program will then wait for the Animal to respond on \ the Correct Lever enough times to meet the current PR Value. \ \ When the current PR Value has been met the program will turn on the Reward \ Device for the Reward Time. At the end of the Reward Time the program will \ time the Time Out Following Reward. \ \ When the Time Out Following Reward has been completed the program set the \ current PR Value to the next value drawn in order from List Z. \ \ The program will then once again wait for the Animal to respond on the Correct \ Lever enough times to meet the current PR Value. \ The program will end when the Session Length has been reached. \ Inputs ^LeftLever = 1 \ Outputs ^Pellet = 3 ^LeftLight = 4 ^LeftLeverOperate= 1 ^HouseLight = 7 ^Fan = 9 \ 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 (60 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; SHOW 1,Session,S/300 ---> 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/300; IF S/300 >= 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^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: 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, ^LeftLever; 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, #Z^Z_Pellet: ON ^Pellet ---> 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
August 27, 2014 at 12:58 pm #12986Med_Support
ModeratorGary Bamberger
You have already set the Session Time to 300 minutes so that will take care of the 5 hour time limit. For the no reward in 60 minutes criteria I believe the following change should do the trick:
\*************************************************** \ REWARD CONTROL TIMER \*************************************************** S.S.3, S1, #Z^Z_Pellet: ON ^Pellet ---> S2 60': Z^Z_End ---> STOPABORTFLUSH \ End if no reward received in 60 minutes 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
I hope that this information helps.
…
I was just noticing that the code in S.S.1, S4 had been modified
S4, \ Time Session Length 0.01": SET S = S + 0.01; SHOW 1,Session,S/300; IF S/300 >= A(^Session) [@EndSession, @ContinueTiming] @End: Z^Z_End ---> S5 @Cont: ---> SXThe value in S is in seconds and the value in A(^Session) is in minutes. You should be dividing S by 60 to convert it into minutes for the comparison to see if the Session Time has been met.
S4, \ Time Session Length 0.01": SET S = S + 0.01; SHOW 1,Session,S/60; IF S/60 >= A(^Session) [@EndSession, @ContinueTiming] @End: Z^Z_End ---> S5 @Cont: ---> SXGary
September 8, 2014 at 9:30 am #12989Med_Support
Moderatorandersem
Great, thanks again for your amazing help!
…
I have a new issue with this program. I want the lever, cue and house light to go in or turn off after receiving the reward for the 20 second time out. It seems that this is working as they turn back on 20 seconds after going in. However, the time out during which another pellet can be earned seems longer than 20 seconds since responses immediately after the lever comes back out are not being counted. Any ideas? Thanks, Eden
\ Copyright (c) 2013 MEDState Notation Repository, All rights reserved. \ ProgressiveRatio_v2.mpc \ \ When the program is started it will turn on the HouseLight and the lights over \ both Levers, and the current PR Value will be set to the first value drawn in \ order from List Z. The program will then wait for the Animal to respond on \ the Correct Lever enough times to meet the current PR Value. \ \ When the current PR Value has been met the program will turn on the Reward \ Device for the Reward Time. At the end of the Reward Time the program will \ time the Time Out Following Reward. \ \ When the Time Out Following Reward has been completed the program set the \ current PR Value to the next value drawn in order from List Z. \ \ The program will then once again wait for the Animal to respond on the Correct \ Lever enough times to meet the current PR Value. \ The program will end when the Session Length has been reached. \ Inputs ^LeftLever = 1 \ Outputs ^Pellet = 3 ^LeftLight = 4 ^LeftLeverOperate= 1 ^HouseLight = 7 ^Fan = 9 \ 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 (60 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; SHOW 1,Session,S/300 ---> 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/300; 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 #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: 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, ^LeftLever; 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, #Z^Z_Pellet: ON ^Pellet; OFF ^HouseLight, ^LeftLeverOperate, ^LeftLight ---> S2 60': Z^Z_End ---> STOPABORTFLUSH \end if no reward received in 60 minutes S2, \ Time Reward Device for A(^RewardTime) seconds \ Default value set in S.S.1, S1 & S2 A(^RewardTicks)#T: OFF ^Pellet ---> S3 S3, 20": ON ^HouseLight, ^LeftLeverOperate, ^LeftLight; 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
September 8, 2014 at 10:12 am #12992Med_Support
ModeratorGary Bamberger
It looks like you have two timeouts in the program. S.S.3 implements a 20″ Timeout after issuing the reward and then issues a Z^Z_EndReward. S.S.2, S3 waits for that Z^Z_EndReward signal and then does another 20″ Timeout in S4.
You probably want to remove the Timeout in S.S.3 so that you can use the variable Timeout in S.S.2.
Gary
September 8, 2014 at 10:46 am #12994Med_Support
Moderatorandersem
So this should work? Thanks!
\***************************************************\ MAIN PROGRAM\***************************************************S.S.2,S1, \ Draw first Progressive Ratio from List Z #START: LIST P = Z(X) ---> S2S2, \ 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 #Z^Z_End: ---> S5S3, \ Wait for End of Reward Signal #Z^Z_End: ---> S5 #Z^Z_EndReward: ---> S4S4, \ Time Out Interval Following Reward \ Update Progressive Ratio P from LIST Z 0.001": ON ^HouseLight, ^LeftLight, ^LeftLever; A(^TimeOutTicks)#T: LIST P = Z(X) ---> S2 #Z^Z_End: ---> S5S5, \ End of Session - Turn Lights Off \ Calculate % Correct and % Incorrect 0.01": OFF ^HouseLight, ^LeftLight, ^LeftLever; 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) ---> S6S6, \ Holding State at End of Session 1': ---> SX\***************************************************\ REWARD CONTROL TIMER\***************************************************S.S.3,S1, #Z^Z_Pellet: ON ^Pellet; OFF ^HouseLight, ^LeftLeverOperate, ^LeftLight ---> S2 60': Z^Z_End ---> STOPABORTFLUSH \end if no reward received in 60 minutesS2, \ Time Reward Device for A(^RewardTime) seconds \ Default value set in S.S.1, S1 & S2 A(^RewardTicks)#T: OFF ^Pellet
Sorry, it didnt look like that in my posted reply, I am attaching the edits. That should work?
September 8, 2014 at 11:00 am #12997Med_Support
Moderatorandersem
Sorry, it didnt look like that in my posted reply, I am attaching the edits. That should work?
September 8, 2014 at 11:08 am #12999Med_Support
ModeratorGary Bamberger
That was close, but I don’t think you want the House Light and Levers coming back on until the end of the Time out. I think this will do what you want.
\*************************************************** \ 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 #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, ^LeftLever; 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, ^LeftLever; 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 ---> 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
Gary
September 8, 2014 at 11:18 am #13001Med_Support
Moderatorandersem
Works wonders, thanks! Someday I may fully understand how to program.
Eden
-
AuthorPosts
- You must be logged in to reply to this topic.