WEBVTT

00:01.240 --> 00:01.840
Hi everyone.

00:01.840 --> 00:02.560
Welcome back.

00:02.560 --> 00:03.320
In this lecture.

00:03.320 --> 00:07.000
Let's understand the windows sliding gatherer in detail.

00:07.240 --> 00:13.920
This gatherer is quite interesting because it helps us create overlapping groups or sliding windows

00:13.920 --> 00:15.960
over the elements of the stream.

00:15.960 --> 00:23.240
When we say overlapping windows, it means that each new window shares one or more elements with a previous

00:23.240 --> 00:23.600
one.

00:24.080 --> 00:30.480
So unlike windows fixed, which forms independent, non-overlapping batches, windows slide move the

00:30.480 --> 00:36.360
window forward by one element at a time, keeping part of the previous window.

00:36.560 --> 00:42.040
This allows us to continuously observe how the data evolves element by element.

00:42.040 --> 00:47.600
For example, in this case we have a stream of four elements A, B, C, and d.

00:47.800 --> 00:54.800
If we apply windows sliding to, this will produce the following windows AB, BC and CD.

00:55.040 --> 01:02.080
You can see that from the first and second window, you have a B element that is being shared in both

01:02.080 --> 01:02.760
the windows.

01:02.800 --> 01:04.720
This is called overlapping windows.

01:04.960 --> 01:13.200
This concept is achieved using the windows sliding gatherer, so this behavior is extremely useful when

01:13.200 --> 01:20.160
you want to analyze sequences or patterns where context matters, not just individual elements.

01:20.160 --> 01:26.640
For instance, if you're analyzing movie ratings over time, you can take every 2 or 3 consecutive movies

01:26.640 --> 01:29.280
and calculate their average rating.

01:29.280 --> 01:33.120
This gives you a sense of how ratings are changed gradually.

01:33.240 --> 01:37.680
Instead of just looking at the movie, which is one movie at a time.

01:38.120 --> 01:43.480
In summary, Windows Sliding helps us process data continuously with overlapping groups.

01:43.480 --> 01:50.240
This is perfect for real time analytics, running averages or sequential comparisons in streams.

01:50.240 --> 01:53.560
Let's go back to the code and explore this particular functionality.

01:55.520 --> 01:58.200
So I'm back in the Stream Gatherer demo class.

01:58.200 --> 02:03.360
So in this case I'm going to comment out the windows sliding function call so that we can actually look

02:03.400 --> 02:06.280
at the data of windows sliding in detail.

02:06.320 --> 02:07.640
So let's go back to this one.

02:07.680 --> 02:09.280
It's going to be the same concept.

02:09.360 --> 02:13.800
So in this case we are going to be doing movie stream dot stream.

02:14.000 --> 02:19.680
And then we are going to be limiting to only five movies because we have 12 movies in the collection.

02:19.840 --> 02:24.400
So using five will help you look at the data in a much clearer way.

02:24.440 --> 02:27.560
So in this case I'm going to be doing the dot gather.

02:27.560 --> 02:33.080
So I'm going to be calling the gatherers dot windows sliding okay.

02:33.120 --> 02:38.880
And then I'm going to be giving the sliding window as two value so that you know what movies are going

02:38.880 --> 02:40.560
to be part of each and every window.

02:40.640 --> 02:42.720
So and then I'm going to be printing this value.

02:42.720 --> 02:46.600
So I'm going to change this one to be a sliding window.

02:46.720 --> 02:48.560
So in this case we have a stream of movie.

02:48.560 --> 02:53.960
As you can see when it when this one happens you have a stream list of movies of size two.

02:54.320 --> 02:56.200
Let me rename this one to be Sliding Window.

02:56.240 --> 02:56.880
There you go.

02:57.000 --> 03:02.280
And then we are going to be accessing those two movies and then printing them over here.

03:02.520 --> 03:02.920
Okay.

03:03.080 --> 03:08.290
Now let's execute this function and then look at the result to get a clearer picture of what this sliding

03:08.290 --> 03:09.450
window creates.

03:09.610 --> 03:12.210
Go to the top and then execute this function.

03:12.250 --> 03:12.570
There you go.

03:12.610 --> 03:15.490
So now you can see that the sliding window is created.

03:15.530 --> 03:19.010
As you can see, we have limited the movie to five right.

03:19.050 --> 03:20.210
Let's go back to the code.

03:20.250 --> 03:22.170
So in here we are limited that to five.

03:22.410 --> 03:24.970
So basically how many windows it created.

03:24.970 --> 03:27.450
1234.

03:27.650 --> 03:28.170
Right.

03:28.210 --> 03:31.330
And if you take a look at it this is the first window which is The Godfather.

03:31.530 --> 03:33.610
And then Shawshank Redemption.

03:33.610 --> 03:37.410
In the second window you see that same movie that is being present.

03:37.570 --> 03:41.090
The last movie in the previous window is a first element in the next window.

03:41.250 --> 03:44.690
And then we have the pulp function, and the same is being repeated.

03:44.690 --> 03:47.970
The last movie in the previous window is the first element in the next window.

03:48.090 --> 03:51.290
So in this case let's go ahead and remove this limit.

03:51.410 --> 03:51.730
Okay.

03:51.770 --> 03:53.850
And then I'm going to change this to four.

03:54.170 --> 03:55.330
Let's see what happens.

03:55.530 --> 03:57.050
Let's rerun the program again.

03:57.210 --> 03:57.410
Okay.

03:57.450 --> 03:58.050
So there you go.

03:58.090 --> 04:00.890
We have this whole sliding window created.

04:01.010 --> 04:04.890
So in this case so you have the first window with four elements.

04:04.890 --> 04:07.970
In the next window you can see that the top.

04:08.250 --> 04:14.050
The last three elements are the first three elements in the next window, so it's always the first element

04:14.050 --> 04:15.890
in the first window is not included.

04:16.050 --> 04:18.090
The rest of the elements are going to be part of this one.

04:18.090 --> 04:19.770
The same concept is repeated.

04:19.810 --> 04:23.850
The last three in the top window is the first three in the next window.

04:23.850 --> 04:30.450
So this concept is called window sliding, where we create overlapping windows of specific size.

04:30.690 --> 04:34.810
And each window shares n elements with a window.

04:34.810 --> 04:42.610
So that means it's going to be sharing the first elements or first windows N elements to the next window.

04:42.610 --> 04:44.650
So in this case if you have to think about it.

04:44.810 --> 04:46.810
So here we have four elements right.

04:46.810 --> 04:51.250
And the next window is going to be holding on n minus one which is four minus one.

04:51.250 --> 04:52.690
In this case the three elements.

04:52.690 --> 04:54.370
That's what we see over here.

04:54.370 --> 04:57.690
So this is all about the window sliding gatherer.

04:57.810 --> 05:04.530
If you have a use case where you have to do a trend analysis, window sliding is a very handy operator

05:04.530 --> 05:06.170
to use for that use case.

05:06.170 --> 05:07.610
This marks the end of this lecture.

05:07.610 --> 05:08.610
Thank you for watching.
