Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Learn Unity ML-Agents ??? Fundamentals of Unity Machine Learning
Learn Unity ML-Agents ??? Fundamentals of Unity Machine Learning

Learn Unity ML-Agents ??? Fundamentals of Unity Machine Learning: Incorporate new powerful ML algorithms such as Deep Reinforcement Learning for games

eBook
Can$12.99 Can$33.99
Paperback
Can$41.99
Subscription
Free Trial

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Learn Unity ML-Agents ??? Fundamentals of Unity Machine Learning

The Bandit and Reinforcement Learning

In the previous chapter, we introduced Machine Learning and the types of learning or training used in ML (Unsupervised Training, Supervised Training, Reinforcement Learning, Imitation Learning, and Curriculum Learning). As we discussed, the various forms of learning each have their own advantages and disadvantages. While ML using supervised training has been used successfully in games as far back as 20 years ago, it never really found any traction. It wasn't until the successful use of Reinforcement Learning was shown to be capable of playing classic Atari games and GO better than humans, that the interest for ML in games and simulations was rekindled. Now, RL is one of the hottest topics in ML research and is showing the potential for building some real continually learning AI. We will spend the bulk of this chapter understanding RL...

Reinforcement Learning

Reinforcement Learning is rooted in animal and behavioral psychology, where it is used in many applications of Machine Learning, from games and simulations to control optimization, information theory, statistics, and many more areas every day. RL, at its most basic level, describes an agent acting with an environment that receives either positive or negative rewards based on those actions. The following is a diagram showing the stateless RL model:



Stateless Reinforcement Learning

Conveniently, our multi-armed bandit problem we built in the last chapter fits well with this simpler form of RL. That problem only had a single state, or what we refer to as a one-step RL problem. Since the agent doesn't need to worry about state, we can greatly simplify our RL equations to just write the value of each action using the following equation:

Consider the following...

Contextual bandits and state

Our next step in understanding RL will be for us to look at the contextual bandit problem. A contextual bandit is the multi-armed bandit problem, with multiple bandits each producing different rewards. This type of problem has many applications in online advertising, where each user is thought of as a different bandit, with the goal being to present the best advertisement for that user. To model the context of the bandit, and which bandit it is, we add the concept of state. Where we now interpret state to represent each of our different bandits. The following diagram shows the addition of state in the Contextual Bandit problem and where it lies on our path to glory:



Stateless, Contextual and Full RL models

You can see in the preceding diagram that we now need to determine the state before evaluating an action. If you recall from earlier, the Value...

Exploration and exploitation

One of the dilemmas we face in RL is the balance between exploring all possible actions and exploiting the best possible action. In the multi-armed bandit problem, our search space was small enough to do this with brute force, essentially just by pulling each arm one by one. However, in more complex problems, the number of states could exceed the number of atoms in the known universe. Yes, you read that correctly. In those cases, we need to establish a policy or method whereby we can balance the exploration and exploitation dilemma. There are a few ways in which we can do this, and the following are the most common ways you can approach this:

  • Greedy Optimistic: The agent initially starts with high values in its q table. This forces the agent to explore all states at least once, since the agent otherwise always greedily chooses the best action.
  • Greedy...

MDP and the Bellman equation

