Placeholder Image

Subtitles section Play video

  • what is going on?

  • Everybody.

  • And welcome to a machine learning slash deep learning example with how light.

  • So before we get too far into that, I just want to cover real briefly, uh, least the overarching structure to really any machine learning at least classifier.

  • Obviously, there's different things.

  • There's like progressors, or you might have generative output or something like that.

  • But for your typical classifier, whether it's deep learning or machine learning, you're gonna have some sort of some sort of input.

  • Vector were array, I suppose.

  • But we'll call it a vector.

  • Uh, and that's just gonna have values.

  • So these they're gonna be your features.

  • So this could be anything in the case of how light these features might be, things like, How many planets do we have?

  • How many ships do we have?

  • How many enemies do we have?

  • How far away is enemy number one?

  • How far away is enemy number two?

  • So they need to be some sort of numerical value.

  • You couldn't pass an entity object in this input vector, and then you're gonna have some sort of output.

  • Now, in the case of deep learning, it's probably gonna be an array, and it's going to be some sort of one hot array.

  • In most cases.

  • If it was traditional machine learning, then your your outputs probably gonna need more like a one.

  • A two, a three a four.

  • Uh, something like that, depending on how many choices you have.

  • So let's say with deep learning organise deep learning here.

  • So we're gonna think of the output as this sort of one hot array, which means only one value is one the rest would be zeros.

  • So in my case, we might say, for each value in here that first value is attack, second value is mine.

  • And then the third value might be Explorer or something like that.

  • So in this case, where we've got 010 that would mean we want to mind.

  • So let's mind our own planet.

  • But if instead, the output vector was maybe a one, that would mean attack was hot, so we would choose to attack, for example, so just a really quick, um, overview of what we're gonna attempt.

  • Basically, in order to do machine learning or deep learning, we have to translate everything we have into this sort of structure, where you've got input features and then output choice.

  • So and then, in the case of deep learning, that output choice needs to be some sort of, like Vector, basically a one hot array.

  • So now let's talk about how we can go about doing this.

  • So we have a few options with how light so of the highlights starter, but which I can pull up real quick, which is totally worth checking out.

  • We're not going to be using that for a variety of reasons, but also, um, the way this works is off of replay files.

  • So those little files that you can upload to watch your replace those contained basically all the information from the game.

  • Um, it's basically it's like a log file.

  • You can think of it like a log file.

  • So what the the M L Starter bought does is it reads the log files and then just kind of determines where we should allocate our ships.

  • So this Aye aye, Onley makes that choice of where should the ships be allocated?

  • Um, and it doesn't really do anything else besides that.

  • So there's obviously going to need to be a lot of logic on top of that.

  • But that's totally fine.

  • So you can use a I for choosing your entire strategy and where to go.

  • Or you could use a eye for something really simple.

  • Like, how fast should your ship go?

  • And that's the only thing he used a eye for.

  • So you can use it for literally anything.

  • So what I'd like to do is use a I to choose whether we should attack minor own planet, reminding Empty Planet Just something simple enough.

  • And for now, I'm not gonna use the replay files.

  • But if you are interested using the replay files and you and you still want to check it out, check out the M l starter.

  • But But also, I'm just gonna copy and paste a snippet of code here just for anybody who is interested.

  • Um, based, this is code.

  • And also there put a link in the description because we're just gonna be doing a lot of snippets of code rather than writing everything out here.

  • Otherwise we'd be here for hours.

  • Um, this is a snippet of code to read a replay file again.

  • It's in the description.

  • There's a link to this tutorial in the description.

  • You can get this code, but for whatever reason, with the M L starter.

  • But I couldn't read replay files.

  • Maybe it's like a Windows thing.

  • Um, but the code didn't decompress the game data at all.

  • So I'm not really sure if maybe the stuff that's in the cloud is not compressed.

  • Don't know.

  • Anyway, If you want to read your local files, you definitely need to decompress Izzy STDs.

  • You have to install that as well.

  • I think I don't think that's a standard lied anyway.

  • That's example.

  • In those replay files, they're just basically just these giant Jason files, and they contain here.

  • You can operate through thegame frames.

  • You could get events, you could get information on planet ships, and then you can kind of pour through.

  • This is just some examples of me kind of parsing that data, but again, it's like a log file, so it's really challenged like it's not like you can just read the replay file, mimic it and directly mimic it.

  • You actually you still have to kind of parson, translate that log file.

  • So I think it adds kind of a layer of complexity that can make especially if you're not totally familiar with deep learning.

  • Um, I can make that a little more challenging, I think, to pick up.

  • But maybe I'm wrong.

  • But you can also, Like I said, besides this tutorial, you can go check out their, uh, their M l starter bought as well in, uh, maybe try both.

  • So now, uh, let's go and get started with script.

  • Um, Like I said, I think I'd rather just use the snippets here and explain its most this stuff.

  • We've already gone over, so I would just be wasting time if we're just gonna rewrite the script.

  • So what I'm gonna do?

  • Like I said, it's all have a link in the description for all the code.

  • And then I'm just gonna move it over here and basically just explain it as I go that way.

  • We're not that way.

  • You guys don't have to type it, and I don't have to type it X again.

  • Pretty much all this stuff is stuff we've coded before.

  • It's Hal.

  • I could So I was gonna paste this in.

  • So we're importing that Hallie directory logging to log order dick, because eventually we wanna have a dictionary That for sure retains its order.

  • Uh, numb pie for numb pi thing's random for choosing a random choice and os for making and deleting files.

  • Well, really, Just deleting files.

  • I don't have a few more Constance here.

  • Uh, this is gonna be how many features per entity that we want to track.

  • That's gonna make a little more sense once we get to that point of entities.

  • Percent changed chance.

  • Kind of like before where we had our ships, and we're kind of saving whatever plan we had for our ships.

  • Um, this is the chance that that plan might change.

  • So if a ship is currently attacking, it might get to the point where we're gonna change its plan and make a go mine or something like that.

  • And the finally desired ship count.

  • I'm setting us to 20.

  • Somewhere between 20 and 50 is a good number.

  • 50 seems to time out.

  • So once you get to many ships, your calculations were gonna take too long.

  • So you have two seconds to to generate through olive your ships.

  • So each turn, you have two seconds.

  • So, um, so one option you have is time.

  • How long you're taking.

  • And then once you've taken too long, you just break.

  • But then that means a lot of ships are probably just going to sit there and do nothing, which is not desirable.

  • So instead, what I've decided to do is if we have more ships than however many ships we desire to have, we send the remainder of ships off to their death on and make them attack.

  • So, uh, that's how we're going to kind of keep control of our ship count.

  • There's there's a few different ways that we could handle that best way I'm gonna handle it.

  • So then we're gonna have our typical you know, starting information.

  • So just the name of the game and start our logging information and stuff.

  • Uh, then, just like before ship plans.

  • And like I said, with that percent change chance, you got a 30% chance, basically every frame per ship to change the plans of a ship.

  • Uh, now what I'm gonna do is we're going Thio.

  • If the file exists, we're gonna delete it.

  • So basically, every game we're gonna save all of this player's moves to a file, depending on whatever version number is.

  • So basically, we're gonna have two scripts.

  • The exact same script.

  • It's just gonna be one's gonna be player.

  • One one's gonna be player two.

  • And then whichever player Winds, we're gonna take those winning moves and then we'll use them to train and at least to start these.

  • It's just gonna be totally random.

  • So the both bots will just be making random moves, and then we use those to train, and then you can actually just continue.

  • The iterative process can have to a eyes compete against each other, train based on the winners and continue.

  • As long as you have some degree of chance and randomness, you should find that you you continue to slowly improve.

  • So once we have that, we're ready.

  • Thio ahead and begin that that mean loop.

  • So let's do the wild troop game map.

  • You should already understand that Command Q.

  • Nothing new there.

  • So now, um, the big Three huge crux of this entire program is collecting those features.

  • So there are some features that we can collect without doing it per ship.

  • Um, so paste is in so we can find out all of our team ships we can find out all of the ships, and then we can find out all of the enemy ships.

  • We can do that without doing it on a per ship basis, because all we're trying to figure out is like, how many ships do we have here?

  • And then we can get So how many ships do I have?

  • How many ships does enemy have?

  • And then how many ships total are there?

  • The next things I'm just gonna grab here, we're gonna get our i d.

  • And then we're gonna put least prepare for empty planets, our planets and then enemy planets.

  • And then here, I'm gonna generate through all of the planets.

  • I'm gonna grab their size and then if it is owned, um, I'm sorry if it's not owned, that's an empty planet.

  • So we're gonna save that.

  • So this entire thes dictionaries are gonna be by size.

  • Uh, and so if it's empty, will throw it in there.

  • If, um, if if we are the owner, then we're going to save it to our planets.

  • And then if we're not the owner, but it is owned, then we'll store it to the enemy planets.

  • So then once we have that we can figure out how many planets each player has.

  • So there we have that.

  • And then finally, we can go by the actual sizes themselves.

  • Something's gonna paste that in.

  • And basically all this gives us is it's the K for Kay.

  • So it's Keefer key.

  • The key was the size of the planet.

  • So this just tells us how big are these planets?

  • And then because of sordid, is gonna go from smallest to largest.

  • We actually were going.

  • We might want largest, a smallest planets.

  • So I'm just reversing the list at the very end there.

  • And then once we have all this data, we're ready to actually start iterating through our ships because the rest of stuff are things that we need to calculate on like a ah per ship basis.

  • So, for example, we might want to know how close are the closest five enemies to each individual ship, or how close is the closest planet or so on.

  • So there's a lot of a lot of those kind of questions We actually have to ask that on a per ship basis, so I'll at least start this, um, so's reiterate through if the ship is basically of the ship is docked.

  • Let's skip it.

  • This is questionable whether or not you want to leave it or not, I would test it both ways.

  • I kind of think it's pretty inefficient.

  • Toe, like docking on docking, docking undock.

  • So I didn't leave it in there, but because we're only choosing between three choices.

  • Um, and one of those choices is mine.

  • Empty planet, uh, which is not likely to be an option much past the first, Let's say 100 frames.

  • Uh, it's probably only gonna learn one move, which would be attack.

  • Okay, so So it'll probably wind up with a very aggressive ai ai if you go with this.

  • Whereas if you remove this the day, I would be much more likely to learn other instances where hey, Yeah, we actually can dock, So yeah.

  • Uh, anyway, continuing along, we'll grab the ship, I d and then determine whether or not we want to make a change.

  • So here changes currently false.

  • But if we choose a random manager, that is less than or equal to, um, the percent change chance.

  • So basically, I think we chose 30.

  • So if it's less than 30 30% chance change equals true.

  • And then we'll use that down the line when we actually go to actually pick whatever move we want to make.

  • Okay, Now comes the massive, uh, list of features that we're going to grab.

  • Um, it's a tonic.

  • Oh, but these air pretty much all the same idea.

  • So we're gonna paste it, and then we'll go over it.

  • So entities by distance, this just grabs all the entities by distance.

  • We've done that before, and then we sort the entities by their distance.

  • So whatever is close of, like making this bigger, as if that's gonna help you anyway, um, and then we're gonna sort that by the key, so it'll be closest to furthest.

  • So now the closest enemy planets.

  • Um, this will just be anything that I'm sorry, this is close to empty.

  • This will be anything that is doesn't have an owner, but yet it's still gonna be sorted.

  • And then entities by distance, that distance in the zeroth element, this will be the values.

  • Here are the actual entity.

  • So you could navigate to each value in this list.

  • And then these are simply the distances So we want both Because on, you know, the feed our neural network or any machine learning classifier.

  • Um, we want to know we want scaler values, right?

  • So we want the actual distance.

  • How far is that thing?

  • Where is here?

  • If we say hey, Yeah, we actually want to go to the closest planet, number one or whatever.

  • We also want to be able to know.

  • Okay, What is that?

  • Because we've got the distances, but we also need to know the entity.

  • So then we're just doing the exact same thing for our own planets and then the enemy planets.

  • And then, honestly, we did it.

  • It's the same thing for the team.

  • Ships were grabbing the actual entities, and then we're also grabbing the distances, same order and all That s o then finally, um, yeah, so that's all done.

  • And then we come down here and this is probably this will be the sole slightly different because basically, what we're doing is we're one of our factors that we're gonna pass is gonna be thesis Eyes is right.

  • We've got sizes and distances.

  • Um, if there's gonna be times when like, for example, when the game first starts, We don't have any planets, and our enemy has no planets.

  • Right?

  • So if we don't have those values, we're just gonna populate negative 99.

  • So the distance will be negative.

  • 99.

  • We also are end up doing the same thing for, like, closest empty planets.

  • All these things, like with the distances we do this fix data function, which, actually, I haven't put that up yet, but I'll show it in a second.

  • Um, which again is just gonna do?

  • The same thing is gonna make sure we have is many values is we're expecting because I guess I didn't mention it before.

  • But that input remember, with the input vector, uh, for example.

  • And it had, I don't know, just some numbers in it, Uh, the size of this input vector, at least in most most of the time.

  • Uh, the size of this input vector needs to be exactly the same.

  • We can't change the size.

  • Also, the meaning of this first value and second, fellas, let's say this is how many ships we have.

  • How many ships the enemy has.

  • This 1st 0 with element here needs to always be how many ships do we have the first ith element needs to always be.

  • How many ships is the enemy have so And then let's say this is the closest enemy planet that needs toe always be the closest enemy planet.

  • But what if the enemy has no plan it?

  • Well, we still have to pass a value there.

  • So in this case, we're just gonna pass negative 99.

  • So, while we're up here to let me just go ahead and, uh, I'm gonna paste these two helper functions that I wrote Sochi by value, this just finds the dictionary's key by the dictionary's value.

  • It's kind of a reverse operation.

  • Dictionaries were never really meant to be looked up by their value that were meant to be looked at by their keys.

  • So we kind of need to generate through, Um, But then sometimes we're not gonna have that Any value civil return negative 99 otherwise will return the actual key, which will be, in most cases, that distance.

  • So it's basically we're looking for a distance by an entity, Uh, and then fix data is kind of like what I was saying before.

  • So we're asking to have five features, But many times we won't own fine of planets, for example.

  • So we're saying, Hey, we want to know the distance to our closest five planets per ship that we own.

  • But many times we won't have that.

  • So maybe we've only got one planet.

  • So what we're gonna do here in fixed data is we just pad that dead data out.

  • So we're going to say here if if this fails, we're just gonna say zero.

  • Let's say if we had no data at all, we're just gonna say zero.

  • Um, but which would pressure It's a price.

  • Should be like a negative 99 anyway, regardless, um, show must go on.

  • Um, if there is a first value will upend that first, it's basically just gonna had that value out.

  • And let's say there's three values, but we need five values.

  • Is if it's going to take that that third value and patted out that way again because we always have to have fixed size of that input vector.

  • Okay, so now we're gonna come back down to where we were creating this.

  • That's the entity lists.

  • Now, what we're ready to do is actually create that input vector.

  • So I'm gonna pace a little bit of code first.

  • That So basically what?

  • This is going to do this because entity lists these are lists, whereas the input vector needs to just be flat.

  • Right?

  • So these each of these is a list of five values.

  • Basically, um Well, actually, it's a list of quite few values.

  • It'll be at least five because we're running fixed.

  • Date on it.

  • But it could, in theory, be many, many more.

  • Um, so we're gonna do that?

  • Uh, then we got our input vector.

  • And then we're gonna generate over this list, which is a list of lists, basically.

  • And then for each element in that list, up to however many features we require, we're gonna upend them to the input vector.

  • Soren Pit Vector is gonna have the five closest empty planet distances.

  • It's gonna have the five closest my planet distances five closest enemy planet distances and so on.

  • That's just going to keep going.

  • Now, At the end of all that, we also want a few, uh, more stats.

  • So we're gonna go ahead and also bring in the following.

  • So we're gonna add in How many ships do I have?

  • How many ships is my enemy have?

  • How many plans do we have?

  • How many are empty planets?

  • And then how many plants does our enemy have?

  • Okay, s so quite a bit of data.

  • Um, honestly, all the way up to this point, all we've been doing is collecting features.

  • We haven't done anything.

  • We're just figuring features out.

  • And then also, some of these features like planet size, for example, I've almost basically never seen a planet really get depleted.

  • And actually, I'm not 100% if someone can comment below, if you actually get Maur docking spots for a larger planets, I can't remember if you do or not.

  • Um, anyways, so planet size may or may not be important, right?

  • And then there's probably a bunch of important factors that we actually could continue adding to this.

  • So this is just meant to be a example.

  • But anyways, we've calculated all of our features, and now we're going to calculate the Output vector, which at this stage is just going to be random.

  • Eventually, we're gonna have our neural network actually picked the output.

  • But for now, random so if the ship count is greater than the desired ship count or output Vector, we're going to say is basically what we're gonna say is, if, um if zero with element is a one.

  • So, um, in fact, let me just do this.

  • Let's say we'll call this, um attack, and that would be a 100 Okay, So if we have more ships than we hoped to have, then we're going to say, OK, the APA victor starts off as three by zero.

  • So that's just gonna be a 000 And then we're going to say the output vector zero with element is equal to a one, which means 100 If that's the case, then we're going to ship plans.

  • Whatever that ship ideas, uh, is that output vector?

  • Then, um, I need this now if that ship doesn't actually have a plan.

  • So if this isn't the case and that ship doesn't have a plan or change is true, we want to pick a new plan.

  • So the output vector again, it's just that three by zero.

  • And then, um, here, we're just gonna pick a random choice.

  • That's it.

  • So 01 or two.

  • A random option between those three options will be a one.

  • And then boom, we append that value.

  • Now, uh, if all else fails, um, So basically, if there was no change but we don't have more ships that were supposed to have, then we'll just continue with whatever the plan for this ship waas When we go to add a neural network and once we've trained it, the only difference is going to be basically this code here.

  • It's just the neural network will choose the output vector rather than the output vector being random.

  • Okay, now we actually have to make the choice.

  • So copy this.

  • That's where I want it.

  • Um, so if the if the art max of the output vector is the zero with elements, so again, we've already talked about it, but that would mean this.

  • So if you dont a numb pie Art Max's trying to find the element.

  • The index basically with the maximum value in this case, it's the zeroth element.

  • So if the art max zero, that means we want to attack an enemy ship.

  • So we're going to attack.

  • We're gonna try to find the closest enemy ship.

  • Now, there's gonna be times when we least on the enemy ship if there's zero enemy ships, Uh, the game is over.

  • Ah, so this probably isn't necessary.

  • I don't know if it goes one more frame after the cause.

  • You last thing you'd want to do is, like, win the game.

  • But time out Because you made in there.

  • So anyway, I would still leave that there.

  • But at least like on the planets, for example, we need to make sure that the planets aren't that kind of integer value as when we go to pad them.

  • But anyway, So, uh so, yeah, if if that was the art Max, then we attack.

  • Now we're going to do the minor planet, and this one is actually a little longer.

  • Uh, because we need to have, like, something to fall back on, just in case we make a mistake.

  • So taste okay?

  • And this is why, uh, we're not writing all this out.

  • So if the art Max is one, what do we want to d'oh?

  • Well, that means we want mine one of our own planets.

  • So then we're gonna check, uh, if that planet is an entity and not an end that we just used a pad.

  • Then the target will be the closest planet.

  • Um, and then we have to make this check.

  • So we have to ask if that planets, um, if the number.

  • So the length of the docked ship I d.

  • S is, uh, less than the number of docking spots that are available.

  • Then we can dock.

  • But there's gonna be times when that planet is full.

  • We can't actually docket that planet.

  • So when that's the case else attack.

  • So we just go on the attack.

  • Um, one option to consider moving forward to is, if this is tow happen, you might want to change your random vector.

  • So because this wasn't actually an option, right?

  • And so any a I that learns what we can try to mine, But then we just fall back on attack.

  • Really?

  • That should be in it on attack option.

  • Not a proper chose to mine option anyway, uh, and then we attack.

  • So, um well, looks like I caught me too much there.

  • Well, if, uh, no.

  • Anyway, um So if if our closest planet there's more here than I thought, Yeah, if if our closest planet is if we can mine it, then we mine it.

  • Otherwise we're going to attack.

  • But if this turns out toe not be like if the closest owned planet, if we don't have a closest owned planet, then we go and fall back to the closest empty planet, and then we attempt to do the closest empty planet.

  • But if that fails, then we attack.

  • So we just have these kind of fall back.

  • So you have two options here.

  • You could one just change your vector choice.

  • If you fall back on one of these fail safe's or you could not have any of the failsafe sw er and then and then hopefully your model might be a little more accurate or something like that.

  • But I'm gonna have him there.

  • Then finally, uh, if if we get that kind of third option, you make sure I get the right amount of tabs.

  • 1234 Tabs over 1234 tabs over paste.

  • And just for the record, if you go on copy and paste, it could from python program Internet, like at the bottom is the full script.

  • So you don't have to do these chunks like this.

  • So now if the art max of the output vector is the is to, uh, meaning the third option, uh, we're gonna mind the empty planet, and this is basically the same kind of logic.

  • First, it tries to mind the closest empty planet.

  • If that fails, for whatever reason, we're just gonna go on attack, okay?

  • And then finally, we just kind of end and the code paste in and and let me make sure we don't have any syntax air here, okay?

  • At least when I'm the syntax air.

  • So, um, we're going to do now is we're gonna go to the next tutorial, which will be taking this pot will make its second version two.

  • And then we're gonna write code that will basically have these two a eyes compete against each other.

  • And then we'll take the winner.

  • Save that data and repeat.

  • And basically, what we want to do is write a script that will just automatically run these games locally, like a bunch of times saving whoever the winner was in all that.

  • So that is what we're gonna be doing in the next tutorial.

  • If you have questions, comments, concerns, whatever, feel free to leave them below.

  • If you've got suggestions about better factors to use or any of the factors that we use that don't really make any sense or whatever, uh, feel free to let us know below, otherwise I will see you in the next tutorial.

what is going on?

Subtitles and vocabulary

Click the word to look it up Click the word to find further inforamtion about it