{"items":["5fda4e5bfb427c00177535cf","5fda4e5bfb427c00177535ce","5fda4e5bfb427c00177535cd"],"styles":{"galleryType":"Columns","groupSize":1,"showArrows":true,"cubeImages":true,"cubeType":"max","cubeRatio":1.7777777777777777,"isVertical":true,"gallerySize":30,"collageAmount":0,"collageDensity":0,"groupTypes":"1","oneRow":false,"imageMargin":5,"galleryMargin":0,"scatter":0,"rotatingScatter":"","chooseBestGroup":true,"smartCrop":false,"hasThumbnails":false,"enableScroll":true,"isGrid":true,"isSlider":false,"isColumns":false,"isSlideshow":false,"cropOnlyFill":false,"fixedColumns":0,"enableInfiniteScroll":true,"isRTL":false,"minItemSize":50,"rotatingGroupTypes":"","rotatingCropRatios":"","columnWidths":"","gallerySliderImageRatio":1.7777777777777777,"numberOfImagesPerRow":3,"numberOfImagesPerCol":1,"groupsPerStrip":0,"borderRadius":0,"boxShadow":0,"gridStyle":0,"mobilePanorama":false,"placeGroupsLtr":false,"viewMode":"preview","thumbnailSpacings":4,"galleryThumbnailsAlignment":"bottom","isMasonry":false,"isAutoSlideshow":false,"slideshowLoop":false,"autoSlideshowInterval":4,"bottomInfoHeight":0,"titlePlacement":["SHOW_ON_THE_RIGHT","SHOW_BELOW"],"galleryTextAlign":"center","scrollSnap":false,"itemClick":"nothing","fullscreen":true,"videoPlay":"hover","scrollAnimation":"NO_EFFECT","slideAnimation":"SCROLL","scrollDirection":0,"scrollDuration":400,"overlayAnimation":"FADE_IN","arrowsPosition":0,"arrowsSize":23,"watermarkOpacity":40,"watermarkSize":40,"useWatermark":true,"watermarkDock":{"top":"auto","left":"auto","right":0,"bottom":0,"transform":"translate3d(0,0,0)"},"loadMoreAmount":"all","defaultShowInfoExpand":1,"allowLinkExpand":true,"expandInfoPosition":0,"allowFullscreenExpand":true,"fullscreenLoop":false,"galleryAlignExpand":"left","addToCartBorderWidth":1,"addToCartButtonText":"","slideshowInfoSize":200,"playButtonForAutoSlideShow":false,"allowSlideshowCounter":false,"hoveringBehaviour":"NEVER_SHOW","thumbnailSize":120,"magicLayoutSeed":1,"imageHoverAnimation":"NO_EFFECT","imagePlacementAnimation":"NO_EFFECT","calculateTextBoxWidthMode":"PERCENT","textBoxHeight":26,"textBoxWidth":200,"textBoxWidthPercent":65,"textImageSpace":10,"textBoxBorderRadius":0,"textBoxBorderWidth":0,"loadMoreButtonText":"","loadMoreButtonBorderWidth":1,"loadMoreButtonBorderRadius":0,"imageInfoType":"ATTACHED_BACKGROUND","itemBorderWidth":0,"itemBorderRadius":0,"itemEnableShadow":false,"itemShadowBlur":20,"itemShadowDirection":135,"itemShadowSize":10,"imageLoadingMode":"BLUR","expandAnimation":"NO_EFFECT","imageQuality":90,"usmToggle":false,"usm_a":0,"usm_r":0,"usm_t":0,"videoSound":false,"videoSpeed":"1","videoLoop":true,"jsonStyleParams":"","gallerySizeType":"px","gallerySizePx":1000,"allowTitle":true,"allowContextMenu":true,"textsHorizontalPadding":-30,"itemBorderColor":{"themeName":"color_12","value":"rgba(230,230,230,0)"},"showVideoPlayButton":true,"galleryLayout":2,"calculateTextBoxHeightMode":"MANUAL","targetItemSize":1000,"selectedLayout":"2|bottom|1|max|true|0|true","layoutsVersion":2,"selectedLayoutV2":2,"isSlideshowFont":true,"externalInfoHeight":26,"externalInfoWidth":0.65},"container":{"width":300,"galleryWidth":305,"galleryHeight":0,"scrollBase":0,"height":null}}

