O'Reilly logo

Artificial Intelligence with Python by Prateek Joshi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Building a learning agent

Let's see how to build a learning agent that can achieve a goal. The learning agent will learn how to achieve a goal. Create a new python file and import the following package:

import argparse 
 
import gym 

Define a function to parse the input arguments:

def build_arg_parser(): 
    parser = argparse.ArgumentParser(description='Run an environment') 
    parser.add_argument('--input-env', dest='input_env', required=True, 
            choices=['cartpole', 'mountaincar', 'pendulum'],  
            help='Specify the name of the environment') 
    return parser 

Parse the input arguments:

if __name__=='__main__': 
    args = build_arg_parser().parse_args() 
    input_env = args.input_env 

Build a mapping from the input arguments to the names of the environments in the OpenAI Gym package: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required