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
£7.99 £19.99
Paperback
£24.99
Subscription
Free Trial
Renews at £16.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. £16.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781789138139
Vendor :
Unity Technologies
Category :
Languages :

What do you get with a Packt Subscription?

Free for first 7 days. £16.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
£16.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
£169.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 £5 each
Feature tick icon Exclusive print discounts
£234.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 £5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total £ 103.97
Unity 2018 Shaders and Effects Cookbook
£41.99
Unity 2018 Artificial Intelligence Cookbook
£36.99
Learn Unity ML-Agents ??? Fundamentals of Unity Machine Learning
£24.99
Total £ 103.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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.