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

Training does not give the expected result

Open satansama6 opened this issue 8 years ago • 7 comments

Hi. I am trying to create an agent that stops a ball from falling down the platform, but for some reason even after 2 million training steps it does nothing then random moving around and hitting the ball sometimes. If any of you did something similar please share your findings with me. image

In collectstate I add the velocity of the ball and the agent, the position relative to the platform for both, and the distance between them. My reward increases in every step with 0.005 and if the ball/cube falls down the platform I just simply give a negative reward. In case the ball stops reward is 1.

Here is the code in case anyone wants to check it: https://pastebin.com/YRFyAhns And my PPO settings. screenshot-2017-12-19 ppo

Can this even be learned this way? Or i need to change up everything? If someone can point me out my errors or point me in the right direction I would be glad. Thank you!

satansama6 avatar Dec 19 '17 06:12 satansama6

How far apart apart are the objects that you're sending relative position data from? Best practice is to normalise these inputs by e.g. dividing them with the max distance.

mikaisomaa avatar Dec 19 '17 10:12 mikaisomaa

Well the middle point is 0,0 and the platform size is 25,25. So from -12.5 to 12.5 in both directions. Could this be the problem? I will try out this suggestion and report back. Thank you

satansama6 avatar Dec 19 '17 11:12 satansama6

I tried dividing with the max value, but that does not seem to help at all. It does the same thing, Mean reward increases from -0.8 to 0.1 and it does not want to improve from there. Could the problem be with the rewards i'm giving?

satansama6 avatar Dec 19 '17 12:12 satansama6

Try measuring the distance for each frame and whenever the distance gets shorter - give the agent a small reward. Also give it a small reward whenever the velocity of the ball gets significantly lower. I would also use reward += rather than reward = in case you might have any concurrent rewards being given so that the current reward doesn't get wiped out.

mikaisomaa avatar Dec 19 '17 13:12 mikaisomaa

I will update the script and run the simulation again. How can i add a small reward based on the distance between them? Something like 1/DISTANCE*0.001 is okay? So the smaller the distance the larger the reward.

satansama6 avatar Dec 19 '17 13:12 satansama6

I added the + sing and now i get this error randomly after 5000-37500 steps:

TypeError Traceback (most recent call last) in () 56 info = env.reset(train_mode=train_model, progress=get_progress())[brain_name] 57 # Decide and take an action ---> 58 new_info = trainer.take_action(info, env, brain_name, steps, normalize) 59 info = new_info 60 trainer.process_experiences(info, time_horizon, gamma, lambd)

G:\unity\2D platformer\python\ppo\trainer.py in take_action(self, info, env, brain_name, steps, normalize) 74 self.stats['learning_rate'].append(learn_rate) 75 new_info = env.step(actions, value={brain_name: value})[brain_name] ---> 76 self.add_experiences(info, new_info, epsi, actions, a_dist, value) 77 return new_info 78

G:\unity\2D platformer\python\ppo\trainer.py in add_experiences(self, info, next_info, epsi, actions, a_dist, value) 101 history['action_probs'].append(a_dist[idx]) 102 history['value_estimates'].append(value[idx][0]) --> 103 history['cumulative_reward'] += next_info.rewards[idx] 104 history['episode_steps'] += 1 105

TypeError: unsupported operand type(s) for +=: 'int' and 'str'

EDIT: It was a math error in my code.

satansama6 avatar Dec 19 '17 14:12 satansama6

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 04 '20 21:01 lock[bot]