thomashirtz / gym-hybrid

Collection of OpenAI parametrized action-space environments.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Confusion about the implementation of accelerate method in SlidingAgent

Hcnaeg opened this issue · comments

Hello, I am kind of confused about the implementation of the accelerate method at here
According to the following formula from stackexchange (as mentioned in L58),
image
to calculate the magnitude of the sum of to polar vectors, we need to know the magnitudes and angles of these two polar vectors, and I think self.speed and speed represent the magnitudes, but I don't understand why they're used to calculate the cosine value by np.cos(value - self.speed) (instead of something represents the angle). By the way, I don't quite understand the way you simulate inertia, from my physics knowledge, it may be necessary to use some variables to represent the 'acceleration' or 'derivative' which specifies how fast the speed changes, am I right ?

Also, I wonder what does "direction of the agent" mean at here and what's the difference between "direction of the agent" and "angle of the velocity vector".

Your timely response will be greatly appreciated.

You are right, there seems to be an issue with the magnitude, and apparently the angle too, self.theta + self.phi*np.cos(self.phi - self.theta) seems wrong as well.

I started to do research on hybrid agent, I changed topic before even finishing this piece of code, I still finished it and released it as I thought it would be useful for some people, however this environment was not fully tested.

As I remember, the inertia was managed by basically increase the speed by a certain amount, during one timestep (because "acceleration = delta(speed) / delta(time)" and delta t in our case is one timestep).

self.speed += value

I assumed that the agent has a speed towards phi and a speed of "acceleration" (that lasts only one timestep) towards theta (the value of the speed is equal to the acceleration for the same reason I explained in the previous paragraph). I will correct the two equations when I have time, however if you find some better way to handle that I would be please to hear it.

Theta is the angle of the agent with the board as reference. It means that the agent is pointing towards theta. However the velocity vector is pointing towards phi. (this means that if we accelerate, we accelerate in the direction of the agent (theta) and not the direction of the existing velocity (phi))

Now that I reread my code, your question and my answer, it is possible that I am missing a delta_t where I am accelerating (but not sure sure, I think some tests may need to be written to see how much acceleration is provided if doing so, maybe too much or too little). Would it be possible to do a MR or send me a message with the changes that you think are right, so I can review it thereafter ? I currently do not have much time to take care of this

Thanks a lot for your explanation, I may think of a way to fix this issue and contact you later.

I think I fixed the magnitude and the angle using the equation from stackoverflow. I will write tests when more time will be in my hand. Please let me know if you found further adjustments to make.