Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Scouting (http://www.chiefdelphi.com/forums/forumdisplay.php?f=36)
-   -   OPR Formula (http://www.chiefdelphi.com/forums/showthread.php?t=101390)

MarkOfDinosaur 06-02-2012 23:27

Re: OPR Formula
 
1 Attachment(s)
Quote:

Originally Posted by Ether (Post 1121422)
What version of Excel do you have?

And just curious: where did you get your Cholesky algorithm from?


I have excel 2007.

And I found the algorithm somewhere online, I don't remember where from. Sorry. I'll attach it.

Ether 06-02-2012 23:57

Re: OPR Formula
 
Quote:

Originally Posted by MarkOfDinosaur (Post 1121387)
Ok, it works, thanks. Now, where do I go from here?

You're trying to solve

[A][x]=[b]

for [x],

where [A] is a symmetric nonnegative-definite matrix,

[x] is the vector of OPR's,

and

[b] is the vector of alliance score sums.


If you factor [A] using Cholesky, you get [L] such that [L][L]T=[A],

so you can substitute that for [A] to get

[L][L]T[x]=[b]

... and that is easily solved in two steps:

substitute [y] for [L]T[x] to get

[L][y]=[b]

and solve for [y] using forward substitution,

then once [y] is known solve

[L]T[x]=[y]

for [x] using back substitution.


[EDIT] I hope you get this working. I'm quite curious to see how fast it runs in an Excel VBA macro. The whole process -- Cholesky factorization, forward substitution and backward substitution to get OPR, then forward substitution and backward substitution again to get CCWM -- takes a bit over 12 seconds for a 2053x2053 [A] matrix on my machine using a 32-bit Delphi console app. [/EDIT]

[EDIT2] Instead of the lower triangular matrix [L], some Cholesky implementations give give an upper triangular [U] such that [U]T[U]=[A]. The solution process is similar. The algorithm you posted produces [L]. [/EDIT2]


MarkOfDinosaur 14-02-2012 23:37

Re: OPR Formula
 
Quote:

Originally Posted by Ether (Post 1121465)
You're trying to solve

[A][x]=[b]

for [x],

where [A] is a symmetric nonnegative-definite matrix,

[x] is the vector of OPR's,

and

[b] is the vector of alliance score sums.


If you factor [A] using Cholesky, you get [L] such that [L][L]T=[A],

so you can substitute that for [A] to get

[L][L]T[x]=[b]

... and that is easily solved in two steps:

substitute [y] for [L]T[x] to get

[L][y]=[b]

and solve for [y] using forward substitution,

then once [y] is known solve

[L]T[x]=[y]

for [x] using back substitution.


I have worked everything out, and am wondering what I have done wrong. I used data from the 2011 Florida, and compared my results to Ed Law's, and mine is similar, but some of the results vary by as much as five and most are about 2 or so off.
I have attached the matrices that I used for A, L, U, B, and Y, and the results for OPR are in X.
Thanks

Ether 14-02-2012 23:45

Re: OPR Formula
 
1 Attachment(s)
Quote:

Originally Posted by MarkOfDinosaur (Post 1126952)
I have worked everything out, and am wondering what I have done wrong. I used data from the 2011 Florida, and compared my results to Ed Law's, and mine is similar, but some of the results vary by as much as five and most are about 2 or so off.
I have attached the matrices that I used for A, L, U, B, and Y, and the results for OPR are in X.
Thanks

There were no attachments to your post.

Why did you use both [L] and [U]? It's one or the other.

Attached ZIP file contains test matrix [A] and test vector [b].

Run your code on that test matrix and test vector, and compare your results to the [L] matrix and the [y] and [x] vectors (also in the ZIP file) to locate where the problem is.


MarkOfDinosaur 16-02-2012 21:29

Re: OPR Formula
 
Quote:

Originally Posted by Ether (Post 1126959)
There were no attachments to your post.


Sorry, I now have it attached.

Quote:

Originally Posted by Ether (Post 1126959)
Why did you use both [L] and [U]? It's one or the other.


I'm Using U as the transpose as L, didn't mean for any confusion.

Quote:

Originally Posted by Ether (Post 1126959)
Run your code on that test matrix and test vector, and compare your results to the [L] matrix and the [y] and [x] vectors (also in the ZIP file) to locate where the problem is.


I ran my code, and it works, so my problem must be in how I'm getting either A or b. I'll double check my code. Is there any way that I could find what those are supposed to be?

Ether 16-02-2012 22:24

Re: OPR Formula
 
1 Attachment(s)
Quote:

Originally Posted by MarkOfDinosaur (Post 1128416)
I ran my code, and it works, so my problem must be in how I'm getting either A or b. I'll double check my code. Is there any way that I could find what those are supposed to be?

Attached ZIP file contains rawData.txt, which was used to generate the matrix [A].CSV and the vector [b].CSV

See if you can generate those from the raw data.

Data is fixed-field; columns are:

red1 red2 red3 blu1 blu2 blu3 redAllianceScore blueAllianceScore


There are different ways to populate the [A] matrix and [b] vector as the data file is being read. This is how I did it:

The data file is read and processed in a single pass.

For each line of the data file, as the team numbers are being read, each new team number encountered is assigned a TeamID, starting with 1 and incrementing by 1 with each new team. The TeamID is used as the index into the [A] matrix and [b] vector.



Ed Law 17-02-2012 00:47

Re: OPR Formula
 
Quote:

Originally Posted by MarkOfDinosaur (Post 1128416)
I ran my code, and it works, so my problem must be in how I'm getting either A or b. I'll double check my code. Is there any way that I could find what those are supposed to be?

Are you using only qualifying matches to assemble your Matrix A and vector b? There is a general consensus that elimination round matches should not be included in the calculation of OPR and CCWM.

Ether 17-02-2012 08:34

Re: OPR Formula
 
Quote:

Originally Posted by MarkOfDinosaur (Post 1128416)
Sorry, I now have it attached.

Attached where? Not to either of your posts.



Ether 17-02-2012 11:12

Re: OPR Formula
 
Quote:

Originally Posted by MarkOfDinosaur (Post 1128416)
... my problem must be in how I'm getting either A or b. I'll double check my code. Is there any way that I could find what those are supposed to be?

Yes. Post your raw data file and I will generate the [A] matrix and [b] vector for it.



Ether 17-02-2012 21:04

Re: OPR Formula
 
Quote:

Originally Posted by MarkOfDinosaur (Post 1128416)
Is there any way that I could find what those are supposed to be?

@Dinosaur: Haven't heard back from you. If you are struggling with processing the raw data directly into the normal equations ([A][x]=[b]), there is a conceptually simpler way to do it. Create matrix [M] and vector [s] from the raw data as follows:

[M] has dimensions 2m x n, where m is the # of matches in the raw data file and n is the number of teams.

[s] has dimensions n x 1.

As you read the data file, for each new team# you encounter assign a sequential TeamID. Use that TeamID (instead of the team#) as the index into [M] and [s].

For each line (match) read from the raw data file, do the following:

row+=1;
M[row,red1TeamID]=1;
M[row,red2TeamID]=1;
M[row,red3TeamID]=1;
s[row]=redAllianceScore;

row+=1;
M[row,blu1TeamID]=1;
M[row,blu2TeamID]=1;
M[row,blu3TeamID]=1;
s[row]=bluAllianceScore;

When you are done, you will have a set of overdetermined linear equations

[M][x]≈[s]

If you multiply both sides by [M]T, you get

[M]T[M][x]=[M]T[s]

The above are called the normal equations (of the overdetermined linear system), and solving these normal equations for [x] gives the least-squares solution.

Notice that [M]T[M] is [A] and [M]T[s] is [b].

So this approach takes more storage space and more computing, but it might be less confusing to code.



MarkOfDinosaur 18-02-2012 13:48

Re: OPR Formula
 
2 Attachment(s)
Quote:

Originally Posted by Ether (Post 1128459)
Attached ZIP file contains rawData.txt, which was used to generate the matrix [A].CSV and the vector [b].CSV

See if you can generate those from the raw data.

Data is fixed-field; columns are:

red1 red2 red3 blu1 blu2 blu3 redAllianceScore blueAllianceScore


There are different ways to populate the [A] matrix and [b] vector as the data file is being read. This is how I did it:

The data file is read and processed in a single pass.

For each line of the data file, as the team numbers are being read, each new team number encountered is assigned a TeamID, starting with 1 and incrementing by 1 with each new team. The TeamID is used as the index into the [A] matrix and [b] vector.


I am having trouble with the assigning of a Team ID. I understand it fully well, it's just drastically different from how I build the matrix. Do you have code I could take a look at, to see if I could understand how to switch mine over? I had previously just been inputting the data in numerical order of the team.

Quote:

Originally Posted by Ed Law (Post 1128557)
Are you using only qualifying matches to assemble your Matrix A and vector b? There is a general consensus that elimination round matches should not be included in the calculation of OPR and CCWM.

Yes, I am only using qualifying matches to assemble the matrix.

Quote:

Originally Posted by Ether (Post 1128764)
Yes. Post your raw data file and I will generate the [A] matrix and [b] vector for it.


The data will be attached.

Also attached is the spreadsheet from earlier I had neglected to attach by accident, twice.

Ether 18-02-2012 14:46

Re: OPR Formula
 
Quote:

Originally Posted by MarkOfDinosaur (Post 1129539)
I am having trouble with the assigning of a Team ID.

Create an array, let's call it TeamID[]. Size it to be bigger than the maximum expected TeamNumber (in the data file you are analyzing). Initialize all values in the array to 0.

Also create an array named TeamNum[]. Size it to be bigger than the expected total number of teams (in the data file you are analyzing).

As you read each TeamNumber from the data file, do the following logic:

if (TeamID[TeamNumber]==0) {_id++; TeamID[TeamNumber]=_id; TeamNum[_id]=TeamNumber;}

The above arrays are then used to lookup a team's ID if you know the team's NUMBER, or to lookup a team's NUMBER if you know the team's ID.



Ether 18-02-2012 15:19

Re: OPR Formula
 
1 Attachment(s)
Quote:

Originally Posted by MarkOfDinosaur (Post 1129539)
The data will be attached.

Attached is a ZIP file containing:

rawdata.txt your raw data file

A.csv the [A] matrix of the Normal Equations [A][x]=[b]

b.csv the [b] vector

L.csv the Cholesky lower-triangular factorization of [A]

y.csv the solution to [L][y]=[b]

x.csv the solution to [L]T[x]=[y]

stats.txt the analysis report



Ben Martin 26-02-2012 04:49

Re: OPR Formula
 
1 Attachment(s)
I've been following this and other OPR discussions for awhile, and I thought I'd share my Excel template for calculating it on the fly (requires an Internet connection).

I use mmult(minverse(play count matrix), total score vector).

Ether 26-02-2012 09:54

Re: OPR Formula
 
Quote:

Originally Posted by BMartin 234 (Post 1135006)
I've been following this and other OPR discussions for awhile, and I thought I'd share my Excel template for calculating it on the fly (requires an Internet connection).

I use mmult(minverse(play count matrix), total score vector).

Is this limited to processing single tournaments, or can it process an entire year's worth of data (in one large matrix) to get a year-end ranking?




All times are GMT -5. The time now is 04:17.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi