I am using clipped PPO to train a neural network to act as the controller for steering an aircraft, and am finding that my networks aren't learning. The goal is to keep the aircraft flying to cover the distance, and the code is implemented using Pytorch. I am wondering if anyone who is more experienced would be willing to take a look at my implementation.

Aircraft and actor model
I have a flight simulation environment with the dynamical system of an aircraft, where the simulation is propagated through time in 0.1s increments. The states of the aircraft serve as inputs to the actor network (airspeed, pitch, heading, height), and the controls include pitch and roll angles.

The actor network uses a multivariate normal distribution to output two values that serve as the means for the pitch and roll angle controls. The variances are fixed. This way, the policy is stochastic and allows for exploration. I am using two hidden layers of 256 neurons each for both actor and critic networks, with learning rates of 1e-4. ReLu activation on the hidden layers and sigmoid on the actor's output, with the critic's output being linear.

Reward structure
I have tried two different reward structures:

  1. A reward of 1 for every time step that the aircraft is in the air (with a reward of 0 in the terminal state, which is when the aircraft crashes to the ground or if it achieves the maximum flight time)
  2. A reward of 0 for every time step, but a single reward computed at the terminal state that is proportional to the displacement of the aircraft over the simulation, and an extremely large penalty that is subtracted from this reward if the aircraft crashes.

Neither of these reward structures seemed to allow learning. I am wondering if simply having a reward of 1 at every time step, much like the gym cartpole environment is insufficient in getting the model to learn how to fly. I was expecting the network to figure out ways of controlling the aircraft to fly longer to obtain a greater total reward. For the second reward structure, I expected the advantage estimation to carry the large reward/penalty backward through the trajectory so that the actor would learn to avoid flying in certain ways that end up in crashing the plane.

PPO implementation
For the clipped PPO implementation, I am:

  1. Resetting the flight simulation environment
  2. Propagating the simulation until the aircraft crashes or reaches maximum flight time
  3. Training the actor and critic networks every 20 time steps (2s of simulation)
  4. Repeating this for a maximum number of simulations

For training, I take the 20 time steps, shuffle them, and divide them into 5 batches. Then I train the network on these batches, reshuffle the 20 time steps and create 5 new batches, and train again. I repeat this process for a total of 4 epochs per learning cycle.

The fastest that the aircraft can reach the ground (crash) is 1.7s of simulation time (17 time steps), whereas I want the aircraft to fly ultimately for 10m (6000 time steps). I am thinking that it is too difficult to train a network to fly for such a long period of time because it would have to learn all the states leading up to that point.

I found that training the algorithm typically resulted in extreme volatility in the test simulation's score (sum of all rewards at every time step). The score history would look like:moving average of 100 scores in orange (moving average of 100 scores in orange).

What I've tried

  1. Changing the standard deviation of the normal distribution of the actor output so that there is less exploration (stability of the aircraft is quite sensitive to the particular control values).
  2. Advantage normalization
  3. Increasing training time to 10 000 simulations (~40 000 learning iterations since there are 4 epochs per simulation)
  4. Testing the algorithm on the gym's cartpole environment (discrete actions). I was able to successfully train the actor in 200ish games.

If anyone has any other suggestions of things to try, it would be greatly appreciated.


2 Answers 2


Training using only 20 timesteps at a time is far too small, especially when the goal will ultimately consist of episodes of length 6000. You definitely need to increase that substantially and that will probably solve your problem immediately. You might try something like simulate 5 episodes and then train on all timesteps in those 5 episodes.

If that still doesn't work, another thing you can do is try training the value function (critic) differently, e.g. use monte carlo returns or more steps in the temporal difference, and you can keep a memory replay for the value function as well.

  • $\begingroup$ Thanks for your suggestion. I've tried it out, and it doesn't seem to be doing too much better. I'm wondering if PPO isn't the right algorithm for this? Wouldn't it be quite unlikely that a series of stochastic actions would keep the plane flying for so long? And even if that were possible, the clipping and learning rate almost guarantees that the network wouldn't learn immediately from a single successful run no? $\endgroup$ Nov 10, 2021 at 20:23
  • $\begingroup$ @james Have you tried adjusting the learning rate? If it works on cartpole it should probably work on your problem, unless your problem is significantly more difficult. $\endgroup$
    – Taw
    Nov 10, 2021 at 22:07
  • $\begingroup$ Yes I've tried tuning the learning rate, but I get a similar score history, where the network appears to be learning sporadically for a few episodes at a time before performance once again plummets. I'm thinking at this point that the stochastic nature of the action selection is hurting performance. The variance of the normal distribution from which the action is sampled is fixed, so if it is too large, it will explore but not consistently perform the "correct" action, while if too small, it will never explore. $\endgroup$ Nov 11, 2021 at 5:58
  • $\begingroup$ Have you tried tuning the variance? You can also predict the variance the same way you predict the mean. $\endgroup$
    – Taw
    Nov 11, 2021 at 17:06
  • $\begingroup$ Ah I see. You mean make the variance an output as well. I think that might be a good idea, because as I understand, the exploratory part of the model comes from the variance, and I'm finding that the model isn't exploring enough and becomes stuck at local minima. $\endgroup$ Nov 11, 2021 at 19:37

A different, variable reward structure might help. You could try a combination of airspeed, pitch, roll and whether it is hovering in the air or not in each timestep as a representation for the reward.

Maybe airspeed should, in expectation, contribute up to 30% of the reward, pitch up to 15%, roll up to 15% and being in the air up to 40%. This would explicitly reward motion, trying new movements as well as being reasonable, i.e. hovering in the air. You can create a new formula for the reward around this premise, even use some logarithms or other fancy functions that you see fit.

The important thing is that this way, the reward in each timestep is varying based on the four aforementioned variables and the chosen formula. It is not 0 or 1 like your previous structures. There is also feedback in each timestep on what it is doing right and how well it is doing, not just the last timestep like the second structure.

  • $\begingroup$ I see. I'll try implementing a more detailed reward structure then. I've been running the algorithm for 10 000 - 100 000 simulations. Would that typically be enough for a control problem like this? $\endgroup$ Nov 16, 2021 at 2:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .