- If you want to understand the weird and wonderful world around you, then maths is your friend. But the real trick is
that with a little bit of mathematical thinking,
you can take those rules and patterns bend and twist them, and fire them straight back at you. (thunderclap) Tonight, we are gonna explore just how far we can push these powers to achieve amazing things. (upbeat music) (audience applauding) Welcome to the Christmas lectures. I am Dr. Hannah Fry, and tonight we are gonna be talking about how to give ourselves
superhuman skills. Now, we're very good at using maths to understand the world around us, but if we want to bend
the world to our will, we're gonna need to be a
little bit more inventive. We're gonna need to take
this maths up a level here. So I thought what we'd do, is we would start off tonight with something of a competition. So I wonder, does anyone know how
to solve one of these? Who doesn't, oh, actually
quite a few of you. Okay. Who doesn't mind coming down? Let's go with you, actually. Yeah, if you want to come down. Round of applause if you can
as he comes to the stage. (audience applauds) What's your name? - George. - George. Okay, how good
are you at these, George? - I solved it a few times. - Okay. All right. Let's give you a go. We're gonna give you lots of encouragement as you go and we're gonna be - Can I look at it first like? - Yeah, you can have a look, like yeah. We'll be patient with you though. - Okay. All right. Yeah. Recking I'm ready to go. - Okay, come on then, George. Come on, George. Hang on, George. (audience murmurs) Hang on, George. George. (audience applauds) George, you solved this
more than a few times. - Yeah, quite a few actually. Yeah. (laughs) - Tell us who you actually are, George. - I'm actually the UK champion of solving the Rubik's Cube. Yeah. - Your the best in Britain. - Yeah, currently raining,
UK champion, yeah. - So tell us, okay. How do you actually solve one of these? - Okay. So I guess the first thing
to know is that like, it's got quite a lot of combination. So it's not like you just
like learn one thing, then you can solve it straight away. So like when you scramble it, chances are it's combinations
that actually never ever been seen before. It just has so many combinations. It has 43 quintillion combinations. - That's a big number. - So 40 followed by 19 zeros. So like you kind of
just split up into steps and you need to learn algorithms like, well, this whole lecture
will be on algorithms. - A list of instructions. - Yes. So when algorithms,
when applied to a cube, that kind of means that you're temporarily mixing up the cube, then putting it back, having
switched a few pieces. So the more algorithms you know, the more efficient you'll be. If I combine that efficiency
with faster turning it allows me to be a faster solver. - Now, there's a very key point here in what George saying, which is that sometimes maths doesn't look like numbers and equations. Sometimes maths can just look
like a list of instructions. I mean, you can solve
this by following a list of instructions and the
algorithm as you say. And that means George then,
if I want to beat you at this, all I've got to do is
follow those instructions faster than you. Right? Well, thankfully, I have just the thing that's going to help me. And Elliot here is the creator of this machine. So I'll tell you what, okay let me just scramble this one up again. We're gonna have a competition. We're gonna do you against the machine. Okay, so here we go. Let's scramble this one. And you're not allowed
to look at this now. Okay. So I'll tell you when
you're allowed to look. Is it ready to go Elliot? Okay, all right. We're gonna count down and then you and the
machine can both look. Ready? Three, two, one, go. Who's gonna win? Who's gonna win? Who's gonna win? Ooh. (audience laughs) George, you're letting yourself down. - All right. - That's absolutely incredible. (audience applauds) I mean that was amazing. That was amazing. Okay, let's go there
and have a little look, and look back at what it did. I mean, this machine is
doing the same things as you. - Exactly, yeah. It's just, it's like seeing those, like when to use those
algorithms way more quickly and it's does like all in one go. So it doesn't have to like pause to look to when to start the next
algorithm or anything like that. - So we can look at it
a little slow-mo replay I think of this. And it is a properly mixed up cube there. Wow. - Amazing. - That was absolutely incredible. So it's not better than
you, it's just faster. - I suppose, so yeah. It would know more
algorithms than I do, yeah. - Amazing. George and the cube solving
machine, thank you very much. (audience applauds) Thank you. That was amazing. So impressed. That really, I think was
there was a great example of a machine following instructions. The question is how do
you get those instructions into the machine in the first place? Well, one man who knows the
answer is coded extraordinary, Seb Lee-Delisle. (audience applauds) Hey Seb. So Seb tell us about the
kind of things that you code. - Well, I like to make really
big light installations that are interactive. - Oh, okay. Are we seeing sufficient this here? On the side of buildings. - Yeah. You see, my ambition really is
to replace fireworks, right? - With lasers. - With lasers, yeah. 'Cause like fireworks are old technology. Now we've got technology that's
just as bright as fireworks. Lasers, super bright LEDs, but all of my technology
is controlled by computers. - Okay. So talking about computers then, how do you control these things? - Well, I'm gonna show
you how we make something called a particle system. So I've got a browser open. I'm gonna do some coding in JavaScript to make some graphics. - You're gonna be making an algorithm? - An algorithm, yeah. - A series of instructions
for the machines. - Exactly right. So the first thing I'm gonna
do is make a single particle, which is essentially just a shape. And we've got to decide what
color that shape should be. Any ideas what color? (audience murmuring) - I think first thing I heard was pink. So I'm gonna actually use magenta, which is my favorite type of pink, and it's a very nice, bright pink, and the next thing I've got to
do is draw a filled-in shape. So let's hear some shapes. (audience murmuring) Circle. Okay, okay. Square. I think I heard square. Okay, square. So a square is just a rectangle. So let's draw a filled-in rectangle. We're gonna draw it at zero zero, which is the top left of the
screen and X and Y coordinates. So we're gonna make it a hundred wide and a hundred high. So lets look at our square. There it is. - So this X and Y that you
were talking about there, are you're treating this
as though it's a graph? - Yeah. So this huge canvas in
JavaScript, it's got pixels and I can identify each pixel
by its X and Y coordinate. - Okay. So this is just straight up math. So far? - It's all maths. It's maths all the way down. Then I can change this X value and you can see that the rectangle moves to whatever coordinate I
specify to the X position. - As you increase X, this is
moving right against the graph. - Yeah, exactly. So let's do the same
thing for the Y value. You can see it moves
down and to the right. Right, so this is good. It's the start of our
particle, but it's not moving. It's completely static. So in order to get it moving, I'm gonna wrap all of this
stuff up in a function, and I'm gonna call this
function 60 times a second. But now, I can do X plus equals one, which adds one to X every time. And now we should have the
rectangle in a brand new place every time we've made some animation. - It doesn't look much like a firework. - No. So we're getting there. So in particle systems, usually the particles are very small. That's the first thing we can fix. Let's just make it really little. Oh. And now, lets makes new variables for the X velocity and for the Y velocity. But the best part is when I give those velocity
values a random number. So you can do that with
the command random, and if I pass in minus 10 to plus 10 and we're gonna get a random
number in the X velocity between those two numbers and
the same as the Y velocity, and you'll see now that
every time we run it, it goes in a completely
different direction. - A random direction every time. - Right, exactly. So that's kind of fun. So we've got one particle,
one particle is cute, but really the idea of particle systems that we make a whole bunch of particles. So now in this next bit of code, I'm doing essentially the same thing, but I'm creating an array of particles and we get an effect like this. - Ah, that looks like a sparkler. - Right, we're getting there. We're getting to the sparkler now. This is an ordinary projector. So it's not very bright. If we want to create something
that's truly spectacular like a real fire firework,
we need to use a laser. - Ah, that's wow, they
are extremely bright. - Right. They're really,
really bright, aren't they? And so I can adjust all the settings here. I can change the speed, how fast they are. Make them fade out over time
a little bit and so, yeah, I can add some gravity
to make them fall down. - But of course, the stuff
that you really well known for Seb it is not just you having control of where this is on the y-axis, where it is on the graph, but letting the audience control it. - Exactly. I love doing interactive things. So what I thought I do is
actually take the sound from the microphone in my
laptop and apply that level to the white origin of the particles. And then we could make a game out of it. So here we've got this. You can see the sparkler on the left. Now it should be that the
more noise that you make, the higher the sparkle rises. All right. Here we go. Three, two, one, go. (audience shouts) - [Hannah] Okay, very good. (audience shouts) This is it, guys. (audience shouts) - It's getting harder. (audience shouts) (audience shouts) Oh. That was amazing. That was such a high score. Well done everybody. - Yeah. Amazing, amazing. - Yeah. - Seb, thank you for
sharing with us your lasers. That was very awesome. - Your very, very welcome. - Thank you much Seb. (audience applauds) Now Sebs fireworks looked very realistic there, but I think if you want something that
looks as real as possible then you really can't do better than looking at Hollywood films. The visual effects that
they use in their movies. Now these are the people,
the people who create those they're the people who they
don't only copy reality but they really know how to bend the rules to their will for our entertainment. And we are very lucky because today we are joined by
someone who does exactly that from Weta Digital in New Zealand please join me in
welcoming Anders Langlands. (audience applauds) So what films have you worked on Anders? - Well Weta has got quite a long history of going all the way back to the Lord of the rings,
Avatar, Planet of the apes. And then most recently Avengers this year. - Oh, crikey. I mean, you don't get
much bigger than Avengers. - How much of the animations that we see the CGI that we see in films How much of it is maths? - Well, it's all maths really. It's like a combination
between art and science. And we use algorithms to
simulate how things move to give animators controls,
to make things move according to their desires and
to render the pictures and make the images through
mathematical equation as well. - But presumably if you want to make things
look realistic on the screen you have to understand how
they work in real life. And that really is what this tower behind us that has just
been built is here for because I would like a volunteer
who would like to come down and help me to dismantle this house. Let's go for, yeah. Do you wanna come down? Round of applause as he comes to stage. (audience applauds) What's your name? Okay perfect. All right, so we I've
got this bowling ball now I want you to roll it very gently. This a very old and important building and we will send you a bill. So very gently and try
and smash down this tower - Can I stand somewhere else?. You can stand, you can stand
a bit further back here if you want to give you a bit of a run up but that's kind of dumb. Ready? Okay. Three, two, one. Go. - Oh, its pretty good. Yay. (Hannah laughs) Well done. Thank you. (audience applauds) But stuff like that isn't just for fun for you guys, right? - No. I mean, we have to
do things a little bit more complex than that, but the basic equations of motion that govern something like that as you've just seen are pretty simple simple enough to solve by
hand in a lot of cases. And if you've done GCSE maths then you've probably
encountered some of that too. - Just the physics behind
what just happened. - Just the physics behind
what just happened. Of course, we want to simulate
much more complex things. And even something like
this tower falling over we need to use computers to do that. So we can do it fast enough
to make a moving animation. - And in fact, talking
of moving animations you have brought one with you. So let's have a look over here
of this is our tower, right? This is kind of the same
as same as our tower. - Yes very similar. - But this one is a complete animation. - Yes. So we look at the forces of gravity and the force of the ball being thrown, analyze the collisions. And then we check every single frame. So at least 24 times a second, we update all of that and work out where the blocks are gonna be on the next frame to create an animation. - So let's have a little
look at it as it's, as it's animated. It's pretty good. In fact, I mean, you've
even got the little bit that I had to kick down. - I haven't got a digital hand to kick it down I'm afraid. - Okay. So once you are at this stage once you have this stuff created you understand how the basics
work, then what do you do? - Well, then we can have
a little fun with it. So because we create the world we can do things like
change the boxes into China. So they shatter when it gets
hit, rather than falling over. We could change all the boxes into balloons and then
pump them full of helium. So they float away. (audience and Hannah laughing) - That's nice. These are escaping around the side. That's nice, I like that a lot. - It getting away, or maybe if wanted something a bit more exciting we could douse them in petrol
and then set them on fire. - Oh, wow. (audience laughs) That looks very realistic. - Yeah thanks. That's kind of the point. (Hannah Laughs) - How do you make that
look that realistic though? - Well, like you said, we have to analyze what's going on in real
world and use maths to try and simulate it as closely as possible. So in the case of fire or
explosions, for example we look at the chemical
processes that drive that. So for fire, the combustion
process is turning a fuel into water and carbon
dioxide and some carbon. And then the temperature
then decides how hot that soup gets. And that decides what the brightness and the color of the flame then is. - When our working with building say, do you take into account the things that the
buildings are made from? - Yeah. We want to analyze
all the different material properties that are in a building. So like how bricks
shatter when they get hit. Mortar turning into
dust, the steel bending. We have to layer all of these things up using
either one big simulation or lots of simulations
that get put together. And you know if you're doing a giant bath
toy knocking a building down you're kind of outside of the realm of real world physics at that point. So a lot of what our effects artists do a lot of their skill comes into figuring out how to tune the physics of the simulation to give
something that you've never seen before that the director wants, but also something that the audience can believe is real. - Take reality and bend it. - Yeah. So a big part of
what our team of scientists and software engineers at Weta do is use math to figure out cool tricks to make
the simulations run faster will still looking real. - That is amazing Anders thank you very much. - Thank you. (audience applauds) - As Anders mentioned there takes huge amount of
brain power to compute those simulations. Takes even machines days to do but of course, it's not just fun and frivolity that's on the table. When you can get machines
to do your maths for you because working out how to get computers to crunch the numbers also saves lives. And something that has had a huge impact from using algorithms
is organ donor matching. Let me explain what I
am talking about here. So let's imagine, let's imagine that you're a bit poorly
and you needed a new kidney. Now, luckily your friend
here has very kindly and generously offered to donate to you one of hers. Almost all of us are born with two kidneys and you can live a very
long and happy life with just one healthy kidney. Now, if you were both good
tissue matches or blood matches for each other, then this would be actually fine. The transplant could go ahead. But if for some reason your blood or tissue type didn't match, then you would be in a position where you had one person
who needed a kidney one person who was
willing to donate a kidney but nothing that you could do about it. That was until very recently all you could do is really wait around on the transplant list,
hoping for another donation. That was until quite
recently when someone had a very bright idea, because while you two might be stuck in that position, perhaps over here there
are another two people who are in a similar position. So maybe you need a kidney you have one that you
are willing to donate, but that unfortunately
doesn't match your loved one who you're trying to help. But what if your kidney rather than matching your friend here. What if your kidney was a match for you? Now that transplant could go
ahead and that would be fine. But the question is, why would you why would you want to give up your kidney to someone
you've never met before? Especially when your friend is still sick and in need of a transplant. But what if there was
a third pair of people? What if we can close this loop with another group who are over here? So one more person and their loved one who was
willing to give them one. You got a whole loop of a pair. Perfect. Thank you. I'll take that down. Now in this situation if this could happen, if this happened to be
a match for you as well, then everyone's happy, right? Everyone who needs a
transplant has got one and everyone has helped make sure that their loved ones have
the operation that they need. Now, the only problem with this is that there are often hundreds of people in the country who are, who
find themselves in this position and finding these matches
is incredibly difficult. The number of possibilities with hundreds of people
is absolutely enormous. And you have to make sure
that you create a closed loop every single time, so that
everybody ends up happy. But this is the kind of thing
that computers are absolutely perfect for. And in fact, this is exactly what a team at the University of Glasgow have done. So here is the output from that algorithm. This, this, this algorithm
runs in seven seconds and this is the network
that, that it spits out. So each one of these dots is a real person and each one of the lines is
it's effectively a ribbon. And if we zoom in on this,
you can see here just how many ribbons this algorithm is potentially considering. Now, clearly there's no way that any human would be able to weigh all
of this up within their their own minds. But this algorithm, this isn't just something
that's theoretical. This is something that actually
does go on to save lives because in fact, up there
holding on to the green ribbon is Yuki, who is part of a real life chain. So Yuki if you want to join us on stage. Round of applause. (audience applauds) Thank you for joining us Yuki. So how long ago did you
have your operation. - I had it three years ago. - And who was the loved one who donated a kidney on your behalf? - It was my grandma from Japan. - From Japan. I think we have a photograph actually here of you guys outside Great Ormond Street. So your grandmother's
kidney went to someone else. Where did your kidney come from? - My kidney came from
someone in Birmingham. - And do you know how
many people there were in your chain? - I think three. - So very exactly the
same as we have here. - Yeah. - It's a really incredible story. Yuki, thank you so much for joining us. (audience applauds) Now this work, it's a
monumental breakthrough. It's something that's
been a real game changer for people within the UK. And the key thing that
that algorithm can do the thing that no human
can do on their own is considered this vast
number of possibilities. And that is the superhuman
power that you open up when you hand over your math to a machine because suddenly it can use all of its grunt to tailor
things to the individual. To work out precisely
what is right for you, which kidney you need and in a much smaller,
but no less profound way, which song or video you might like. Now, YouTube videos, Netflix Amazon, BBC iPlayer, all
of them crunching through vast amounts of information
on their websites. But how do they make sense of
the content that is uploaded and what kind of process do they use to decide what you might like to see next? Well Okay. I'll tell you what let's find out here by
making our own video. So I wonder, can I have a volunteer? Someone who is a happy
to help me commentate on a little YouTube video. Ah, okay, perfect. Yeah, let's go there. Come on down. Round of applause as
he comes to the stage. (audience applauds) Now what's your name? - Anthony. - Anthony. Okay, perfect Anthony. Right? So we were gonna make you got your phone? - Yes. - Okay, perfect. Right. We're
gonna make a video Anthony and we want it to be seen by
as many people as possible. Right? We want it to be picked
up by the, by the algorithm. So we're gonna make a
great YouTube video here. Now. Thankfully, the world famous Royal
Institution demo team are on hand to help us make our
videos exciting as possible. So if you give me this and I will, I'll do your video for you. If you take these, you can
come and stand over here and help me commentate on this video. So I'll take the video, here's demo. You, you start off whenever you want to. Okay. There we go. - What's up folks. It's me, Anthony again. Thanks for subscribing. This is my best, best friend,
Gemma doing some science. They have some extremely
cold liquid nitrogen. Whoa. Look at all these ballon dogs. Where are they coming from? It's the balloon dog challenge. Now Gemma is gonna add hot water to liquid nitrogen at
it will yeet everywhere. Let's give her a countdown. Nice and loud. Three, two, one. Whoa. (audience applauds) Now chalked out of view its YouTube Tom Scott. - And behind the cloud appears YouTube sensation Tom Scott. Anthony thank you so much. There you've got your video there. Thank you very much indeed. Big round of applause if you can. (audience applauds) And do you often appear
in clouds of smoke? - No, it's the first time
I've been summoned like this. It's wonderful. - Now I should say to you for any of you who don't recognize, Tom Tom is one of Britain's
foremost YouTubers. If there is one person that we can ask about how to make sure a video gets seen by as
many people as possible. I mean, you are that person. - Yeah. I wish there was some
magical way to guarantee it but I mean, I've, I've done
some pretty cool stuff. I've I've been in zero G but that video didn't do well compared to, well a two minute shot of
me continuously looking at some toasters and talking about how long it's gonna
take them to pop up. That video did better than
me flying about in zero G. But what did better than both of those to achieve like twenty-five million views was me attaching some garlic
bread to a helium balloon and sending it to the edge of space then bringing it back
down and eating it now. - [Hannah] Twenty five million views. - [Tom] Twenty five million. - [Hannah] What 25 million is a lot. - I kind of figured that
one was gonna do well. I didn't think it was gonna do that well. I have never ever been able
to find anything that will that will get these
recommendation engines. These algorithms to specifically
go for a particular video. - Because it is an algorithm
that's deciding what gets promoted on different
people's YouTube, right? - Yes. And originally years and years ago it was all down to the
title and the thumbnail. Is that okay? Because that's, that's crackling a lot. - I'm slightly nervous. (audience murmurs) I mean this is gonna make
a quite a YouTube video if it explodes on us now as well. - I'm gonna keep going. We're gonna keep it. Originally. When I started
2006, it was all about the title and the thumbnail. And that was it. So you could trick people
into clicking on something with a lie in the thumbnail,
a lie in the title. And that's still true now,
but it doesn't work as well. Because after that, they
said it was more about how long people watched a video for. So at that point, people put
a little explosion at the end of a 20 minute video. So you'd have to watch all the way through - Those long introductions that were very fashionable for a while. - Because they kept people watching. So now YouTube doesn't
give any advice at all on how to make something,
please the algorithm. And as a YouTube creator, like all of us just call it the algorithm,
this one monolithic thing. They say that if people
watch it and people like it then the algorithm will also
recommend it to other people but they will never ever
say what the reasons are because the minute they do that everyone will say, "Oh yeah,
well, I'll start doing that." And suddenly a hundred thousand 200,000 people are all doing that. And no one's watching it anymore. There are 500 hours of video uploaded to YouTube every minute,
not watch like uploaded. So I'm sure it's a great
video on your phone statistically, it's
probably not gonna go big but it might cause the more
times you can roll that dice in the better your chances are. - I'm gonna go create a garlic
bread video of my own now, I think. - Good luck. (Tom laughs) - Apparently it does well. - Tom Scott, thank you very much indeed. Thank you. (audience applauds) Now as Tom hinted there, there is actually something
slightly different going on here to the, the fireworks or the organ donate
algorithms that we saw earlier that YouTube algorithm, it
isn't just crunching through a straight list of instructions anymore. It's actually doing something
a little bit different. I want to explain this to you using a cup of tea and a robot. Oh, okay. Maybe not an actual robot but definitely the next best thing. Please join me in welcoming
robot Matt Parker. (audience applauds) That's a (audience applaud continues) That's a great outfit, Matt. - Thank you, I made it myself. - Sorry. I compiled it myself. (Hannah laughs) - Okay. Now robot Matt, like all robots he isn't
particularly bright. - Oh oh. Offense registered. - He also takes things
incredibly literally, as we are about to discover because we are gonna
together try and instruct robot Matt Parker with
how to make a cup of tea. Okay. So here we go. What was the first thing to do if you make a cup of tea? - You heat up the water in a kettle. - [Hannah] Heat up the
water in the kettle. Perfect. Sound sensible. There's the kettle. Okay. Next step. Next step. - You take out the tea bags. - Take out the teabags. (audience laughs) - That's good. Next step. - Get a mug. - Get a mug. Oh, a teeny tiny one. Look at that. What should we do next? - Put the teabag in the mug. (audience laughs) (Hannah laughs) - [Hannah] Is that the right mug there? Well, let's let's get another. - Put the boiling water in. (audience laughs) - He takes things very literally. (audience murmurs) - Heat registered. (audience laughs) - [Audience Member] Get a
normal size tea bag and cup. - [Hannah] A bigger cup. (audience laughs) - Put the normal tea bag in the mug. (audience laughing) - [Hannah] I'm gonna come around there. Hang on one second. (Hannah laughs) Hold on a second. I'm gonna come up here. Here we go. What's next. What's next. - Stop. Pouring the water. - [Audience Member] Put
the tea bag in the mug. - Pouring the water into the mug. (audience laughing) - [Audience Member]
Stop pouring the water. - Add milk and sugar to taste. (audience laughs) - Pour the milk from the first mug into the mug with the tea. (audience laughs) - [Hannah] Oh yeah,
then we've got one more. - Stop pouring the milk into the cup. - [Hannah] And the last step. - Drink it. (audience laughs) - I've made this for you. - Here there an. Oh that's ghastly. ( Hannah laughs) (audience applauds) Thank you very much. - Okay. I think it's quite obvious that our list of instructors
there needs to be needs to be quite long and that is only for making a cup of tea, something very easy. So imagine how much harder
it would be to write a list of instructions for a
very literal computer. Okay. How would you explain to a computer how to recognize a picture of a dog? What, what, what do dogs look like? Shout out. What are the important things about what dogs look like that you know? (audience shouts) Fluffy, fur yeah. (audience shouts) Four legs. (audience shouts) Tail, yeah okay. All right, all right. So we've got we've got fluffy or
furry, tail and four legs. Great. Okay. Those are all good. But what about this? Oh. (audience laughs) Slight problem there, but okay. All right. What else? What about its face? What, what, what what's important to recognize about the face. (audience murmurs) Pointy ears. (audience murmurs) Pointy snout. Okay. Okay. Okay. Here we go. All right, so pointy snout someone said, how about this then? (audience murmurs) Okay. Even if, even if you
could work out, you know maybe take into account the
color, all of that stuff. Didn't you say that dog
had to have four legs because what about this guy? It's still definitely a dog. Still definitely a dog but it just goes to show
just how hard it is. If you're trying to write
a long list of instructions just how hard it is to pin down exactly what a dog looks like. Now, humans, we're amazing at this. We can do this without even thinking but explaining how we do it, especially to a pretty dumb computer that takes things very literally ends up being quite a lot
harder than you might imagine. But there is another way around this to explain please join me in welcoming computer scientists extraordinary
Anne-Marie Imafidon. (audience applauds) There is another way to
all of this Anne-Marie. - There is another way
we need a different type of program that isn't a specific. - Isn't it a list of straightforward do this, do this, do this. - Exactly. We need to type a
program that has an end point or a goal and we let the computer or the machines figure out its own rules to get to that end goal. - Without giving it
straightforward instructions? - Without giving it any instructions other than that's where we're going. And maybe when it's got it right. - Okay. Anne-Marie this sounds like magic. - Well, it's computer
science more than it's magic. - It's a lot like training an animal. When you get a dog, you're training it to maybe
do a particular trick. You don't say move this
muscle and look that way. You kind of just give it a treat when it does the right thing. - And you got a clear idea in your mind of what it is you want them to do - Exactly. Whether it's sitting or whether it's anything else. - Okay. All right. Well, on that point then
of, of training animals what's this kind of algorithm called in certainly when it's in computer science. - So we call it a reinforcement
training algorithm and it's one that learns on its own. So which actually part
of machine learning. - Okay. All right. So reinforcement learning. Let's see how this works because we're gonna try
some reinforcement learning on one of you. So who would like to be our volunteer? You had your hand up I think first, if you could come down. (audience applauds) What's her name? - Emily. - Emily. Okay, perfect. Emily, if you want to come over here. Okay. So Emily, what we're gonna do then is we're gonna play a little game with you and you can just come to the side while they bring all these things on. What we're gonna do is we're
gonna show you four pots. You can see all the different
routes that we go there. They all, these pots are colored and they've got kind of
sums on them on the side to solve. Now Anne-Marie and I, we
have gotten our minds. We've got a very clear idea of which pot we want you to pick. So in each round, all you do
is you just touch one pot. Okay? If you are correct, we're
gonna give you a treat. We're gonna give you a little reward and I think they might be just be in here. We're gonna give you a
little reward of a humbug and if you're wrong, we're
gonna move on to the next round. Okay? If you want to just stand in there for me. Now, just to prove that
this really is something that is not specific to humans, you are going to play this game against a competitor by
which I mean a pigeon. If we can, if we can
work one to the stage. Alfie and his trainer Lloyd. Around of applause. (audience applauds) Now I have to tell you, Emily Alfie has had a bit of
a headstart on this. Alfie has been trained. Look how sweet Alfie
is, very beautiful bird. Right, so you happy? You understand the game? All right, let's go. Let's go for round one. So just touch one pot. Incorrect. Alfie got it right though. - He did. - He did. - Alfie one human zero. (Hannah and audience giggle) - Okay, here we go. Round two. Incorrect? Oh. Alfie two human zero. And here we go. Next one. Correct. Okay. Next one. Oh, incorrect. - Alfie's got it correct again. - Okay. Let's go final round. Now. Okay. The equations on this
side are getting harder and harder and harder. Almost like there's no possible way
that you could solve them. Ah, incorrect. That is tough. That is tough. Okay. Tell us, how did
you, how did you find it? Tell us what you thought. - It was quite hard. I just basically picked random ones. There wasn't really a method. - What were you thinking
when you got it right? I didn't really have a thing. I just saw picks one apart from the one where the yellow
pot lid fell on the floor. - Oh, did you see the yellow part? That was a big clue on fact, actually. Which part do you think that
Alfie was picking every time? Should we tell her the yellow her? - The yellow one? - The yellow one. Exactly. Right, exactly right. (audience applauds) Now, that was quite tough. That was quite tough. But Anne-Marie, tell
us how similar is this to the things that we
see in compute science. - So this is very similar to what we see in computer science, but with a computer it's able to do this thousands, millions billions
of times in a second. And so can then pick up that pattern quicker than we can as humans. And often it can see patterns
that we humans can't see and can make those kinds
of connections as well. - And that is a really important point because you only had a few rounds, but if you were a computer, you'd have had 10,000 in that time. So there you go have another treat and
a big round of applause. Thank you very much Emily, thank you. (audience applauds) Now the way the Alfie was trained there was just using exactly
that same technique. Alfie just had a lot more goes at it. But as Anne-Marie said there if an animal can learn in this
way with very simple rewards never hearing full instructions, then so can a machine. Now that might seem like
a bit of a bit of a leap. How do computers learn,
especially when, as we found out with that cup of tea
machines are incredibly dumb. Well, it is possible. And perhaps unsurprisingly given that it's in this program,
it is totally mathematical because it turns out you can teach an inanimate object to learn. And we have been doing exactly
that for the last week. Please welcome Matt Parker
and the menace machine. (audience applauds) Has to be honest Matt menace machine looks quite a lot like a whole heap of matchboxes. - That's because menace is
just a heap of matchboxes but we've taught these matchboxes to play noughts and crosses. - Okay. Okay. Talk me through it. How on earth can matchbox is
playing noughts and crosses? - Well, the great thing
about noughts and crosses is there aren't that many possible games. There's only nine squares. It's a nought or a cross. And on the front of these boxes every single one is a different state that
the game could be in. In fact, this is every possible position of every possible game that
menace could possibly face. We've got all the first
moves, second moves. The third moves are in blue and the final fourth
moves over here in pink and inside each box, we've
put some colored beads. So here's one that we haven't used yet. And you can see there's a real mixture. There's like nine different colored beads and each color of bead corresponds to a move menace can make. - Because of course there's
only ever nine possible places that you could, you could
play for noughts and crosses. - Exactly. - Okay. So how do you
actually train it though? - Well, initially there's
just a random collection of beads in every single one. So actually it's making every
possible move equally likely. And initially menace is terrible but the reinforcement
learning is we track each game and if menace wins we give it more beads that are the same color
into the same boxes. If it loses, we confiscate those beads which makes it less likely
to do that move again. And to train it. We've had it play hundreds of games. And thank you so much everyone who before the show tonight
played against menace. Each time we either
reward it or we punish it and with each game, it
gets a little a bit better. - And how good is it? Do you think it can beat a human? - I think it will probably
not lose to a human. - All right. Well let's, let's give it a go. Who would like to come
and play with menace? Let's go for you there, yeah. Round of applause as she comes down. (audience applauds) What's your name? - Allie. - Allie. Okay. Perfect. Allie. Now, Allie, you've got the advantage of being a sentient being. So I think it's only fair that we let the matchboxes go first. - Okay. So minister's gonna go first. And this is the blank box
where there's nothing on it 'cause we haven't played at all yet. I'm gonna give it a shake and then I'm gonna pull
a beat out at random. So, well, menace is the brain. I've got to do the actual moving around. Okay, so the first bead is green. Which is not surprising 'cause you look in the
box, they're all green. There's one purple one because menaces has learnt very quickly. If it goes in the middle to start with it's way more likely to win. Now there you are Allie,
where would you like to go? Put a cross wherever you wish. Oh, a corner old move. Okay. I've now got to find in the group of second
move boxes this game. Oh, okay. There it is. But if you have a look, Allie it's the same as this game,
but it's the mirror image. And that's because we didn't want to use twice as many boxes. It's not good for the environment. So if you don't mind me
turning the game over are you happy? That's still the same game. But now it exactly matches what's on the box
so I can give it a shake. And menace is gonna go make sure it's properly random yellow. They're all yellow. Okay. So it's learnt. I mean, there are other
moves that could make but it happens to have learnt that there is a good second move. Okay. Your go. Predictable. Okay. You're not letting
it win that easily. That's fine. Okay. Third move. Where are we? Where are we? There. Okay. So you can see that one there that matches this state. Here we go. Give it a shake. Okay. Oh, white. Okay. So the next move is gonna be white. That's over, oh, that's not bad. Here you are. You're just not letting
menace have luck, are you? Okay, that's fine. So now I've got to find this in here. Bear with me. This is exactly as much fun
as real noughts and crosses. (audience laughs) Okay. I think, I think that's it. Let's have a look that's yes okay, right. Menace is gonna go oh its probably blues left in this one. Oh orange. Okay. So I'm gonna put
an orange one there. And now that move. And now for the exciting conclusion. (audience laughs) Excellent. And now we go over there. It's a drawer. And the problem with noughts and crosses is if everyone's playing perfectly well it always ends in a drawer. So in this case, I'm gonna
give menace one extra of those beads to say that was fine but I'm not gonna give it
as many as if it had won. - Amazing. Well, there we go. You managed to draw with a
bunch of cardboard boxes. Very impressive. A big round of applause if you can. Thank you. (audience applauds) The point here is that you
don't need to explain the rules or the instructions, the
machine, in that case the matchbox learns from getting rewards
when it does the right thing. And it turns out you can use
this for all kinds of things. You can teach matchboxes how
to play noughts and crosses. And going back to that earlier challenge of recognizing dogs, turns out you can teach
machines to do it too. Now for this, I would like a volunteer to help me demonstrate this. At the back there. Yeah.
With the red jumper. Round of applause as
she comes to the stage. Thank you. (audience applauds) What's your name? - Felicity. Okay. Felicity. Right. So let's, let's have a little look over here. I'm gonna demonstrate to you how a machine can learn to recognize pictures
of dogs and not dogs. Now, the way that this
works is what you do is you give the machine a bunch
of pictures of both dogs and not dogs, and then you
label them for the machine. So that one goes into the,
the dog pile just here. Perfect. Now, initially, when
you give these pictures to the machine, it's just
gonna be guessing at random like we saw earlier in the first stages of,
at that pigeon thing. But what you can do is if you play this over and
over and over again with tens or maybe hundreds of
thousands of different images and eventually if you
do this enough times, you can end up with something like this little app over here. If you want to come and sit over here. Now we've got a little algorithm running on this iPad that has been trained in just the way that we described. And we're gonna show this algorithm a series of objects and the algorithm is gonna work out whether they're dogs or not dogs. All right. Is everyone ready to play dog or not dog? (audience answers yes) Here we go. Contestant. Number one, please. Dog or not dog? (audience claps) (upbeat music) Hello. (dog barking) Dog. Hurray. Thank you Luna. Contestant number two. Dog or not dog? Not dog. Thank you very much. Contestant number three. (audience clapping) Dog. Amazing. Next contestant please. (Hannah giggling) Aw, this is very cute. Sit, sit. Not dog. Well done. Next contestant please. Aw, look. Not dog. And our final contestant. (audience murmuring) Look, how beautiful. Dog. Thank you very much anyway. And thank you very much for
playing the game with us. Big round of applause for everyone involved in dog or not dog. (audience applauds) Now this idea, this kind of algorithm reinforcement learning algorithm it can actually have profound consequences because the algorithm doesn't really care what it's looking at. If it can learn to identify dogs it can also learn to identify diseases. To explain, please
welcome an ophthalmologist from Moorfield Eye Hostel, Pearse Keane. (audience applauds) So please tell me, tell
me what it is that you do. - So I'm a consultant ophthalmologist at Moorfields Eye Hospital and I specialize in the
treatment of retinal diseases. So in particular, I specialize in the treatment of a disease called macular degeneration and macular degeneration is the commonest cause of blindness in the United Kingdom. - And is it treatable? - So the, the thing about
macular degeneration is that if we pick it up early, we
have some good treatments and we can stop people
going blind from it. The problem that we have is that it affects so many
people as they get older that sometimes we have
a challenge to actually find the people who've developed it and treat them in a timely fashion. - Because there are so many people. - Because there's so many touts. So we actually get 200 people who develop the blinding
forms of macular degeneration every single day, just in the UK. And so for us, it seemed like this would be a perfect example where we could apply
artificial intelligence to try to identify those people with the most sight threatening diseases at the earliest point
and save their sight. And I've brought a Elaine Manner patient of mine at Moorfields
Eye Hospital, Reinventing (audience applauds) - Thank you very much
for joining us Elaine. - For me Elaine exemplifies actually why this is important because the Elaine story is that actually she had lost sight in one eye from this condition, from
macular degeneration. And then in 2012 she started to develop it in her good eye. And she went to her high street optician and was told you need to be urgently seen by a retina specialist, someone like me but she got an appointment
for six weeks later. So you can imagine a situation if you're losing sight in your good eye, and there is an effective treatment but you're told that you
have to wait six weeks. - What was that like at the time, Elaine? - I absolutely terrified. I felt that when I went to bed would I wake up to a world of darkness? Would I see my family again? It was worrying. - Yeah. And this is all just because of the sheer volume of patients - Because the huge number
of huge number of patients. - So what is this machine? How does that work? - So this is a eye scanner it something that scans the retina. It's super high resolution,
three-dimensional image of the back of your eye. - But it's something that these algorithms can get to work on? - Well, that's exactly it. I mean, if you, if the algorithm
can tell dog or not dog then it seems like it could
tell macular degeneration or not macular degeneration and help people help prevent
people from going blind. - So I hope that we can have a little look at how this algorithm looks
when it has processed an image. Can we have a little look? - You see here on the scan it's called that, that
there's an urgent problem with the eye. It's identified coronal
neovascularization. This red area here is some
blood vessel growth at the back of the eye, which is suggestive of the
condition Pierse was describing. - We've published a research article. What we've shown is the proof of concept that the algorithm that we've developed is actually as good as me or other consultants that Moorefields or other world-leading eye doctors at diagnosing these diseases. - And this stuff is, I mean it's incredibly important to get you to those urgent cases quicker. - Yes. - Like Elaine, I guess. - But the great thing was, although it was stressful
for Elaine at the start, she was able to get the treatment that she needed in this eye in time. And, and we have been able to save the sight that she has in her good. - Pearse Keane and Elaine, thank you very much indeed for joining us. (audience applauds) Wow. As I think Pearse has
work there demonstrates you can see just how far you can go with a machine that is capable
of categorizing images. As impressive as all of this technology is it's not quite perfect. It is important to just say
that these, these algorithms they don't really understand the world in the same way that we do. They don't understand context,
they don't understand nuance. And that means that it
really can make mistakes in particular, when you take
something and you put it in a strange situation
like this picture here. So if we take farm yard animals and we put them in strange situations like being cuddled by
a child, for instance the algorithm labels as a dog. This one I quite like if you take a farm yard animal and put it in a tree. This is a real photograph, by the way the algorithm gets a bit confused (audience laughs) Surely it's an Orangutan. And my favorite one of all is
that if you leave them back in the original context, but instead paint them pink the algorithm thinks they must be flowers. Which I think is quite silly. (audience laughs) This is a consequence of the way that these machines learn. As we have seen a couple
of times during this show in the beginning, they
just start off doing loads of completely random things, which means that as they settle in to completing their task, they can end up with some rather strange little quirks and have a look at this little video here. So this is a simulation, of an algorithm that was given a body and its objective was to work
out how to move its body. And every time it falls over,
it fails and starts again. And you can see it in the beginning. It's just trying lots of
things, lots of random things. But the consequences of
that is that it really has like some quite strange,
quite strange habits that it ends up picking
up as it sort of flailing all of its limbs around at random. Now, this is what happens when you put reinforcement
learning into a body a simulated one, in that particular case. But there is nothing stopping you from putting the very same ideas into the body of a robot too. So to explain please
join me in welcoming back Anne-Marie Imafidon. (audience applauds) So Anne-Marie, robots talk me through it. - So embodied robots, and
we've got lots of them that we're trying to train to do all kinds of different tasks. And we've got an example here. - Okay. So this is from professor Peter Abeel at the Berkeley AI research lab. - Exactly. So we can see this as a robot that has never kind of known
how to move its arm before - Just basically flinging its arm around at some random trying to get - Its really trying to
get the peg into the hole. - Its doing very well. - It's not 'cause it hasn't
had the time to learn what an elbow is kind of
how it needs to move around, but also that the shape needs to fit the hole that it's got there. So this is after five goes. We can see here iteration
eight is where we've jumped to, and it's getting very close. - Yeah. It's still not managing it though. I mean, it's basically just trying lots and lots of things at random it. And this, I think actually
is something that pretty much every parent of a
young child will recognize. This is this is Juno. Come on then Juno, do you want to come
and have a little play? Now, this is something that
you really notice is that when they're very little,
they don't necessarily understand how to control their limbs. Let's give you a go. You can try this too Juno, here we go. Do you wanna play with this one? Is it the similar thing going on? - Exactly. So you learn the kind of
motor skills you might need to actually complete this task between 12 to 18 months in
Juno here is only six months. So she's kind of, it's gone (audience laughs) in her mouth which the
robot didn't do, admittedly. - Different kind of reward. - Exactly. - But it's only over time by learning through
lots and lots of random random behavior initially that we learn how to control our limbs. - We've all been there. We've all been Juno. So the robots are learning
in a very similar way. Just they do have fewer distractions. They don't want to put
things in their mouth and their rewards are just
a little bit different. - So if the humans take about
18 months to master this task how long did that robot take? - So this particular robot
that we're just looking at learn to do that task in under an hour. - Yeah, well, not long to go now Juno. You might not manage it in an hour but give it a few months. And you'll definitely be doing this. Thank you very much to
Juno and Anne-Marie. Thank you. (audience applauds) That is the key key idea here. It's all about harnessing the power of randomness using trial and error to hone in on something that works. Babies, do it, robots do it. And as an audience, now
we're gonna do it too. So as a room we are all gonna be artificial,
artificial intelligence. We're gonna let you loose
like machine learning bots. And for that, I'm gonna handover to the very wonderful WIFI wars. (audience applauds) Hey Steve, tell us what we're gonna do. - So what we're gonna do is
we're gonna get you guys here to represent a random computer attempts at navigating a maze. So what we need to do
is get your phones out and go in to your browsers. And while you're all going back into there I will show you the maze. If I can please Rob, there we are. So what we're gonna do,
we're gonna put all of you in this blue room, in
the bottom right corner but we're gonna incentivize
you to go exploring. So you will get 10 points for each square in the corridor that you get through. But far more importantly, you will get a thousand bonus points for each of the colored of
rooms you managed to get to. So the big prize in this one is get to these three interconnected
rooms and the top left. If you do that, I will be very impressed. Everything we do at WIFI
Wars is competitive. So what we've done is we
split you into two half. So you guys on this of the room, I believe are the blue computer. (audience cheers) And you guys are a much
louder red computer. (audience cheers) That wasn't fair, that wasn't fair. Not yet, booing already, okay? So I'm gonna give you 90
seconds to go through that - So because there's so many people and we're gonna be looking at that big map is
really difficult to work out who you are, right? So you are essentially each
representing a random attempt at winning at this particular game. - Exactly if it was one or two you could find your way through but we're gonna make that
much more complicated. Good. Are you ready? (audience answers yes) All right good, well
let's do a gaming then. If you could send it to
their phones now, please Rob. We've put 90 seconds on the clock. And hopefully we're gonna see that immediately we see you
all there appearing. So you set them up we've got a lot of blue and red placements in computers. And already people getting out. A red person was the first one out. So wherever you are, although
collectively the blue team I was gonna say they were doing better but by the time I said it, they're not. So actually the red computer after 15 seconds have 6,000
points for the blue is 5,400. No one's found a colored room yet. And as I said, if you can get to these three in the top left corner as you can get there,
there'll be lots points - Oh these blue's doing very well. - Yeah their all going for it it's going around the two main channels as you would expect this
sort of more often than not they're picking the main thoroughfares as they hit that ends. And actually we've got
a few people who are in the purple room now, so well done. So I think a red was
the first so well done. And for context, anybody
wondering what's going on what Rob's created is
a thing that allows us without installing anything,
any device, any browser any operating system but bringing games into all your devices. - Oh look at this, red ones on the way. - Oh wow. All right, yeah, good. So I don't know if you know,
if there's a red, if you if you now are in a green room cheer. Yeah its you so, well done
to you are very, very good. You got 30 seconds left to do something about it. Nobody's managed to find
the orange or the red yet but we have got a few, well,
we've got another red coming for the green, but a
lot more blues actually. So blues might manage to level this up if they can all get in there. But with, 20 seconds
left its 70,000 points for the red computer. Blues you need to do better. You've only got 60,000
with 16 seconds left. So many people getting stuck
in this horrible dead end that we currently put
in the top right corner. I think blue is gonna need a miracle. The reds without really cheering 10 seconds left five
seconds left now 88,000 for the red computer 82,000 of the blue. So that is a winner I'm
afraid for the red computer. (audience cheers) - Well done to you. Polite applause. Well done. - That was absolutely fantastic, but okay, here is the big question on top of all of that, because
we saw in the last lecture the highs and the lows of uncertainty, we saw what can go right and what can go wrong when you rely on something that has
randomness at its core. So, okay. If we accept that
perfection is impossible. If we acknowledge that
these things are always gonna have errors, we have to ask, do we want to put flawed
machines in a position of power? That I think is one for the next lecture but for now who'd like to
have a rematch of this? (audience cheers) (upbeat music)