If you have studied Reinforcement Learning previously, you may have already come across the term MDP, for the Markov Decision Process, and the Bellman equation. An MDP is defined as a discrete time stochastic control (https://en.wikipedia.org/wiki/Stochastic) process, but, put more simply, it is any process that makes decisions based on some amount of uncertainty combined with mathematics. This rather vague description still fits well with how we have been using RL to make decisions. In fact, we have been developing MDP processes all of this chapter, and you should be fairly comfortable with the concept now.

Up until now, we have only modeled the partial RL or one-step problem. Our observation of state was only for one step or action, which meant that the agent always received an immediate reward or punishment. In a full RL problem, an agent may need...

Q-Learning and connected agents

Typically, Q-Learning is taught using a grid problem such as the one we looked at it in the previous section. Here, though, we want something a little more complex and abstract that also allows you, the reader, to build on it and explore it further. We have put together an interesting example where we represent our bandits as rooms or objects with a number of exit options. This example could also very easily represent a dungeon or another connected room structure that you need to navigate an agent through. Follow these steps to get started on building the connected agents exercise:

  1. From the menu, select Assets -> Import Package -> Custom Package..., then navigate to the book's downloaded source code and import the Chapter_2_Connected_Bandits_unitypackage. This is the example, which has been fully constructed already for you. Apologies...

Exercises

"For the things we have to learn before we can do them, we learn by doing them."
– Aritstotle

Be sure to complete the following questions or exercises on your own:

  1. Extend the bandit cube maze in the last section with your own design. Make sure to keep all the cubes connected so that the agent has a clear path to the end.
  2. Think of another problem in gaming, simulation, or otherwise, where you could use RL and the Q-Learning algorithm to help an agent learn to solve this problem. This is just a thought exercise, but give yourself a huge pat on the back if you build a demo.
  3. Add new properties for the Exploration Epsilon minimum and the amount of change per decision step. Remember, these are the parameters we hard-coded in order to decrease the epsilon-greedy exploration value.
  4. Add the ability to show the Q values on the individual BanditCube objects. If...

Summary

In this chapter, we dove into working with the ML-Agents framework by developing a heuristic brain that uses an ML technique called Reinforcement Learning to solve various fundamental learning problems. We first explored the classic multi-armed bandit problem in order to first introduce the concepts of RL. Then, we expanded on this problem by adding context or the sense of state. This required us to modify our Value function by adding state and turning our function into a Q function. While this algorithm worked well to solve our simple learning problem, it was not sufficient for more complex problems with delayed rewards. Introducing delayed rewards required us to look at the Bellman equation and understand how we could discount rewards over an agent's steps, thus providing the agent with Q value breadcrumbs as a way for it to find its way home. Finally, we loaded...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • • Learn how to apply core machine learning concepts to your games with Unity
  • • Learn the Fundamentals of Reinforcement Learning and Q-Learning and apply them to your games
  • • Learn How to build multiple asynchronous agents and run them in a training scenario

Description

Unity Machine Learning agents allow researchers and developers to create games and simulations using the Unity Editor, which serves as an environment where intelligent agents can be trained with machine learning methods through a simple-to-use Python API. This book takes you from the basics of Reinforcement and Q Learning to building Deep Recurrent Q-Network agents that cooperate or compete in a multi-agent ecosystem. You will start with the basics of Reinforcement Learning and how to apply it to problems. Then you will learn how to build self-learning advanced neural networks with Python and Keras/TensorFlow. From there you move o n to more advanced training scenarios where you will learn further innovative ways to train your network with A3C, imitation, and curriculum learning models. By the end of the book, you will have learned how to build more complex environments by building a cooperative and competitive multi-agent ecosystem.

Who is this book for?

This book is intended for developers with an interest in using Machine learning algorithms to develop better games and simulations with Unity. The reader will be required to have a working knowledge of C# and a basic understanding of Python.

What you will learn

  • • Develop Reinforcement and Deep Reinforcement Learning for games.
  • • Understand complex and advanced concepts of reinforcement learning and neural networks
  • • Explore various training strategies for cooperative and competitive agent development
  • • Adapt the basic script components of Academy, Agent, and Brain to be used with Q Learning.
  • • Enhance the Q Learning model with improved training strategies such as Greedy-Epsilon exploration
  • • Implement a simple NN with Keras and use it as an external brain in Unity
  • • Understand how to add LTSM blocks to an existing DQN
  • • Build multiple asynchronous agents and run them in a training scenario

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 30, 2018
Length: 204 pages
Edition : 1st
Language : English
ISBN-13 : 9781789131864
Vendor :
Unity Technologies
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Jun 30, 2018
Length: 204 pages
Edition : 1st
Language : English
ISBN-13 : 9781789131864
Vendor :
Unity Technologies
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just Can$6 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just Can$6 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total Can$ 173.97
Unity 2018 Shaders and Effects Cookbook
Can$69.99
Unity 2018 Artificial Intelligence Cookbook
Can$61.99
Learn Unity ML-Agents ??? Fundamentals of Unity Machine Learning
Can$41.99
Total Can$ 173.97 Stars icon
Banner background image

Table of Contents

7 Chapters
Introducing Machine Learning and ML-Agents Chevron down icon Chevron up icon
The Bandit and Reinforcement Learning Chevron down icon Chevron up icon
Deep Reinforcement Learning with Python Chevron down icon Chevron up icon
Going Deeper with Deep Learning Chevron down icon Chevron up icon
Playing the Game Chevron down icon Chevron up icon
Terrarium Revisited – A Multi-Agent Ecosystem Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
(3 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 100%
Digital Kristen & Family Aug 04, 2018
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
While the information was great, attempting to get a windows machne to work with the examples was filled with headaches and errors after errors. I was unable to get any of the examples to work that used external trainers. If your looking for a book on theory, pick this book up else i wouldn't suggest this book.
Amazon Verified review Amazon
Crystal Shining Unicorn Princess Jul 31, 2018
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
Absolutely useless book covering what is actually written in free unity ML Agents tutorials (not even 100% of what is covered). Don't waste your money, invest in some legit books on machine learning.
Amazon Verified review Amazon
rishabh Nov 24, 2018
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
Chapters have no good explanation of anything. I found better explanation of the ml-agents examples provided by unity on its own website. The last chapter felt like things were heading in a better direction. The author just gives a set of instructions to set up a project instead of explaining why he is using a specific piece of code and its impact on the project. A true let down.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.