ml-agents icon indicating copy to clipboard operation
ml-agents copied to clipboard

Agent stop exploring after a few iterations and gets stuck in a single behavior

Open theforgottenmachine opened this issue 8 years ago • 4 comments

Hi folks,

I'm trying to create a 3D plane agent that moves in the X, Y, Z planes and it's goal it to reach a cube in the sky. The world space is limitless but the environment is setup so that the cube is always about 400 units away.

//Cube spawning cube.transform.position = new Vector3(UnityEngine.Random.Range(-100f, 50f), UnityEngine.Random.Range(100f, 300f), UnityEngine.Random.Range(300, 400)); cubePosition = cube.transform.position;

My agent always starts at the same place. I am using orientation, vector positions, and distance between the two gameobjects as my observations. I even tried using ray perception (modeled after the push block example).

Current code:

{
        string[] detectableObjects;
        detectableObjects = new string[] { "cube" };
        curPos = plane.transform.position;
        curOrient = plane.transform.rotation;
        prevDist = curDist;
        curDist = (plane.transform.position - cubePosition).magnitude;
        Vector3 targetVec = cubePosition - curPos;
        curAngleBetween = Vector3.Angle(plane.transform.forward, targetVec);
        prevAngleBetween = curAngleBetween;
        float rayDistance = 300f;
        float[] rayAngles = { 0f, 45f, 90f, 135f, 180f, 110f, 70f };
        
        AddVectorObs(rayPer.Perceive(rayDistance, rayAngles, detectableObjects, 0f, 0f));
        AddVectorObs(rayPer.Perceive(rayDistance, rayAngles, detectableObjects, 10f, 0f));

        Vector3 relativePlanePosition = (plane.transform.position - cubePosition);

        // 3 Positions
        AddVectorObs(relativePlanePosition.x );
        AddVectorObs(relativePlanePosition.y );
        AddVectorObs(relativePlanePosition.z );

       


        // 4 Orientations
        AddVectorObs(curOrient.w);
        AddVectorObs(curOrient.x);
        AddVectorObs(curOrient.y);
        AddVectorObs(curOrient.z);

        // Distance from cube
        AddVectorObs(curDist);
}

These are my config settings, at the moment. I've messed around with them a lot, and my agent still gets stuck in the same behavior.

One simple example is that we had a negative reward if the agent crashed and died. There was no way to get that reward (-15f) if you just don't crash. The worst you'd do is -1f. The agent, after just a few thousand iterations would just start diving and crash every single time. Why would that happen? Why would it not explore more options?

max_steps: 500000 learning_rate: 1.0e-5 batch_size: 128 buffer_size: 2048 beta: 1.0e-3 hidden_units: 128 summary_freq: 1000 time_horizon: 64 num_layers: 2

Here are a couple of tensorboards for the last two runs.

image

image

Any and all ideas are GREATLY appreciated! :)

Thanks, Ali

theforgottenmachine avatar Apr 09 '18 22:04 theforgottenmachine

@awjuliani - would you happen to have any ideas, suggestions? What could I be messing up? Thanks!

theforgottenmachine avatar Apr 09 '18 22:04 theforgottenmachine

Make the observations rotational independent. (so you leave out the plane orientation and transform the target position into the local space of the plane)

(copied from an other reply): Then try to decrease the episode length. (in my experience the learning improved significantly when it is below 1000 (i normally aim for 500 or lower). An easy way to reduce this is by changing fixed time step (i currently train with 10 ticks per second). Alternatively you could increase the decision frequency (i havent tried this yet)

And always reset the agent when he does something bad, like moving into the wrong direction for x seconds

And the last thing: never make rewards larger than 1 (the neural network doesn't really learn well with values like the -15 of your crash)

Hengoo avatar Apr 10 '18 10:04 Hengoo

Hi @theforgottenmachine , we are closing this issue due to inactivity, feel free to open it if you need more help on this.

xiaomaogy avatar May 17 '18 21:05 xiaomaogy

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Jan 03 '20 10:01 lock[bot]