Help with RANDI function please!

MEDState Notation Repository Forums Coding Help Archive Help with RANDI function please!

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #12972
    Med_Support
    Moderator
    drothfuss

    Hello there,

    I am currently piloting a PR lever press task but I have no experience in writing MED PC code. I want to add a light that turns on at random once per PR interval, and cannot turn on at the same time as the reward. It seems to me the best way to do this is to have an IF function that says when the current lever presses towards the reward equals the required lever presses for reward divided by a random integer from 2 to 5 (using RANDI), the light turns on. Below is my attempt, but thus far it has not worked. Can anyone provide insight as to why, or possibly another way to approach the problem? Thanks so much!

    \Inputs
    ^LeftLever = 1
    ^RightLever = 2
    
    \Outputs
    ^LeftLever = 1
    ^RightLever = 2
    ^PelletFeeder = 3
    ^LeftLight = 4
    ^RightLight = 5
    ^HouseLight = 7
    ^RandomLight = 8
    
    \Define Variables
    \A= LeftLever Presses
    \B=RightLever Presses
    \C=Reward counter and holds the fixed ratio list position
    \F=Current Fixed Ratio
    \G=Ratio List Position
    \P=Presses toward current ratio
    \N=Session Timer
    \T=Session Time
    \Q=Value assigned from list R
    
    \Define Arrays
    \V(0-5000) Active Lever Array
    \W(0-1000) = Inactive Lever array
    
    LIST F = 1,3,5,8,12,16,22,29,38,50,65,84,108,139,178,228,291,371,473,603,767,977,1243,1582,2012,2559,3255,4139,5263,6692,8509,10818
    LIST R = 2,3,4,5
    
     
    
    DIM V = 5000, W = 1000
    
    \Session Timer
    S.S.1,
    S1,
    #Start: ON^HouseLight; SET P = 0, G = 0, T = 120; SHOW 5, Session Time, N/60 ---> S2
    S2,
    1": ADD N; SHOW 5, Session Time, N/60; IF N/60 >= T [@True, @False]
    @True: ---> STOPABORTFLUSH
    @False: IF N <= 2 [@T, @F]
    @T: ---> SX
    @F: ON^LeftLever, ^RightLever---> SX
    
    \Main Control logic for Progressive Ratio
    S.S.2,
    S1,
    #Z1: IF P >= F(C) [@True, @False]
    @True: ON^PelletFeeder; Z2 ---> SX
    @False: ---> SX
    
     
    
    \Active Lever Counter
    S.S.3,
    S1,
    #Start: SHOW 1, Active Presses, A ---> S2
    S2,
    #R^LeftLever: SET V(A) = N; ADD A; ADD P; SHOW 1, Active Presses, A; Z1 ---> SX
    
     
    
    \Inactive Lever Counter
    S.S.4,
    S1,
    #Start: SHOW 2, Inactive Presses, B ---> S2
    S2,
    #R^RightLever: SET W(B) = N; ADD B; SHOW 2, Inactive Presses, B ---> SX
    
     
    
    \Ratio counter
    S.S.5,
    S1,
    #Start: SHOW 3, Break Point, F(C) ---> S2
    S2,
    #Z2: SHOW 3, Break Point, F(C) ---> SX
    
     
    
    \Reward Counter
    S.S.6,
    S1,
    #Start: SHOW 4, Rewards, C ---> S2
    S2,
    #Z2: ADD C; SET P = 0; Show 4, Rewards, C; Z3 ---> SX \update r list after "add c"
    
    \Light Flash
    S.S.7,
    S1,
    #Z3: ON^LeftLight, ^RightLight ---> S2
    S2,
    0.5": OFF^PelletFeeder, ^LeftLight, ^RightLight ---> S1
    
     
    
    \Random Light
    S.S.8,
    S1,
    #Start: RANDI Q = R; IF P = F(C)/Q [@True, @False]
    @True: ---> S2
    @False: ---> SX
    S2,
    0.01": ON^RandomLight ---> S3
    S3,
    0.5": OFF^RandomLight ---> SX
    
    #12973
    Med_Support
    Moderator
    Gary Bamberger

    So here is the relevant code:

    \ Random Light
    S.S.8,
    S1,
    #START: RANDI Q = R;
    IF P = F(C) / Q [@True, @False]
    @True:  ---> S2
    @False: ---> SX
    
    S2,
    0.01": ON ^RandomLight ---> S3
    
    S3,
    0.5": OFF ^RandomLight ---> SX
    
     
    
    When a START command is issued you draw a value from List R and then check IF P = F(C) / Q.  Since the program has just started P = 0 and C = 0 (F(C) = F(0) = 1) so the statement is:
    
    IF 0 = 1 / 3 [@True, @False]   (I'm assuming 3 was drawn, but it could have been any of the four numbers)
    
    This is of course False and causes a transition back to SX or back to State 1.  Since we are still in S1 nothing will happen until another START command is received.
    
    The first thing is that we need to transition to a different State when the START command is issued.
    
     
    
    \ Random Light
    S.S.8,
    S1,
    #START: RANDI Q = R ---> S2
    

     

    Next what is the input criteria that causes us to check if the Random Light needs to turn on?  The equation is checking if the number of responses equals the Progressive Ratio divided by a random number.  So we could use the response on the Left Lever as the input criteria.

     

    S2,
    #R^LeftLever: IF P >= F(C) / Q [@True, @False]
    @True:  ---> S3
    @False: ---> SX
    

     

    Notice that I changed the = to >=.  IF 1 >= 1 / 3, then the equation will be True, but IF 1 = 1 / 3 will never be True.

    One final change is needed.  After the Random Light has been flashed we don’t want the Random Light to flash again until the reward has been issued so we need to wait for the reward signal:

     

    S3,
    0.01": ON ^RandomLight ---> S4
    
    S4,
    0.5": OFF ^RandomLight ---> S5
    
    S5,
    #Z2: RANDI Q = R ---> S2
    
     
    
    Once the reward signal has been received we then want to draw a new value from List R and go back to wait for the next response on the Left Lever.
    
    Give it a try and let me know if this works for you.
    
    Gary
    #12976
    Med_Support
    Moderator
    drothfuss

    Thanks so much Gary! Works great now and I have a better understanding of how the code works. Very clear answer

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