This forum is read-only now. Please use Forum 2 for new posts

xml No replies possible in the archive
How to calculate who's safe not to be relegated?
Author: Wak
Date: 06-02-2010, 17:05
I am sure there's a way OTHER than brute force through program computing, that could say whether or not one team is sure to be in the league the next season - even in a 24-teams championship.

All I know is the 1st step:
> Take the current TABLE,
> add as much victories as matches left for all teams EXCEPT the team you want to know the fate (let's call it "T")
> order the table again.
If team T is still out of the relegation places, it will surely stay out for the remaining part of the season.

But there are a few problems. With this method you can be weeks late!
It doesn't count
- fixtures between teams who are not relegated yet
-> which gives 3 different possibilities
->--> and surely decreases the threshold of points needed to avoid relegation.

Re: How to calculate who's safe not to be relegated?
Author: Lyonnais
Date: 06-02-2010, 22:41
Edited by: Lyonnais
at: 06-02-2010, 22:48
Look at this website.

It's a mathematician from the University of Lille who calculates all probabilities (sorry guys, only for French Ligues 1&2). If I understand correctly the methodology, he's using standard historical data (such as chances for home win 48%, draw 29%, away win 22%) for all teams and then computes all possible combinaisons.

So, as per his calculations, the minimum to be safe from relegation this season is 48 pts (using Grenoble example). But at the same time, Grenoble can still have expectations to be safe with 29 pts only.

Re: How to calculate who's safe not to be relegated?
Author: amirbachar
Date: 06-02-2010, 23:13
Edited by: amirbachar
at: 06-02-2010, 23:34
Attention - a little academic computer science knowledge is required to understand the following post.

In a 2 points per win system with 1 relegating team, It can be showed that it is equivalent to the Maximum Flow Problem in a graph with a source and a destination.
There are algorithms which solve that problem.
one such algorithm called Ford-Fulkerson's Algorithm that works on this occasion in a time complexity of O(n*m) where n is the number of teams below and m is the number of matches left between them.
In a 2 points per win system with k relegating teams, we can compute a graph for every choice of another k-1 relegating teams other than our team, so the complexity becomes O((n-k+1)*m*(n choose k-1)).
In a 3 points per win system, it becomes a bit more complex, because we can't know how many points will be dealt in the match (2 or 3), so I have to think about a way other than brute force to solve this problem. I hope I will come up with something tomorrow.

An explanation about Ford-Fulkerson's Algorithm:
http://en.wikipedia.org/wiki/Ford-Fulkerson_algorithm
I hope it wasn't to complex to keep up...

Re: How to calculate who's safe not to be relegated?
Author: Wak
Date: 06-02-2010, 23:27
Edited by: Wak
at: 06-02-2010, 23:28
Thanks Lyonnais.

I remember having seen this website already. That was something like in 2007. By the time Rennes was 14-15th, in February, the calculations gave almost no chance for Rennes to clinch a european spot. Rennes ended its 13 remaining games with 8-4-1, ending up 6th and reaching the Intertoto spot.

It is crazy to think that Montpellier has 12% chances to win Ligue 1 and Lyon just 5%. It leaves out many criteria like
- the importance of the last games,
- the winning and losing streaks (tho I don't know how to handle that),
- the strenghth of the remaining teams to play,
- the pace of a team's schedule (i.e. Bordeaux and Marseille may play 2 matches a week until March, except just one midweek off)

I wouldn't be suprised if last year, this website gave Lyon the most chances to win L1 in early April, and Bordeaux no chance to win its last 11 games last season, because it was something NEVER accomplished before.

What I'm curious about is the mathematics, not the statistics - see how many times we say that records are bound to fall.

I don't think that anybody in the world did bet on Grenoble winning 5-0 against Auxerre. I just want to be the first to say who is safe and who's already out. For this purpose, the only way not to look like a cunt because of the randomness of sport, is to rely on mathematics, not statistics.

Re: How to calculate who's safe not to be relegated?
Author: Wak
Date: 07-02-2010, 00:08
Edited by: Wak
at: 07-02-2010, 00:12
Thanks a lot amirbachar.

I have to say that I don't have this level of mathematics! I don't know what is time complexity for instance.
It's great that you know that!
Now, for the 3-points system, if you're looking for the number of points shared each match, I don't think it could be solved. But perhaps, the draws are not that useful to get the thresold?

I've just found this: http://www.lix.polytechnique.fr/~durr/MaxFlow/
but my little understanding of it bars me from doing anything

Re: How to calculate who's safe not to be relegated?
Author: Lyonnais
Date: 07-02-2010, 00:31
Thanks amirbachar for these useful precisions.


It is crazy to think that Montpellier has 12% chances to win Ligue 1 and Lyon just 5%. (...) I wouldn't be suprised if last year, this website gave Lyon the most chances to win L1 in early April, and Bordeaux no chance to win its last 11 games last season, because it was something NEVER accomplished before.


My understanding is that these probabilities are purely statistical, meaning that he doesn't introduce subjective factors such as "Lyon might wake up one day and thus I overweight their chances to win their games".
As per my understanding, all teams have say 48% chances to win their home games regardless who they are and who are their opponents. That's why Montpellier being above Lyon in the standings have more chances to win the title than Lyon in his model.
It's a basic model but it's designed to provide some mathematic assurance, not to bet on who' gonna be champion or relegated.

Re: How to calculate who's safe not to be relegated?
Author: amirbachar
Date: 07-02-2010, 19:44
I tried to solve the problem today. Unfortunately, I couldn't find an "easy to calculate" solution.
Wak comment, that the draws are not that useful to get the threshold is somewhat true. In fact, we can assume that 2 teams that meet each other won't make more than 1 draw between them, because then they can win and lose 1 match each and get 3 points instead of 2. Moreover, we can assume that there is no "draws circle", that is if you look at the graph where each vertex is a team and each edge means there's a draw between them, it is a forest.
Therefor, each forest on this graph can be matched with a choice of teams that draw each other. There are (n choose n/2)/(n+1) such forests on n vertexes (this number is called the nth Catalan number and denotes as Cn.
That way, for each forest we are back to the normal situation where in every match 3 points are dealt, and we can use Ford–Fulkerson algorithm again. So the overall complexity becomes
O((n choose k-1)*Cn*n*m).
We can use the Push-relabel maximum flow algorithm with FIFO vertex selection rule which works on O(|V|^3) complexity instead of the Ford–Fulkerson algorithm and get an overall complexity of O(n^(k+1)*(n choose n/2). Still not a polynomial, so it doesn't considered as a solution in the computer science field.

Re: How to calculate who's safe not to be relegated?
Author: amirbachar
Date: 07-02-2010, 20:36
Now, here is a bit more naive and much easier to understand solution, that might actually work better in reality (where the number of remaining matches between every 2 teams is small).
Lets say there are t matches remaining between teams i and j, which both are below our team. As we said earlier, we can assume they don't make more than 1 draw.
If they don't make any draws, the number of possibilities for the number of matches team i wins is t+1 (between 0 and t). If they make 1 draw, there are t-1 remaining matches, so there are t possibilities. Therefor there are 2t+1 possibilities for the points distribution between them.
We will now denote the number of remaining matches between teams i and j by m(i,j) and the total number of remaining matches between teams that are below our team by m as earlier.
There are (n 2)=(n choose 2)=n*(n-1)/2 such i,j combinations.
So the total number of possibilities is the product of (2m(i,j)+1)
for all 2 teams i,j. By the Inequality of arithmetic and geometric means that get its maximum value when all m(i,j) are equal so m(i,j)=m/(n 2) and this value is (2*m/(n 2)+1)^(n 2).
lim(1+k/n)^n=e^k, so the complexity of this solution is O(e^2m), so still not an efficient solution.

It was very interesting to try solving this problem. I hope you enjoyed my explanations.
Maybe some day I will come up with a polynomial solution (or a proof there isn't one...).

Re: How to calculate who's safe not to be relegated?
Author: Ricardo
Date: 09-02-2010, 21:26
Hi,
as I don't understand (don't want to) amirs reasoning, though it mught very well be right I see the following, partly from amir's assumption.
2 assumptions
1. you know the current standing
2. you know all ties still to be played.

A team X is safe when he loses all remaining matches and still remains above relegation line.

all teams above X will also lose all their matches, except for the ones that are played with other teams above X (or X itself)
Then you can find the cicle's lik amir said, with all teams in a circle winning 1 and losing 1.
So roughly speaking you could say that all teams below X get 3 pts. for a match with X or abov and 1.5 for a match with a team under X.
That's not getting it right, as a team that's 2 pts under X has enough with just 1 win to get above X.
So I'm stuck there, you should go from top to bottom, but well how to decide which match to win for this team and which to lose...

Re: How to calculate who's safe not to be relegated?
Author: Wak
Date: 13-02-2010, 20:57
I'm back after a few days
@amirbachar
You say that you want us to enjoy your answer. Frankly, I would really want to enjoy... I would really want to ;-)

What is your level of mathematics? Or a passionate self-made math expert?

When I have time I'll learn a few C++ or VB code in order to create a program for brute force I don't see any other solution...

Re: How to calculate who's safe not to be relegated?
Author: amirbachar
Date: 14-02-2010, 19:52
Edited by: amirbachar
at: 14-02-2010, 19:58
I have a B.Sc in Computer Science and Math...
If you are going to code it, you should at least use the last algorithm I wrote, which is very easy to implement.
Also, I didn't mention it, because it was pretty obvious in my mind, but Ricardo was right that I made these 2 assumptions:
1. you know the current standing
2. you know all ties still to be played.
He was also right that a team X is safe if and only if it loses all its remaining matches and all teams above X also lose all their matches, except for the ones that are played with other teams above X (or X itself), and it still remains above relegation line in any case.

Re: How to calculate who's safe not to be relegated?
Author: MalcolmW
Date: 15-02-2010, 11:19
A good way to start is to assume all (other) teams will win their home matches plus those away to the team being checked.
Look at the final table thus projected and decide what changes will uplift teams still below the team being checked, e.g. the bottom team could now be switched to winning at a team several points above the team being checked. Very occasionally a draw will be needed so as to ensure both clubs can climb above the target level.
This will normally provide a high figure, but a true one. While all those mathematicians managing teams "know" that 40 points ensures safety (in a 20 club league) this is not reality - just a 95% probability.

Re: How to calculate who's safe not to be relegated?
Author: Rapmaster
Date: 18-02-2010, 00:52
Hi!
amirbachar, the problem which you are looking to solve is NP-complete. In German language, the problem is called the "Meisterschaftsproblem" and there are various papers on this topic. Actually, there are some heuristics which are quite good, but I never tried them out. If you like, I could post some sources, but you need access to mathematical libraries.

Re: How to calculate who's safe not to be relegated?
Author: ilias
Date: 18-02-2010, 12:12
More than a football forum!

Re: How to calculate who's safe not to be relegated?
Author: amirbachar
Date: 18-02-2010, 16:06
Edited by: amirbachar
at: 18-02-2010, 17:46
Hi Rapmaster,
I will appreciate if you could post some sources.
I should have access to most mathematical libraries through my graduate University.

Re: How to calculate who's safe not to be relegated?
Author: Rapmaster
Date: 20-02-2010, 12:46
Hm, I searched for sources, but i couldn't find much in English. One English source is:
"Football Elimination Is Hard to Decide Under the 3-Point-Rule" by
Thorsten Bernholt, Alexander Gülich, Thomas Hofmeister and Niels Schmitt
Lecture Notes in Computer Science, Mathematical Foundations of Computer Science, 410-418, 1999
German source:
"Komplexitätstheorie, effiziente Algorithmen und die Bundesliga"
Thorsten Bernholt, Alexander Gülich, Thomas Hofmeister, Niels Schmitt and Ingo Wegener
Informatik-Spektrum, Volume 25, Number 6 / Dezember 2002

Alexander Gülich wrote a diploma thesis about this topic, maybe you can find some other papers of him about this topic. Btw, the German paper is much better than the English one, don't know if you understand German. I found some nice papers about planing good playing schedules for a championship.

Re: How to calculate who's safe not to be relegated?
Author: amirbachar
Date: 20-02-2010, 19:02
Edited by: amirbachar
at: 20-02-2010, 19:06
Thank you very much. It is an interesting reduction.

Re: How to calculate who's safe not to be relegated?
Author: leviramsey
Date: 13-03-2010, 18:34
Edited by: leviramsey
at: 13-03-2010, 18:42
I think this algorithm/heuristic should give the highest possible point total that would result in relegation (though I haven't proven it... taking goal difference into account is essentially intractable, since any goal difference can in theory be overtaken).

* First, construct a league table ordered by points and then games remaining (e.g. in SQL "SELECT team FROM table ORDER BY points DESC,played ASC").
* As a simple definition, two clubs are in the same spot if they have an equal number of points from an equal number of games... thus it is possible that there could be at least five clubs in the final relegation spot; in such a case, all five clubs WILL be considered to be occupying the final relegation spot.
loop-begin: UNTIL THE STOP CONDITION (see below) IS REACHED:
* If there are any clubs below (not in) the highest relegation spot with games remaining to be played, assign remaining results as follows:
- loss if the opponent is in the highest relegation spot or higher
- draw if the opponent is below the highest relegation spot
- after assigning the results, recompute the table and go back to loop-begin
* For each club that started the loop in the highest relegation spot, assign remaining results as follows:
- draw if the opponent started the loop in the highest relegation spot
- win otherwise
* Test the STOP CONDITION: regenerate the table as in the first step; if all clubs in the highest relegation spot have no remaining games, then we have reached the STOP CONDITION

It may well be effectively the same algorithm as proposed earlier... it should be fairly easy to write readable code for this in a language (e.g. Perl) that has associative arrays/hashes and allows references (e.g. a hash of arrays). This should be O(n*m), where n is the number of teams in the league and m is the average number of games remaining per team (so the absolute worst-case is O(p) where p is the total number of games remaining, though the average-case is substantially better)... minor tweaks are needed if you're feeding this a table where everybody has the same number of points from the same number of games (thus everybody is level with everybody else).

Re: How to calculate who's safe not to be relegated?
Author: leviramsey
Date: 13-03-2010, 23:12
Further, my algorithm/heuristic is somewhat designed for what's the normal real-world case where the question gets asked: you're in the second half of a season, which in most [popular> leagues means that each club has at most one game remaining against every other club.

Re: How to calculate who's safe not to be relegated?
Author: amirbachar
Date: 14-03-2010, 20:54
Edited by: amirbachar
at: 14-03-2010, 21:06
You algorithm is wrong:
for example the next table with 1 relegated team:
A 3
B 2
C 2
D 1
with the remaining matches D-B and D-C
Team A can be relegated if both matches are tied, but your algorithm will give D a win in their first match.

I wouldn't try to find a solution, as this problem is NP-complete as proven earlier in the thread (even when there are 3 matches remaining for each team).
Although, if you will find a polynomial solution (or even proven there isn't one), you will get 1M$... (the problem "is P=NP?" is one of 7 questions with such prize)

Re: How to calculate who's safe not to be relegate
Author: stef
Date: 10-04-2010, 02:16
i have developed a function in matlab.i'm not an expert at comp science but it should work well enough. you need to input a matrix containing all ties between all teams.it's a symmetric matrix with diagonal zero. first it gives the max points to all teams below you against all teams above you(and yourself because you score no extra points) then it generates a square matrix containing all ties to be played between all teams that are lowerranked even if they win against you and all higherranked teams. then you enter how much points they need to make to equal you in a vector . a loop generates all matrices with diag 0 and if (i,j)=3 then (j,i)= 0, if (j,i) = 1 rhen (j,i) =1 . so it contains all possible outcomes 4 the remaining games between lowerranked teams . it's not symmetric anymore you can read the number of points team i gained against team j in(i,j) it multilpliies the ties matrix elementwise with each matrix. it calculates the sum of each row then it compares with the number of points necessary to equalise. it creates a vector 4 each iteration that if it consist only out of 1 s means that your team has still a chance to finish last1 zero means ur worst possible rank is second to last etc. thevector w most1s obviously is the one 2 look at. might post the function later so it becomes more clear . srry 4 lay out used my ps3 to post.

re
Author: stef
Date: 16-04-2010, 17:21
Edited by: stef
at: 16-04-2010, 17:22
apparently it's not straightforward to implement the whole calculation in one function. I decided to split them up. First function uses current standing and ties to be played to make a standing: with all teams below the team i (the one you want to determine the fate) winning against team i and teams above team i. It displays the new standing (worst case scenario for team i) and all other encounters between lower ranked teams.

I've tested it for 6 teams don't know if it'll work for more.

function 1.(replace "close square brackets" by "bigger than" on line 1 and 6)


function[Z> =nodegradation(X,K)
%X=m*3 matrix col1= matches played
%col2= points earned
%col3= blanco
%K=m*m symmetric matrix, diag(K)=0; all ties
[m,~>=size(X);
for i=1:m
display('________________________________________________________')
display(i)
Z=X(1:m,: );
%K1= all complex matches
K1=K(i+1:m,i+1:m);

K2=K(1:i,1:m);
S=sum(K2,1);
S(1:i)=0;

for j=1:m
Z(j,2)=Z(j,2)+S(j)*3;
Z(j,1)=Z(j,1)+S(j);
end
Z(i,3)=i;
Z(1:i,1)=(m-1)*2;
display (K1)
display (Z)
end
display(X)




The second function uses the output generated from the first function as input. I'll try to post that one later. It's harder to create a loop for this, because it uses more system resources.