Teams coming from the same group and from same association can not be drawn against.

One can compute the probabilities of the likely outcomes by using ensemble average, a standard way of finding the frequencies where we identify whole sample space. Here we take a different approach and use time averages. What we do is torun large number of draws (20 million times) using randomly generated draws. I have calledthis exercise a Monte Carlo simulation, rather a simple sort while there is no fancy sampling of any sort, only rejection of pair up or the given draw if the last remaining pair does not satisfy the rules. A statistical languageGNU R is used to generatethe likely outcome. We use Mersenne Twister RNG, a default random number generator which is known to have very large cycle. In result we basically count the likely pair-ups in a matrix (matrix of pairs) and find the frequency of each likely pairup. Simulation takes 3-4 hours on a single CPUIntel Xeon with 16 GB RAM running Ubuntu GNU/Linux. Well, to be honest I haven't optimized the code.

Qualified teams, their groups and associations definitions, the simulation and results reporting R code are as follows (note that we use xtable for html outputs, for other functions we use, see below codes after tables):

Simulations results can be interpreted based on frequencies (probabilities) of pairings, rather intuitively while probabilities are not that far off . For example if we consider Barcelona, Milan and Arsenal score the largest 0.23 and 0.21. So my guess based on these frequencies, which I select maximums first ,then the second maximum and so on. If all ties I select the highest count using the second table. Here are the predicted pairs, (ordered with highest probability):

Monday, 3 December 2012

Recently a short idea on how function closures can be build in R is shown [link]. It is also discussed in detail by Darren Wilkinson's blog [link]. Here we will mimic the approach presented there. Recall that function
closures are basically a reference to a function with the attachment of
its lexical environment. Note that, it is not a function pointer
while it also return the values of its arguments if they are defined in
the given scope. This sort of language construction can be very handy
when some of the inner details need to be parametrized, so to speak to
prevent re-writing the function over and over again.

A trivial example of adding a number to a given number can be formulated. Let's say x is a number and we need to add 4 to x.

function add4(x) x+4end

So
far so good, but do you really want to re-write an other function to
add 7. Not really! So instead we can generate a function that generates
addition function for 7 (Sounds like an onion.). This is quite standard
in functional languages and noting new actually!

So function add4 and add7 are generated by the function addx. We just utilized function handles.
This might be quite trivial. Let's try the technique in a little more
realistic setting. Imagine we need to take a median of each vector,
which has different sizes stored in a structure. Let's generate one

So a function that takes a structure like this and returns the median value of the named member

>> medianVec= @(str, memName) median(str.(memName));

For example for vec1

>> medianVec(myStr, 'vec1'); 0.5194

If we need this procedure for vec1 repetitively, we don't need to re-write the second argument all the time. So>> medianVecN = @(memName) @(str) median(str.(memName));>> medianVec1 = medianVecN('vec1');>> medianVec1(myStr); % Vala!0.5194

This might still look trivial but hopefully it would give you an idea of the technique.

In this post, I would like to give you a crash tutorial on the basics of MATLAB ™ - GNU Octave (MO). They are not fully compatible but quite close in grammar. For differences see here. We will concentrate on the basic data structures and object manipulation that would help you to write useful code quickly.

Structures and CellsA structure definition can be performs as follows
persons=struct();
Fields can be defined after .
persons.age=12;
Further index can be assigned dynamicallypersons(2).age=32;
persons(3).age=40;

FunctionsReturn vector with function definition must be in a seperate file. For example here pov.m (in
the working directory)

function [ pov2, pov3] = pov(x) pov2= x^2; pov3 = x^3;end

(pwd will tell you which directory you are working in. A return vector here is [pov2, pov3].

Function handles and apply functionsTo define new function ff with function handle
it takes a structure xx and returns its field age value

ff = @(xx) xx.age

We can apply this function to each element of the structure,returning an array (vector)

arrayfun(ff, persons)

Example Task:Lets align two vectors, meaning that we found matching indices and delete non matching ones. Here is the solution: