Skip to content

Instantly share code, notes, and snippets.

@CerebralMastication
Created January 4, 2011 04:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CerebralMastication/764370 to your computer and use it in GitHub Desktop.
Save CerebralMastication/764370 to your computer and use it in GitHub Desktop.
segue example
estimatePi <- function(seed){
set.seed(seed)
numDraws <- 1e6
r <- .5 #radius... in case the unit circle is too boring
x <- runif(numDraws, min=-r, max=r)
y <- runif(numDraws, min=-r, max=r)
inCircle <- ifelse( (x^2 + y^2)^.5 < r , 1, 0)
return(sum(inCircle) / length(inCircle) * 4)
}
seedList <- as.list(1:1e3)
require(segue)
myCluster <- createCluster(20)
myEstimates <- emrlapply( myCluster, seedList, estimatePi )
stopCluster(myCluster)
myPi <- Reduce(sum, myEstimates) / length(myEstimates)
format(myPi, digits=10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment