5 (4)

5 (4)

#### Overview of this book

Welcome to the Robot World … and start building intelligent software now! Through his best-selling video courses, Hadelin de Ponteves has taught hundreds of thousands of people to write AI software. Now, for the first time, his hands-on, energetic approach is available as a book. Starting with the basics before easing you into more complicated formulas and notation, AI Crash Course gives you everything you need to build AI systems with reinforcement learning and deep learning. Five full working projects put the ideas into action, showing step-by-step how to build intelligent software using the best and easiest tools for AI programming, including Python, TensorFlow, Keras, and PyTorch. AI Crash Course teaches everyone to build an AI to work in their applications. Once you've read this book, you're only limited by your imagination.
Preface
Free Chapter
Welcome to the Robot World
Python Fundamentals – Learn How to Code in Python
AI Foundation Techniques
Your First AI Model – Beware the Bandits!
AI for Sales and Advertising – Sell like the Wolf of AI Street
Welcome to Q-Learning
AI for Logistics – Robots in a Warehouse
Going Pro with Artificial Brains – Deep Q-Learning
AI for Autonomous Vehicles – Build a Self-Driving Car
AI for Business – Minimize Costs with Deep Q-Learning
Deep Convolutional Q-Learning
AI for Games – Become the Master at Snake
Recap and Conclusion
Other Books You May Enjoy
Index

# Building the environment

When building an AI, the first thing we always have to do is define the environment. Defining an environment always requires the following three elements:

• Defining the states
• Defining the actions
• Defining the rewards

These three elements have already been defined in the previous chapter on Q-learning, but let's quickly remind ourselves what they are.

## The states

The state, at a specific time t, is the location where the robot is at that time t. However, remember, you have to encode the location names so that our AI can do the math.

At the risk of disappointing you, given all the crazy hype about AI, let's remain realistic and understand that Q-learning is nothing more than a bunch of math equations; just like any other AI model. Let's make the encoding integers start at 0, simply because indexes in Python start at 0:

Figure 5: Location to state mapping

## The actions

The actions are the next possible...