Use same scenarios for training multiple times

Hi,
Currently it seems that all scenarios which are generated here are just used once for training in train_model.py. Is that correct?

Is there any hyperparameter to choose the number of times the scenarios are repeated?

Apologies if it is already documented but I could not find it anywhere in the available documentations.

Regards
Shivesh

Found the issue. I misunderstood what was happening in the tutorials.

Also for anyone else looking for how to change this behaviour, the CommonroadEnv class in commonroad_env.py has a variable play. If play is True, then the scenarios are not reused and vice versa. By default it is False. So scenarios are getting reused by default.

Hi,

sorry for the late response. Yes, exactly. By default, sceanrios are used multiple times during training. However, one cannot specify how many times a scenario is repeated since they are randomly selected from a list.

Best,
Xiao

Thank you for the clarification. I have another doubt, shouldn’t self.navigator be also set to None in here. Otherwise the route planner doesnt seem to get reset for each scenario because of this

Also I think what was intended here was that the reference points should be in the ego-vehicle’s frame. But what _rotate_2darray_by_orientation instead does is rotates the reference point again by the vehicle’s orientation. But shouldn’t we rotate it by the negative of ego-vehicle orientation? I think we should pass -orientation_ego here instead of orientation_ego.

Hi,

Yes, you are right. Here it should be self.navigator = None instead of self.goal_observation.navigator = None.

Best,
Xiao

@shiveshkhaitan I implemented the _rotate_2darray_by_orientation function in the navigator. The idea was indeed to bring the waypoints and orientations in the ego-vehicle’s frame.
I am not sure, whether the -orientation_ego should be passed, since when we render the observations not in the ego-vehicle’s (i.e. we don’t use the _rotate_2darray_by_orientation, when rendering out the waypoint) . However, you should be able to see the waypoints plotted with the render() option in the global frame.
How to test:

  • Maybe you could render the observations in the ego_vehicle frame?

@michaelf Thank you for looking into this. I have tried to put my reasoning of using -orientation in the picture below

You are right in some way, we multiple the rotation matrix in your way. (rot_matrix @ twodim_array.T).T see:

However, I designed the rot_matrix incorrectly is guess rot_matrix = np.array([[c, s], [-s, c]]).T . Therefore the result should be the same, right?

For training a RL model, there should be no difference, since the two observations are just swapped.

I think the observations are swapped just in this case because of the symmetry of the example I took. But if we have an asymmetric case (e.g. orientation = 40 degree and initial point in cartesian coordinate = [1, 2]), then the result is not just swapped but the values are different altogether

Correct me If I am wrong, but because the in here, the rot_matrix is defined as rot_matrix = np.array([[c, s], [-s, c]]) and not rot_matrix = np.array([[c, -s], [s, c]]) and sin(x) = - sin(x), the code works the intended way. Maybe makes still sense to pass -orientation by default and swap the rotation_matrix, but the result is the same, right?

No, I don’t think the results are same. I will try to explain again. So you defined the rotation matrix as:

rot_matrix = np.array([[c, s], [-s, c]]).T

which is equivalent to: rot_matrix = np.array([[c, -s], [s, c]])

So there is no problem in the rotation matrix itself. The definition of rotation matrix is correct in the code.

But when we want to project a point in the cartesian coordinate into the ego-vehicle’s frame, the result is different if we use orientation instead of -orientation. In the code, orientation has been used, but I think it should be -orientation. The final vector which we get using orientation and -orientation are not the same.

For e.g. let’s say initial point = [1, 2]
Ego-orientation = 40 degrees

Rotation matrix using 40 degrees = array([[ 0.76604444, -0.64278761], [ 0.64278761, 0.76604444]])
Rotated vector using this matrix = array([-0.51953078, 2.1748765 ])

Rotation matrix using -40 degrees = array([[ 0.76604444, 0.64278761], [ -0.64278761, 0.76604444]])
Rotated vector using this matrix = array([2.05161966, 0.88930128])

So the final rotated vectors which we get using orientation and -orientation are different. And the answer from -orientation looks correct.

Okay, I also build some code to test it against:

array = np.array([[1.5,0.9]])
orient = 0.54 
# radians, ~30,9 deg.
# point x=1.5,y=0.9 is exactly at 30.9 deg, 
# desired = np.array([[sqrt((1.5**2)+(0.9**2)),0.])
x_desired = np.array([[((1.5**2)+(0.9**2))**0.5,0.]])

x_negative = _rotate_2darray_by_orientation(-orient, array)[0]
x_positive= _rotate_2darray_by_orientation(orient, array)[0]

print(f"{x_negative}\n{x_positive}\n{x_desired}" )

x_negative seems to be right.

It might be best to remove the:

  • np.array([[c, s], [-s, c]]).T to np.array([[c, -s], [s, c]])
  • change to -orientation
  • adapt test cases