Hello and welcome to this fight and to torero.
All right now we're going to make the push function which will do two tasks.
First it will depend a new transition or a new event in the memory and then second it will make sure
that the memory has always 100 transitions.
I'm seeing 100 because we gave the example of 100 events in the previous tutorial but in fact this will
be much more than 100.
This will be rather maybe ten thousand one hundred thousand we'll see.
But anyway this value will be the capacity.
All right.
So let's make this push function.
So as usual we start with death to define a new function and then we give a name to this function so
we call it push and this function will have two arguments.
First as usual self that refers to the object and the next one.
Why do you think that will be.
Well remember this push function will be used to append a new event into memory.
We already have the memory.
So what we need now is a variable is an event that will be our arguments or input and we will bend this
input into memory which is a variable of the object.
All right.
So event you can actually call it event or transition.
That's the same and you will see in the next code sections.
What exactly is this event.
What form it has.
Actually I can tell you now this event this transition that we're adding to the memory is a total of
four elements.
The first one is the last state that is esty.
The second one is the new state that is Estep us one.
The third one is the last section that is 80.
The action that was displayed and the fourth one is the last word the last word obtained.
That is our.
So that's exactly the form that this event will have.
All right.
And that's all we just need the event because we just want to pin the event to the memory and then making
sure that the memory has capacity elements.
All right so now let's go inside the function.
So the first thing we'll do is attend to you then to the memory.
And that's very simple because we're going to use the append function.
So that will be direct.
And when we use the append function we must start with the list to which we want to spend something
and this list is of course memory.
So we start with memory and since memory is a variable of the object we start here with self taught
memory that we go to set up memory and then we have to do that and then the open function which is the
first one.
So it bent and inside the open function we input what we want to spend to memory which is of course
our evidence.
So even here.
And that will append the new event composed of the last eight new state last action and last word to
the memory.
All right.
So that's the first thing done.
And then the second thing we need to do is make sure that the memory always contains capacity elements.
So let's say capacity is now 100000.
That's probably the capacity you will choose because then one million elements might make the train
slow.
So let's say 100000.
Now we're going to make sure that our memory always contains 100000 transitions 100000 events and never
more.
So of course at the beginning it will have one then two and three but then once it reaches 100000 events
Well it will always have 100000 events.
So to make sure of it we simply need to make an IF condition with this upper bound that we don't want
to go over.
So if we get the idea that we'll use here is that if we go over the limit Well we will delete the first
transition the first event of the memory and therefore we're going to take the lead function to take
the length of the memory that is the number of elements in the memory.
So here in the len function we can put self memory to memory.
So if the number of elements of that memory is larger than the capacity well in that case we will remove
the first element to make sure that the memory always has the same number of capacity elements and to
do the first element there is nothing more simple we are going to use another function which is the
tell byte centric so well and therefore we want to remove the first transition which is the oldest transition
in the memory because the last transitions are the ones that we are tense and therefore that's the new
transitions.
So the first transitions are the oldest one.
And so here we want to delete self taught memory and records and we take the first element of the memory
which has an zero itself that memory zero Now interesting I have a little warning which says that there
is an undefined capacity.
That's because the capacity here is not the input that must be the capacity variable attached to the
object and therefore you will need to add a self self that capacity.
And now the warning has come.
Now you understand even more the use of self that's really to refer to the object to take the capacity
of the object that will be created that is an instance of the replay memory class.
All right.
So we're done with this push function.
And so now we can move on to the next function which is the simple function which will take some random
samples from this memory at the last capacity elements and doing this will improve a lot.
The deep cleaning process.
All right.
So let's do this in the next tutorial.
And until then I.