Search Unity

Question about actions and AddReward

Discussion in 'ML-Agents' started by ZEBEDEE_ENGINEERING, Feb 6, 2021.

  1. ZEBEDEE_ENGINEERING

    ZEBEDEE_ENGINEERING

    Joined:
    Dec 26, 2019
    Posts:
    10
    Hi
    I have a karting game and my agent receives a vector assigned to acceleration

    ```

    public override void OnActionReceived(float[] vectorAction)
    { acceleration = vectorAction[1];


    }
    ```

    when training I can see that 50% of the time acceleration is less than 0 and 50% of the time it is more than 0, which is to be expected, the result is my kart jiggles a bit but doesn't move forward

    in order to make the kart move forward I added a reward when the acceleration is positive and a penalty when it is negative

    ```

    public override void OnActionReceived(float[] vectorAction)
    { acceleration = vectorAction[1];

    if(acceleration > 0)
    {
    AddReward(1f);
    }
    else if(acceleration < 0)
    {
    AddReward(-1f);
    }
    }
    ```

    I would expect to see over time the ratio would be in favor of more positive acceleration numbers being produced, however the ratio is still 50/50

    Am I fundamentally misunderstanding something here?
     
  2. awjuliani

    awjuliani

    Unity Technologies

    Joined:
    Mar 1, 2017
    Posts:
    69
    Hello. Your intuition is correct. Are there any other rewards in the environment which would be competing with this one?