Cartpole gym spawn point

How can I change the initial spawn point on of the cartpole while resetting the environment? I have to use a custom reward in testing reward is like:

def new_reward(state, x0):
    s = state[0]
    theta = state[2]
    max_reward = 500
    min_reward = 0
    r_center = np.exp(-((s - x0) ** 2) / 0.5)
    r_angle = np.exp(-(theta ** 2) / 0.1)
    reward = r_center+0.5*r_angle

    return reward

However I'm not sure about this. Any advice? Also, x0 is the initial spawn point

I tried passing: --central_point 1.0, as it's 0.0 by default:

parser.add_argument("--central_point", type=float, default=None,
                        help="Point x0 to fluctuate around")

Also I tried changing it by hand:

def train(agent, env, train_episodes, early_stop=True, render=False,
          silent=False, train_run_id=0, x0=0.0, random_policy=False):

Or changing it after resetting:

observation = env.reset()
        x0  = 2

Upvotes: 0

Views: 19

Answers (0)

Related Questions