# Random Walks

With this post, I want to introduce the concept of a random walk and point out some their many real-world applications.

Say you find yourself at the corner of a street block and decide to randomly move north, south, east, or west. After moving one block, you find yourself at the corner of a new block and industriously continue this process. This idea is the concept behind a random walk, particularly, one in two dimensions. Below, I animate some 100 step random walks in black fading them into red as they finish.

The stochasticity and spatial progression of a random walk makes them amenable to a variety of practical models in science. For example, random walks are used to model diffusion arising from effectively randomly directed elastic collations between many interacting particles—known as Brownian motion. The animation below shows an example of this phenomena by modeling the motion of a larger, yellow, particle being bombarded by many smaller ones and tracking the resultant motion.

This same principle is seen macroscopically examining diffusion of ink in water.

Naturally, we expect diffusion to be quicker if the surrounding particles are comparatively higher in energy. The above GIF illustrates this concept as temperature of the water in the right glass is higher than that of the left, resulting in the ink's faster diffusion.

In biology, random walks can be used to model the nearly random motion of bacteria as they search for food, a phenomenon dubbed *chemotaxis*. I say 'nearly random' because, in this case, the random walk is biased toward a particular direction. Loosely speaking, the food can be thought of as radiating particulates which bacteria have evolved to become attracted to, which effectively bias their walk in a specific direction. This process is animated below with the effective 'food source' at the center of the frame.

In many of these cases, it would be nice to know how far away from the origin a random will take you. Of course, we can never say with certainty the distance of a random walk, but we make an educated guess rooted in statistics. Quoting a result, it can be shown that the distance of a random walk is proportional to the square root of the number of steps taken. Simply put,

where *N* is the number of steps taken in the walk.

Now, let’s investigate these random walks and see if we can computationally recover some theoretical results. Rather than updating the figure after each step, as I had done in my first animation, I'll display the progression of the walk at certain step intervals to expedite the animations. The black lines will trace the current walk while the faded red lines show a history of previous walks. As walks accumulate, the most frequently visited areas will become opaquer while those rarely touched will remain translucent.

(Top) An animation of a ten 1,000 step random walks updated every 50 steps. (Bottom) An animation of ten 10,000 step random walks updated every 500 steps.

Notice, in both the above cases the areas near the beginning of the walk are visited more frequently than those at the boundaries. This is of course expected, as farther reaching walks are less likely to occur than those moving about the starting point.

As a quantifiable measure, we can examine the distance of the random walk observing its agreement with theoretically predicted results. To illustrate this, I’m affixing a graph which dynamically updates with each walk iteration displaying the distance travelled from the origin of each walk (red), the cumulative average distance of all previous walks (blue), and the theoretical prediction for the average distance (black). Moreover, rather than updating the graph at discrete step intervals, I’ll only flash the path of each walk in black as they finish.

100 step random walks

1,000 step random walks

10,000 step random walks

Regardless of the number of steps, we see the distance from the origin converging onto the theoretically predicted results in all cases. Furthermore, with the longer random walks, the opaque areas near the origin are evidently seen as more frequently visited then those on the outskirts.

As a final thought, there's a theorem which states that random walks starting from the origin in one and two dimensions are guaranteed to return to the origin in some finite number of steps. More generally, every walk in these lower dimensions is eventually guaranteed to visit every single point in space. This recurrence, however, is not true in higher dimensions, giving rise to the commonly quoted phrase regarding regarding random walks attributed to Shizuo Kakutani:

*"A drunk man will find his way home, but a drunk bird may get lost forever." *