Blog Archives

Parallelizing Voting simulation

March 1, 2012
By
Parallelizing Voting simulation

Last week I have compared synchronous and asynchronous implementation of NetLogo Voting model. An interesting afterthought is that synchronous model implementation can be easily made much faster using vectorization.The two versions of the Voting synchr...

Read more »

Synchronous vs. asynchronous agent activation example

February 24, 2012
By
Synchronous vs. asynchronous agent activation example

This time I have implemented NetLogo Voting model to verify how agent activation scheme influences the results.The code executing the simulation is given below. It simulates two types of voter preferences encoded as 1 and -1. In this way...

Read more »

Generating directed Watts-Strogatz network

February 11, 2012
By
Generating directed Watts-Strogatz network

There are two limitations of Watts-Strogatz network generator in igraph package: (1) it works only for undirected graphs and (2) rewiring algorithm can produce loops or multiple edges.You can use simplify function of such a graph, but then number of ed...

Read more »

Implementing Circles example

February 4, 2012
By
Implementing Circles example

This week I reimplemented part of Conic Sections 1 model from NetLogo. In the model turtles seek to to be in target distance from center.My code takes only one center point, so only circles can be obtained. Apart from turtle location plot giv...

Read more »

Replicating NetLogo Fire model

January 27, 2012
By
Replicating NetLogo Fire model

While preparing for the new semester I have started reimplementing standard NetLogo examples in R. The first is Fire model.The simulation in R is presented here:# Forest matrix trees encoding:# 3 – green, 2 – burning, 1 – burnt, 0 – no treesimu...

Read more »

Simulating average height of a random binary search tree

January 22, 2012
By
Simulating average height of a random binary search tree

Recently on Stack Overflow I have found a discussion on Average height of a binary search tree. The problem has been solved analytically, see for example Reed (2003). However, I was intrigued by one of the answers that presented a simulation ...

Read more »

Exercise in grImport

January 13, 2012
By
Exercise in grImport

Last week I used grImport for the first time. I decided to try perform another exercise using it. The task was to add voivodeship division of Poland.Standard R maps do not contain such a division. I have found it on r-forge in package  m...

Read more »

Coat of arms of Poland challenge

January 5, 2012
By
Coat of arms of Poland challenge

Last week I have experimented with coloring map of Poland in national colors. Vaidotas Zemlys improved on my effort by adding colors to map of Lithuania and posted a challenge to also add coat of arms to the plot. This proved to be a nice exe...

Read more »

Color map of Poland for the New Year

December 31, 2011
By
Color map of Poland for the New Year

To celebrate the New Year I decided to plot map of Poland in our national colors.It was not so difficult using maps  package. Here is the result:and the code I used to generate it:library(maps)x.mid <- function(x1, x2, y1, y2, y.mid) {&nbs...

Read more »

Programming traps when using "sample"

December 23, 2011
By
Programming traps when using "sample"

Standard sample function works differently when it gets single element integer vector as opposed to longer vectors. This can lead to unexpected bugs in R code.Several times I had a problem with code similar to one given here:for (i in 1:4) {&...

Read more »