Skip to main content


Showing posts from April, 2014


I have always loved symmetry in photography. The picture above was created in Photoshop simply by coping and rotating certain parts. See SchlockySymmetry for other symmetrical photos. Recently, I stumbled upon an article in R-bloggers that used abind and biOps for some simple image manipulation. I thought it would be fun to perform some of the tricks mentioned in the article to achieve the picture above.
R Code:#Image processing#Read Original Image x <- readJpeg("Boudha.jpg") plot(x) dev.copy(png,filename="original.png",width=2048,height=1206); (); #copy pixels from left to right and mirror y <- imagedata(abind(x[,1:(ncol(x)/2),], x[,(ncol(x)/2):1,] , along=2)) plot(y) dev.copy(png,filename="halfmirror.png",width=2048,height=1206); (); #copy all pixels and mirror rows z <- imagedata(abind(y[1:(nrow(x)),,], y[(nrow(x)):1,,] , along=1)) plot(z) dev.copy(png,filename="final.png",width=2048,height=1206); ();


"Little boxes on the hillside,
Little boxes made of ticky tacky,
Little boxes on the hillside,
Little boxes all the same.
There's a green one and a pink one 
And a blue one and a yellow one,
And they're all made out of ticky tacky
And they all look just the same."


The Zorganian Republic has some very strange customs. Couples only wish to have female children as only females can inherit the family's wealth, so if they have a male child they keep having more children until they have a girl. If they have a girl, they stop having children. What is the ratio of girls to boys in Zorgania?
The ratio of girls to boys in Zorgania is 1:1. This might be a little counter-intuitive at first. Here are some ways of tackling this problem. 1. Monte Carlo Simulation: Although, Monte Carlo simulation does not necessarily show why the result is 1:1, it is appropriate because of the very counter-intuitive nature of the problem. At the very least, it helps us see that the result is indeed 1:1. Therefore, this is a good start.
The following R code estimates the probability of a child being a boy in Zorgania. 
couples <-100000 boycount <-0for (i in1:couples){ # 0: boywhile (sample(c(0,1),1) ==0) { boycount=boycount+1 } } probability <- boycount/(co…


This is the naive/brute-force implementation of the Mandelbrot Set plotting. I just followed the algorithm.  
# Plotting the Mandelbrot Set # length of sequence for real and imaginary parts of complex numbers length <-1000# sequences for real and imaginary partsreal= seq(-1.8,0.6, len=length) imaginary= seq(-1.2,1.2, len=length) result <-matrix(nrow= length, ncol= length) for (i in1:length) { for (j in1:length) { result[i,j]=inmandelbrotset(complex(real= real[i], imaginary= imaginary[j])) } } image(result, axes=FALSE)
# function that checks if a point E mandelbrot setinmandelbrotset<-function(c) { dwell.limit <-2048 z <-0for (i in1:dwell.limit) { z <- z **2+ c if (Mod(z) >2) { return(FALSE) } } return(TRUE) }
Adding colors: We now have a Boolean matrix that records if a point is in the Mandelbrot Set. Since the matrix can only have two values : true or false, thus far, we have only been able to plot read an…


I used R for two of my classes in college: Probability and Statistics and Stochastic Probabilities. During that time, I was in reverence with the way it handled lists. However, I did not use it much after getting done with those classes. I have decided to relearn it.

In this post, I will start off with some simple programs. After ascertaining some comfort with the syntax and semantics of R, I will try some complex ones. Also, since I am in the process of learning myself, if you decide to use some of these codes, just keep in mind that there might be several better ways of doing the same thing.
1. Dice Rolls: Probability of getting a side f number of times in n dice rolls# DiceRolls.R# Probability of getting a side f number of times in n dice rolls#inputs side <- 4 f <- 2 n <- 5# Binomial Distribution# using R's function for binomial distribution # where P(X=k) probability <- dbinom(frequency, n, 1/6) probability # Monte Carlo Method rep <- 10000# Number of repet…


These are screenshots of some of my very first apps. They did not do much. However, they build my appreciation towards Android development.