-: Hello and welcome to this Python tutorial.
All right, it's a very quick tutorial today
to make the score function,
and so basically, this function will just compute the score
on the sliding window of the rewards,
and so basically, we will very simply compute the mean
of all the rewards in the reward window.
So this will be very simple.
Let's do this now.
We're gonna make this new function
that we're gonna call score.
And the score function will just take the argument self
because basically we don't need anything.
We need to take self
because, of course, we will take self.rewardWindow.
So just self.
And then colon and there we go.
It's gonna take one line of code.
So we wanna compute the mean
of all the rewards in the reward window.
So that's basically the sum of all the rewards
in this reward window
that are between -1 and +1
divided by the total number of elements in this window.
So let's do this.
We're directly going to return that.
So I'm starting with return.
And so we need to take the sum
of all the rewards in the reward window,
and to do this, we simply need
to take the reward window itself
and so I'm inputting here self.rewardWindow.
And so very simply,
this will sum all the elements inside rewardWindow.
So that's pretty practical.
And then to get the mean,
we need to divide this sum
by the number of elements in the rewardWindow,
and to get the number of elements,
well, we need to take the len function,
and then we take our rewardWindow again.
There it is.
But now we just need to be careful with something.
It's that len self.rewardWindow is a denominator
and this must absolutely not be equal to zero.
No matter what, we need to avoid this
and to make sure that the denominator here
is not equal to zero.
We're gonna add this safety trick.
We're gonna add here a plus one
so that len self.rewardWindow plus one
will never be equal to zero.
If the denominator here is equal to zero,
this will crash your system.
So we must avoid it,
and that's totally fine to add a plus one.
We will still get a good measure in the score.
All right, perfect.
And so that's all.
We have our score function,
which will give us the mean of the rewards
in the signing window.
All right, now let's move on to the next function,
which is the save function
that will save your model,
that is save the brain of your core
so that you can then be able
to reuse it by loading it with another function
that we'll make after the save function.
So that's really practical to have this save trick,
save function to save your models
in case you want to reuse them
for any kind of purpose where they can be useful.
So that's what we'll do in the next tutorial.
And until then, enjoy AI.