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

When to Add reward

Open tanakataiki4 opened this issue 8 years ago • 9 comments

@awjuliani Thanks for a good repo https://github.com/Unity-Technologies/ml-agents/blob/d6dad11c773a8598540a8896d0d48b2489b222ae/UnitySDK/Assets/ML-Agents/Examples/Walker/Scripts/WalkerAgent.cs#L143

in this code reward is added at every step but Action and observation is done at N decision step. so is this better (more acurate)than adding reward at every decision step?

tanakataiki4 avatar Nov 12 '18 05:11 tanakataiki4

The reward is only sent during the decision step. The rewards added between decisions is added up. Since we reward the Walker for its orientation speed, we cannot just add a reward at the decision step (intermediate steps count as well). I hope this helps.

vincentpierre avatar Nov 12 '18 18:11 vincentpierre

@vincentpierre Thanks, I understand that case. If the reward accumulate before decision then the amount of reward exceeds 1(recommended to set as maximum value) right?doesn't this cause issues?

And if I add reward only at decision step the reward is obviously less than add every step but does this still work fine?

tanakataiki4 avatar Nov 13 '18 00:11 tanakataiki4

The limit of 1 is not a hard limit. We advise people to keep the rewards to small values. I do not think the Walker's rewards go above 1, if they do, probably not by much. Very large rewards are know to cause issues (10 or 100 would probably break something). The problem with only adding at the decision step is that the agent could be incentivized to only maximize the reward at the decision step. For instance, slow down when the reward is not added and accelerate when the reward is about the be calculated. I do not know what would happen, I think you could try it and see if it fits your case.

vincentpierre avatar Nov 13 '18 17:11 vincentpierre

@vincentpierre Thanks. Then Does ppo net work consider step size of action not only at decision step that accumulates reward and states?

tanakataiki4 avatar Nov 15 '18 01:11 tanakataiki4

PPO only receives a signal when a decision is requested, not at every step. The reward ppo receives at each decision is the sum of the rewards that were added at each step between decisions.

decision request
 step - AddReward(0.2f)
 step - AddReward(0.2f)
 step - AddReward(0.2f)
decision request -> PPO receives 0.6 reward
 step - AddReward(0.2f)
 step - AddReward(0.2f)
 step - AddReward(0.2f)
decision request -> PPO receives 0.6 reward
...

vincentpierre avatar Nov 15 '18 03:11 vincentpierre

@vincentpierre Got it. Thanks a lot

tanakataiki4 avatar Nov 15 '18 05:11 tanakataiki4

One question depending the reward adding. I added a reward of -0.001 as exploration incentive. But somehow this seems to be not accepted as a reward, because if you write the CumultativeReward into a text field it doesn't change with such a low reward. With hundredths it's working but not with a thousandths, is this correct?

KReguieg avatar May 23 '19 09:05 KReguieg

The reward is using floating points, rewards of a thousandths should work. It might be truncation in the to string method (try to multiply by 1000 and see if this number is changing) You could also be overwriting your reward with a SetReward call.

vincentpierre avatar May 23 '19 18:05 vincentpierre

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.

github-actions[bot] avatar Jan 31 '21 16:01 github-actions[bot]