Publications by Bogumił Kamiński
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) { x1 + ((x2 – x1) / (y2 – y1)) * (y.mid – y1)}poland map(“world”,“poland”, fi...
1196 sym 4 img
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 exercise of using pixmap and grImport packages.I wanted to compare adding coat of arms of Polan...
2320 sym 6 img
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 mapoland based on ESRI shape files, but I wanted to import such a map from SVG file which can be...
2114 sym 4 img
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 of average tree height. I thought that it would be nice to have its implementation in R.I de...
6282 sym 2 img
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 treesimulate function (forest.density = 0.6, size = 251) { forest matrix(3 * rbi...
2182 sym 4 img
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 given in NetLogo implementation I added:plot showing maximal difference between turtle distance...
929 sym R (2285 sym/1 pcs) 4 img
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 edges in the graph is reduced.Below I give ws.graph function that generates directed...
894 sym R (1217 sym/1 pcs) 4 img
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 average preference equal to 0 indicates 50/50 split. Voters are arranged on square grid wit...
3287 sym 6 img
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 synchronous code are given here:step.syn.slow function(space) { base.x c(-1, –1, –1, 0, ...
2333 sym 2 img
Shapley-Shubik Power Index in R
This spring we have Rector Elections at Warsaw School of Economics. One of my collegues Tomasz Szapiro agreed to start in the elections. This induced me to write Shapley-Shubik Power Index calculation snippet in R.Rector elections in Warsaw School of Economics are organized in eleven constituencies representing different communities ...
1807 sym 4 img