.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/example_mountain_car.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_example_mountain_car.py: Example: Solving an OpenAI Gym environment with CGP. ==================================================== This examples demonstrates how to solve an OpenAI Gym environment (https://gym.openai.com/envs/) with Cartesian genetic programming. We choose the "MountainCarContinuous" environment due to its continuous observation and action spaces. Preparatory steps: Install the OpenAI Gym package: `pip install gym` .. GENERATED FROM PYTHON SOURCE LINES 14-47 .. code-block:: default # The docopt str is added explicitly to ensure compatibility with # sphinx-gallery. docopt_str = """ Usage: example_parametrized_nodes.py [--max-generations=] [--visualize-final-champion] Options: -h --help --max-generations= Maximum number of generations [default: 1500] --visualize-final-champion Create animation of final champion in the mountain car env. """ import functools import warnings import matplotlib.pyplot as plt import numpy as np import sympy from docopt import docopt import cgp try: import gym except ImportError: raise ImportError( "Failed to import the OpenAI Gym package. Please install it via `pip install gym`." ) args = docopt(docopt_str) .. GENERATED FROM PYTHON SOURCE LINES 48-51 For more flexibility in the evolved expressions, we define two constants that can be used in the expressions, with values 0.1 and 10. .. GENERATED FROM PYTHON SOURCE LINES 51-61 .. code-block:: default class ConstantFloatZeroPointOne(cgp.ConstantFloat): _def_output = "0.1" class ConstantFloatTen(cgp.ConstantFloat): _def_output = "10.0" .. GENERATED FROM PYTHON SOURCE LINES 62-68 Then we define the objective function for the evolution. The inner objective accepts a Python callable as input. This callable determines the action taken by the agent upon receiving observations from the environment. The fitness of the given callable on the task is then computed as the cumulative reward over a fixed number of episodes. .. GENERATED FROM PYTHON SOURCE LINES 68-100 .. code-block:: default def inner_objective(f, seed, n_runs_per_individual, n_total_steps, *, render): env = gym.make("MountainCarContinuous-v0") env.seed(seed) cum_reward_all_episodes = [] for _ in range(n_runs_per_individual): observation = env.reset() cum_reward_this_episode = 0 for _ in range(n_total_steps): if render: env.render() continuous_action = f(*observation) observation, reward, done, _ = env.step([continuous_action]) cum_reward_this_episode += reward if done: cum_reward_all_episodes.append(cum_reward_this_episode) cum_reward_this_episode = 0 observation = env.reset() env.close() return cum_reward_all_episodes .. GENERATED FROM PYTHON SOURCE LINES 101-105 The objective then takes an individual, evaluates the inner objective, and updates the fitness of the individual. If the expression of the individual leads to a division by zero, this error is caught and the individual gets a fitness of -infinity assigned. .. GENERATED FROM PYTHON SOURCE LINES 105-136 .. code-block:: default def objective(ind, seed, n_runs_per_individual, n_total_steps): if not ind.fitness_is_None(): return ind f = ind.to_func() try: with warnings.catch_warnings(): # ignore warnings due to zero division warnings.filterwarnings( "ignore", message="divide by zero encountered in double_scalars" ) warnings.filterwarnings( "ignore", message="invalid value encountered in double_scalars" ) cum_reward_all_episodes = inner_objective( f, seed, n_runs_per_individual, n_total_steps, render=False ) # more episodes are better, more reward is better n_episodes = float(len(cum_reward_all_episodes)) mean_cum_reward = np.mean(cum_reward_all_episodes) ind.fitness = n_episodes / n_runs_per_individual + mean_cum_reward except ZeroDivisionError: ind.fitness = -np.inf return ind .. GENERATED FROM PYTHON SOURCE LINES 137-144 We then define the main loop for the evolution, which consists of: - parameters for the population, the genome of individuals, and the evolutionary algorithm. - creating a Population instance and instantiating the evolutionary algorithm. - defining a recording callback closure for bookkeeping of the progression of the evolution. Finally, we call the `evolve` method to perform the evolutionary search. .. GENERATED FROM PYTHON SOURCE LINES 144-200 .. code-block:: default def evolve(seed): objective_params = {"n_runs_per_individual": 3, "n_total_steps": 2000} population_params = {"n_parents": 1, "seed": seed} genome_params = { "n_inputs": 2, "n_outputs": 1, "n_columns": 16, "n_rows": 1, "levels_back": None, "primitives": ( cgp.Add, cgp.Sub, cgp.Mul, cgp.Div, cgp.ConstantFloat, ConstantFloatZeroPointOne, ConstantFloatTen, ), } ea_params = {"n_offsprings": 4, "tournament_size": 1, "mutation_rate": 0.04, "n_processes": 4} evolve_params = { "max_generations": int(args["--max-generations"]), "termination_fitness": 100.0, } pop = cgp.Population(**population_params, genome_params=genome_params) ea = cgp.ea.MuPlusLambda(**ea_params) history = {} history["expr_champion"] = [] history["fitness_champion"] = [] def recording_callback(pop): history["expr_champion"].append(pop.champion.to_sympy()) history["fitness_champion"].append(pop.champion.fitness) obj = functools.partial( objective, seed=seed, n_runs_per_individual=objective_params["n_runs_per_individual"], n_total_steps=objective_params["n_total_steps"], ) cgp.evolve(pop, obj, ea, **evolve_params, print_progress=True, callback=recording_callback) return history, pop.champion .. GENERATED FROM PYTHON SOURCE LINES 201-202 For visualization, we define a function to plot the fitness over generations. .. GENERATED FROM PYTHON SOURCE LINES 202-214 .. code-block:: default def plot_fitness_over_generation_index(history): width = 6.0 fig = plt.figure(figsize=(width, width / 1.618)) ax = fig.add_axes([0.15, 0.15, 0.8, 0.8]) ax.set_xlabel("Generation index") ax.set_ylabel("Fitness champion") ax.plot(history["fitness_champion"]) fig.savefig("example_mountain_car.png", dpi=300) .. GENERATED FROM PYTHON SOURCE LINES 215-219 We define a function that checks whether the best expression fulfills the "solving criteria", i.e., average reward of at least 90.0 over 100 consecutive trials. (https://github.com/openai/gym/wiki/Leaderboard#mountaincarcontinuous-v0) .. GENERATED FROM PYTHON SOURCE LINES 219-255 .. code-block:: default def evaluate_champion(ind): env = gym.make("MountainCarContinuous-v0") env.seed(seed) observation = env.reset() f = ind.to_func() cum_reward_all_episodes = [] cum_reward_this_episode = 0 while len(cum_reward_all_episodes) < 100: continuous_action = f(*observation) observation, reward, done, _ = env.step([continuous_action]) cum_reward_this_episode += reward if done: cum_reward_all_episodes.append(cum_reward_this_episode) cum_reward_this_episode = 0 observation = env.reset() env.close() cum_reward_average = np.mean(cum_reward_all_episodes) print(f"average reward over 100 consecutive trials: {cum_reward_average:.05f}", end="") if cum_reward_average >= 90.0: print("-> environment solved!") else: print() return cum_reward_all_episodes .. GENERATED FROM PYTHON SOURCE LINES 256-258 Furthermore, we define a function for visualizing the agent's behaviour for each expression that increase over the currently best performing individual. .. GENERATED FROM PYTHON SOURCE LINES 258-287 .. code-block:: default def visualize_behaviour_for_evolutionary_jumps(seed, history, only_final_solution=True): n_runs_per_individual = 1 n_total_steps = 999 max_fitness = -np.inf for i, fitness in enumerate(history["fitness_champion"]): if only_final_solution and i != (len(history["fitness_champion"]) - 1): continue if fitness > max_fitness: expr = history["expr_champion"][i][0] expr_str = str(expr).replace("x_0", "x").replace("x_1", "dx/dt") print(f'visualizing behaviour for expression "{expr_str}" (fitness: {fitness:.05f})') x_0, x_1 = sympy.symbols("x_0, x_1") f_lambdify = sympy.lambdify([x_0, x_1], expr) def f(x): return [f_lambdify(x[0], x[1])] inner_objective(f, seed, n_runs_per_individual, n_total_steps, render=True) max_fitness = fitness .. GENERATED FROM PYTHON SOURCE LINES 288-291 Finally, we execute the evolution and visualize the results. To animate the behavior of the car for the found expression, uncomment the last line of the example. .. GENERATED FROM PYTHON SOURCE LINES 291-310 .. code-block:: default if __name__ == "__main__": seed = 818821 print("starting evolution") history, champion = evolve(seed) print("evolution ended") max_fitness = history["fitness_champion"][-1] best_expr = history["expr_champion"][-1] best_expr_str = str(best_expr).replace("x_0", "x").replace("x_1", "dx/dt") print(f'solution with highest fitness: "{best_expr_str}" (fitness: {max_fitness:.05f})') plot_fitness_over_generation_index(history) evaluate_champion(champion) if args["--visualize-final-champion"]: visualize_behaviour_for_evolutionary_jumps(seed, history) .. image:: /auto_examples/images/sphx_glr_example_mountain_car_001.png :alt: example mountain car :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none starting evolution [2/1500] max fitness: -97.8999999999986 [3/1500] max fitness: -97.8999999999986 [4/1500] max fitness: -97.8999999999986 [5/1500] max fitness: -97.8999999999986 [6/1500] max fitness: -97.8999999999986 [7/1500] max fitness: -97.8999999999986 [8/1500] max fitness: -97.8999999999986 [9/1500] max fitness: -97.8999999999986 [10/1500] max fitness: -97.8999999999986 [11/1500] max fitness: -51.477965251020066 [12/1500] max fitness: -51.477965251020066 [13/1500] max fitness: -51.477965251020066 [14/1500] max fitness: -51.477965251020066 [15/1500] max fitness: -51.477965251020066 [16/1500] max fitness: -51.477965251020066 [17/1500] max fitness: -51.477965251020066 [18/1500] max fitness: 1.9996849395480436 [19/1500] max fitness: 1.9996849395480436 [20/1500] max fitness: 1.9996849395480436 [21/1500] max fitness: 1.9996849395480436 [22/1500] max fitness: 1.9996849395480436 [23/1500] max fitness: 1.9996849395480436 [24/1500] max fitness: 1.9996849395480436 [25/1500] max fitness: 1.9996849395480436 [26/1500] max fitness: 1.9996849395480436 [27/1500] max fitness: 1.9996849395480436 [28/1500] max fitness: 1.9996849395480436 [29/1500] max fitness: 1.9996849395480436 [30/1500] max fitness: 1.9996849395480436 [31/1500] max fitness: 1.9996849395480436 [32/1500] max fitness: 1.9996849395480436 [33/1500] max fitness: 1.9996849395480436 [34/1500] max fitness: 1.9999999206327992 [35/1500] max fitness: 1.9999999206327992 [36/1500] max fitness: 1.9999999206327992 [37/1500] max fitness: 1.9999999206327992 [38/1500] max fitness: 1.9999999206327992 [39/1500] max fitness: 1.9999999206327992 [40/1500] max fitness: 1.9999999206327992 [41/1500] max fitness: 1.9999999206327992 [42/1500] max fitness: 1.9999999206327992 [43/1500] max fitness: 1.9999999206327992 [44/1500] max fitness: 1.9999999206327992 [45/1500] max fitness: 1.9999999206327992 [46/1500] max fitness: 1.9999999206327992 [47/1500] max fitness: 1.9999999206327992 [48/1500] max fitness: 1.9999999206327992 [49/1500] max fitness: 1.9999999206327992 [50/1500] max fitness: 1.9999999206327992 [51/1500] max fitness: 1.9999999206327992 [52/1500] max fitness: 1.9999999206327992 [53/1500] max fitness: 2.0 [54/1500] max fitness: 2.0 [55/1500] max fitness: 2.0 [56/1500] max fitness: 2.0 [57/1500] max fitness: 2.0 [58/1500] max fitness: 2.0 [59/1500] max fitness: 2.0 [60/1500] max fitness: 2.0 [61/1500] max fitness: 2.0 [62/1500] max fitness: 2.0 [63/1500] max fitness: 2.0 [64/1500] max fitness: 2.0 [65/1500] max fitness: 2.0 [66/1500] max fitness: 2.0 [67/1500] max fitness: 2.0 [68/1500] max fitness: 2.0 [69/1500] max fitness: 2.0 [70/1500] max fitness: 2.0 [71/1500] max fitness: 2.0 [72/1500] max fitness: 2.0 [73/1500] max fitness: 2.0 [74/1500] max fitness: 2.0 [75/1500] max fitness: 2.0 [76/1500] max fitness: 2.0 [77/1500] max fitness: 2.0 [78/1500] max fitness: 2.0 [79/1500] max fitness: 2.0 [80/1500] max fitness: 2.0 [81/1500] max fitness: 2.0 [82/1500] max fitness: 2.0 [83/1500] max fitness: 2.0 [84/1500] max fitness: 2.0 [85/1500] max fitness: 2.0 [86/1500] max fitness: 2.0 [87/1500] max fitness: 2.0 [88/1500] max fitness: 2.0 [89/1500] max fitness: 2.0 [90/1500] max fitness: 2.0 [91/1500] max fitness: 2.0 [92/1500] max fitness: 2.0 [93/1500] max fitness: 2.0 [94/1500] max fitness: 2.0 [95/1500] max fitness: 2.0 [96/1500] max fitness: 2.0 [97/1500] max fitness: 2.0 [98/1500] max fitness: 2.0 [99/1500] max fitness: 2.0 [100/1500] max fitness: 2.0 [101/1500] max fitness: 2.0 [102/1500] max fitness: 2.0 [103/1500] max fitness: 2.0 [104/1500] max fitness: 2.0 [105/1500] max fitness: 2.0 [106/1500] max fitness: 2.0 [107/1500] max fitness: 2.0 [108/1500] max fitness: 2.0 [109/1500] max fitness: 2.0 [110/1500] max fitness: 2.0 [111/1500] max fitness: 2.0 [112/1500] max fitness: 2.0 [113/1500] max fitness: 2.0 [114/1500] max fitness: 2.0 [115/1500] max fitness: 2.0 [116/1500] max fitness: 2.0 [117/1500] max fitness: 2.0 [118/1500] max fitness: 2.0 [119/1500] max fitness: 2.0 [120/1500] max fitness: 2.0 [121/1500] max fitness: 2.0 [122/1500] max fitness: 2.0 [123/1500] max fitness: 2.0 [124/1500] max fitness: 2.0 [125/1500] max fitness: 2.0 [126/1500] max fitness: 2.0 [127/1500] max fitness: 2.0 [128/1500] max fitness: 2.0 [129/1500] max fitness: 2.0 [130/1500] max fitness: 2.0 [131/1500] max fitness: 2.0 [132/1500] max fitness: 2.0 [133/1500] max fitness: 2.0 [134/1500] max fitness: 2.0 [135/1500] max fitness: 2.0 [136/1500] max fitness: 2.0 [137/1500] max fitness: 2.0 [138/1500] max fitness: 2.0 [139/1500] max fitness: 2.0 [140/1500] max fitness: 2.0 [141/1500] max fitness: 2.0 [142/1500] max fitness: 2.0 [143/1500] max fitness: 2.0 [144/1500] max fitness: 2.0 [145/1500] max fitness: 2.0 [146/1500] max fitness: 2.0 [147/1500] max fitness: 2.0 [148/1500] max fitness: 2.0 [149/1500] max fitness: 2.0 [150/1500] max fitness: 2.0 [151/1500] max fitness: 2.0 [152/1500] max fitness: 2.0 [153/1500] max fitness: 2.0 [154/1500] max fitness: 2.0 [155/1500] max fitness: 2.0 [156/1500] max fitness: 2.0 [157/1500] max fitness: 2.0 [158/1500] max fitness: 2.0 [159/1500] max fitness: 2.0 [160/1500] max fitness: 2.0 [161/1500] max fitness: 2.0 [162/1500] max fitness: 2.0 [163/1500] max fitness: 2.0 [164/1500] max fitness: 2.0 [165/1500] max fitness: 2.0 [166/1500] max fitness: 2.0 [167/1500] max fitness: 2.0 [168/1500] max fitness: 2.0 [169/1500] max fitness: 2.0 [170/1500] max fitness: 2.0 [171/1500] max fitness: 2.0 [172/1500] max fitness: 2.0 [173/1500] max fitness: 2.0 [174/1500] max fitness: 2.0 [175/1500] max fitness: 2.0 [176/1500] max fitness: 2.0 [177/1500] max fitness: 2.0 [178/1500] max fitness: 2.0 [179/1500] max fitness: 2.0 [180/1500] max fitness: 2.0 [181/1500] max fitness: 2.0 [182/1500] max fitness: 2.0 [183/1500] max fitness: 2.0 [184/1500] max fitness: 2.0 [185/1500] max fitness: 2.0 [186/1500] max fitness: 2.0 [187/1500] max fitness: 2.0 [188/1500] max fitness: 2.0 [189/1500] max fitness: 2.0 [190/1500] max fitness: 2.0 [191/1500] max fitness: 2.0 [192/1500] max fitness: 2.0 [193/1500] max fitness: 2.0 [194/1500] max fitness: 2.0 [195/1500] max fitness: 2.0 [196/1500] max fitness: 2.0 [197/1500] max fitness: 2.0 [198/1500] max fitness: 2.0 [199/1500] max fitness: 2.0 [200/1500] max fitness: 2.0 [201/1500] max fitness: 2.0 [202/1500] max fitness: 2.0 [203/1500] max fitness: 2.0 [204/1500] max fitness: 2.0 [205/1500] max fitness: 2.0 [206/1500] max fitness: 2.0 [207/1500] max fitness: 2.0 [208/1500] max fitness: 2.0 [209/1500] max fitness: 2.0 [210/1500] max fitness: 2.0 [211/1500] max fitness: 2.0 [212/1500] max fitness: 2.0 [213/1500] max fitness: 2.0 [214/1500] max fitness: 2.0 [215/1500] max fitness: 2.0 [216/1500] max fitness: 2.0 [217/1500] max fitness: 2.0 [218/1500] max fitness: 2.0 [219/1500] max fitness: 2.0 [220/1500] max fitness: 2.0 [221/1500] max fitness: 2.0 [222/1500] max fitness: 2.0 [223/1500] max fitness: 2.0 [224/1500] max fitness: 2.0 [225/1500] max fitness: 2.0 [226/1500] max fitness: 2.0 [227/1500] max fitness: 2.0 [228/1500] max fitness: 2.0 [229/1500] max fitness: 2.0 [230/1500] max fitness: 2.0 [231/1500] max fitness: 2.0 [232/1500] max fitness: 2.0 [233/1500] max fitness: 2.0 [234/1500] max fitness: 2.0 [235/1500] max fitness: 2.0 [236/1500] max fitness: 2.0 [237/1500] max fitness: 2.0 [238/1500] max fitness: 2.0 [239/1500] max fitness: 2.0 [240/1500] max fitness: 2.0 [241/1500] max fitness: 2.0 [242/1500] max fitness: 2.0 [243/1500] max fitness: 2.0 [244/1500] max fitness: 2.0 [245/1500] max fitness: 2.0 [246/1500] max fitness: 2.0 [247/1500] max fitness: 2.0 [248/1500] max fitness: 2.0 [249/1500] max fitness: 2.0 [250/1500] max fitness: 2.0 [251/1500] max fitness: 2.0 [252/1500] max fitness: 2.0 [253/1500] max fitness: 2.0 [254/1500] max fitness: 2.0 [255/1500] max fitness: 2.0 [256/1500] max fitness: 2.0 [257/1500] max fitness: 2.0 [258/1500] max fitness: 2.0 [259/1500] max fitness: 2.0 [260/1500] max fitness: 2.0 [261/1500] max fitness: 2.0 [262/1500] max fitness: 2.0 [263/1500] max fitness: 2.0 [264/1500] max fitness: 2.0 [265/1500] max fitness: 2.0 [266/1500] max fitness: 2.0 [267/1500] max fitness: 2.0 [268/1500] max fitness: 2.0 [269/1500] max fitness: 2.0 [270/1500] max fitness: 2.0 [271/1500] max fitness: 2.0 [272/1500] max fitness: 2.0 [273/1500] max fitness: 2.0 [274/1500] max fitness: 2.0 [275/1500] max fitness: 2.0 [276/1500] max fitness: 2.0 [277/1500] max fitness: 2.0 [278/1500] max fitness: 2.0 [279/1500] max fitness: 2.0 [280/1500] max fitness: 2.0 [281/1500] max fitness: 2.0 [282/1500] max fitness: 2.0 [283/1500] max fitness: 2.0 [284/1500] max fitness: 2.0 [285/1500] max fitness: 2.0 [286/1500] max fitness: 2.0 [287/1500] max fitness: 2.0 [288/1500] max fitness: 2.0 [289/1500] max fitness: 2.0 [290/1500] max fitness: 2.0 [291/1500] max fitness: 2.0 [292/1500] max fitness: 2.0 [293/1500] max fitness: 2.0 [294/1500] max fitness: 2.0 [295/1500] max fitness: 2.0 [296/1500] max fitness: 2.0 [297/1500] max fitness: 2.0 [298/1500] max fitness: 2.0 [299/1500] max fitness: 2.0 [300/1500] max fitness: 2.0 [301/1500] max fitness: 2.0 [302/1500] max fitness: 2.0 [303/1500] max fitness: 2.0 [304/1500] max fitness: 2.0 [305/1500] max fitness: 2.0 [306/1500] max fitness: 2.0 [307/1500] max fitness: 2.0 [308/1500] max fitness: 2.0 [309/1500] max fitness: 2.0 [310/1500] max fitness: 2.0 [311/1500] max fitness: 2.0 [312/1500] max fitness: 2.0 [313/1500] max fitness: 2.0 [314/1500] max fitness: 2.0 [315/1500] max fitness: 2.0 [316/1500] max fitness: 2.0 [317/1500] max fitness: 2.0 [318/1500] max fitness: 2.0 [319/1500] max fitness: 2.0 [320/1500] max fitness: 2.0 [321/1500] max fitness: 2.0 [322/1500] max fitness: 2.0 [323/1500] max fitness: 2.0 [324/1500] max fitness: 2.0 [325/1500] max fitness: 2.0 [326/1500] max fitness: 2.0 [327/1500] max fitness: 2.0 [328/1500] max fitness: 2.0 [329/1500] max fitness: 2.0 [330/1500] max fitness: 2.0 [331/1500] max fitness: 2.0 [332/1500] max fitness: 2.0 [333/1500] max fitness: 2.0 [334/1500] max fitness: 2.0 [335/1500] max fitness: 2.0 [336/1500] max fitness: 2.0 [337/1500] max fitness: 2.0 [338/1500] max fitness: 2.0 [339/1500] max fitness: 2.0 [340/1500] max fitness: 2.0 [341/1500] max fitness: 2.0 [342/1500] max fitness: 2.0 [343/1500] max fitness: 2.0 [344/1500] max fitness: 2.0 [345/1500] max fitness: 2.0 [346/1500] max fitness: 2.0 [347/1500] max fitness: 2.0 [348/1500] max fitness: 2.0 [349/1500] max fitness: 2.0 [350/1500] max fitness: 2.0 [351/1500] max fitness: 2.0 [352/1500] max fitness: 2.0 [353/1500] max fitness: 2.0 [354/1500] max fitness: 2.0 [355/1500] max fitness: 2.0 [356/1500] max fitness: 2.0 [357/1500] max fitness: 2.0 [358/1500] max fitness: 2.0 [359/1500] max fitness: 2.0 [360/1500] max fitness: 2.0 [361/1500] max fitness: 2.0 [362/1500] max fitness: 2.0 [363/1500] max fitness: 2.0 [364/1500] max fitness: 2.0 [365/1500] max fitness: 2.0 [366/1500] max fitness: 2.0 [367/1500] max fitness: 2.0 [368/1500] max fitness: 2.0 [369/1500] max fitness: 2.0 [370/1500] max fitness: 2.0 [371/1500] max fitness: 2.0 [372/1500] max fitness: 2.0 [373/1500] max fitness: 2.0 [374/1500] max fitness: 2.0 [375/1500] max fitness: 2.0 [376/1500] max fitness: 2.0 [377/1500] max fitness: 2.0 [378/1500] max fitness: 2.0 [379/1500] max fitness: 2.0 [380/1500] max fitness: 2.0 [381/1500] max fitness: 2.0 [382/1500] max fitness: 2.0 [383/1500] max fitness: 2.0 [384/1500] max fitness: 2.0 [385/1500] max fitness: 2.0 [386/1500] max fitness: 2.0 [387/1500] max fitness: 2.0 [388/1500] max fitness: 2.0 [389/1500] max fitness: 2.0 [390/1500] max fitness: 2.0 [391/1500] max fitness: 2.0 [392/1500] max fitness: 2.0 [393/1500] max fitness: 2.0 [394/1500] max fitness: 2.0 [395/1500] max fitness: 2.0 [396/1500] max fitness: 2.0 [397/1500] max fitness: 2.0 [398/1500] max fitness: 2.0 [399/1500] max fitness: 2.0 [400/1500] max fitness: 2.0 [401/1500] max fitness: 2.0 [402/1500] max fitness: 2.0/opt/hostedtoolcache/Python/3.8.10/x64/lib/python3.8/site-packages/numpy/lib/function_base.py:3942: RuntimeWarning: invalid value encountered in multiply x2 = take(ap, indices_above, axis=axis) * weights_above [403/1500] max fitness: 2.0 [404/1500] max fitness: 2.0 [405/1500] max fitness: 2.0 [406/1500] max fitness: 2.0 [407/1500] max fitness: 2.0 [408/1500] max fitness: 2.0 [409/1500] max fitness: 2.0 [410/1500] max fitness: 2.0 [411/1500] max fitness: 2.0 [412/1500] max fitness: 2.0 [413/1500] max fitness: 2.0 [414/1500] max fitness: 2.0 [415/1500] max fitness: 2.0 [416/1500] max fitness: 2.0 [417/1500] max fitness: 2.0 [418/1500] max fitness: 2.0 [419/1500] max fitness: 2.0 [420/1500] max fitness: 2.0 [421/1500] max fitness: 2.0 [422/1500] max fitness: 2.0 [423/1500] max fitness: 2.0 [424/1500] max fitness: 2.0 [425/1500] max fitness: 2.0 [426/1500] max fitness: 2.0 [427/1500] max fitness: 2.0 [428/1500] max fitness: 2.0 [429/1500] max fitness: 2.0 [430/1500] max fitness: 2.0 [431/1500] max fitness: 2.0 [432/1500] max fitness: 2.0 [433/1500] max fitness: 2.0 [434/1500] max fitness: 2.0 [435/1500] max fitness: 2.0 [436/1500] max fitness: 2.0 [437/1500] max fitness: 2.0 [438/1500] max fitness: 2.0 [439/1500] max fitness: 2.0 [440/1500] max fitness: 102.55337700605139 evolution ended solution with highest fitness: "9.0*dx/dt" (fitness: 102.55338) average reward over 100 consecutive trials: 96.41038-> environment solved! .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 18.822 seconds) .. _sphx_glr_download_auto_examples_example_mountain_car.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_mountain_car.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_mountain_car.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_