A Markov chain is a mathematical system that undergoes transitions from one state to another on a state space in a stochastic (random) manner. Examples of Markov chains include the board game snakes and ladders, where each state represents the position of a player on the board and a player moves between states (different positions on the board) by rolling a dice. An important property of Markov chains, called the Markov property, is the memoryless property of the stochastic process. Basically what this means is that the transition between states depends only on the current state and not on the states preceding the current state; in terms of the board game, your next position on the board depends only on where you are currently positioned and not on the sequence of moves that got you there. Another way of thinking about it is that **the future is independent of the past, given the present**.

# Monthly Archives: January 2014

# Markov clustering

The Markov Cluster (MCL) Algorithm is an unsupervised cluster algorithm for graphs based on simulation of stochastic flow in graphs. Markov clustering was the work of Stijn van Dongen and you can read his thesis on the Markov Cluster Algorithm. The work is based on the graph clustering paradigm, which postulates that natural groups in graphs (something we aim to look for) have the following property:

A random walk in G that visits a dense cluster will likely not leave the cluster until many of its vertices have been visited.

# Making symmetric matrices in R

A quick short post on making symmetric matrices in R, as it could potentially be a nasty gotcha. So in R, there are two functions for accessing the lower and upper triangular part of a matrix, called lower.tri() and upper.tri() respectively. Let me illustrate:

#make a small 10 by 10 matrix small <- matrix(rep(0,10*10), nrow=10) small [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 0 0 0 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 0 0 0 0 0 [3,] 0 0 0 0 0 0 0 0 0 0 [4,] 0 0 0 0 0 0 0 0 0 0 [5,] 0 0 0 0 0 0 0 0 0 0 [6,] 0 0 0 0 0 0 0 0 0 0 [7,] 0 0 0 0 0 0 0 0 0 0 [8,] 0 0 0 0 0 0 0 0 0 0 [9,] 0 0 0 0 0 0 0 0 0 0 [10,] 0 0 0 0 0 0 0 0 0 0 upper.tri(small) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [2,] FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [3,] FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [4,] FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE [5,] FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE [6,] FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE [7,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE [8,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE [9,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE [10,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE lower.tri(small) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [2,] TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [3,] TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [4,] TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [5,] TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE [6,] TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE [7,] TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE [8,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE [9,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE [10,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE

# Getting started with Shiny

Shiny is a package from RStudio that makes it incredibly easy to build interactive web applications with R. Have a look at some of the applications built using Shiny and perhaps you'll be as impressed as me. I will set up a local Shiny server on Ubuntu (12.04) running under VirtualBox. You don't actually need to install the server, to build Shiny applications, however some day I would like host my own Shiny server with a bunch of applications that I've built. To get started, let's check out the official tutorial on using Shiny. Fire up R and install the package:

install.packages("shiny") library(shiny) #run the first example runExample("01_hello")

*A web browser screenshot of what you would see when you run the example*.