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)

brennonbrimhall 28-01-2012 15:33

OPR Formula
 
This is going to sound extremely stupid, but what is the formula for OPR?

Thanks in advance.

Tom Line 28-01-2012 16:18

Re: OPR Formula
 
That is not a stupid question.

OPR is actually a system of simultaneous equations. The difficulty lies in solving that many simultaneous equations.

For instance. In a standard district event in Michigan, there might be 80 matches.

Each match has equations that lay out like this:
Robot_1_score+Robot_2_score+Robot_3_score=Red_Scor e
Robot_4_score+Robot_5_score+Robot_6_score=Blue_Sco re

So, in the end you'll have a system with 160 equations, and 40 variables (each robot is one variable, as shown in the equations above). The trick is solving those equations. Until just recently, excel didn't have the firepower to do it unless you used macros. However, with the newer versions, the Matrix formulas are powerful enough to do it. Keep in mind this isn't like algebra - the computer has to iterate to find an answer.

This is not a simple process. It is fairly complicated. Look up "solving simultaneous equations using matrices" in excel, and you should be able to find some examples. That is how we wrote our OPR. It requires pretty in-depth knowledge of excel though. You'll have to understand named arrays, matrix math functions, and array formulas.

2834 the Bionic Barons put out an awesome OPR sheet that handles the calculations through some open-source macro code. It is far more complex (to me) than using matrix formulae, because I have never used macros and vb programming in excel.

Of course, programs like matlab have more advanced equation solvers and you may be able to easily write a program to perform the calculations.

Ether 28-01-2012 16:31

Re: OPR Formula
 
Quote:

Originally Posted by Tom Line (Post 1115348)
So, in the end you'll have a system with 160 equations, and 40 variables (each robot is one variable, as shown in the equations above). The trick is solving those equations.

Tom,

I've done a fair amount of work with large overdetermined systems of equations (20,000 equations in 6,000 variables).

I'd like to play around with some of this data. Maybe I could write and post a small app. Do you know where I could get a couple of CSV, or whitespace-delimited, or fixed-field text files from 2011?

Thanks.


Tom Line 28-01-2012 16:59

Re: OPR Formula
 
I believe you can copy and paste from the old scores on the FIRST website. For instance, here:

http://www2.usfirst.org/2011comp/eve...chresults.html

That is how I developed ours. I've never tried to do the whole web-scrape or download the scores automatically as they are posted by FIRST. If, however, someone could explain how that's done it would be absolutely wonderful!

plnyyanks 28-01-2012 19:07

Re: OPR Formula
 
Quote:

Originally Posted by Tom Line (Post 1115379)
I've never tried to do the whole web-scrape or download the scores automatically as they are posted by FIRST. If, however, someone could explain how that's done it would be absolutely wonderful!

In newer versions of Excel, go to the Data tab, and then click (under Get External Data - left most panel) "From Web". Then, you can put the URL of the results page into the little browser window that pops up and then select the table with match results. To refresh, click "Refresh All" in the Connections pane (still on the data tab).

MagiChau 28-01-2012 19:13

Re: OPR Formula
 
Also, the FIRST FMS system uploads its data in twitter posts under @frcfms so you could scrape a lot more data from that since it tells of penalties point total for instance.

Ether 28-01-2012 19:25

Re: OPR Formula
 
Quote:

Originally Posted by plnyyanks (Post 1115442)
In newer versions of Excel, go to the Data tab, and then click (under Get External Data - left most panel) "From Web". Then, you can put the URL of the results page into the little browser window that pops up and then select the table with match results. To refresh, click "Refresh All" in the Connections pane (still on the data tab).

Is there a CSV or whitespace-delimited or fixed-field text file somewhere that has all the scores from all the matches around the country (world) in one file for 2011?


plnyyanks 28-01-2012 20:38

Re: OPR Formula
 
1 Attachment(s)
Quote:

Originally Posted by Ether (Post 1115456)
Is there a CSV or whitespace-delimited or fixed-field text file somewhere that has all the scores from all the matches around the country (world) in one file for 2011?


How's this? I just threw it together by scraping all the competitions and putting them in one big file.

Also, some fun facts I found:
- there were 5,258 FRC matches played in 2011
- There were 357,981 points scored total
- The average individual alliance score was 34.04 points
- The average total number of points per match was 68.08311145 points
- The highest alliance score was 147 points

brennonbrimhall 28-01-2012 21:01

Re: OPR Formula
 
Many thanks for all the info. Can I assume the same basic principles hold true with DPR as well?

Alex.q 28-01-2012 22:00

Re: OPR Formula
 
Quote:

Originally Posted by MagiChau (Post 1115448)
Also, the FIRST FMS system uploads its data in twitter posts under @frcfms so you could scrape a lot more data from that since it tells of penalties point total for instance.

I was not aware of this. Would someone be able to tap this data during the tournament to feed it into a scouting program? How much information is available there?

Also, I know OPR means offensive power rating, but what does this actually mean?

EricH 28-01-2012 23:03

Re: OPR Formula
 
Quote:

Originally Posted by Alex.q (Post 1115540)
I was not aware of this. Would someone be able to tap this data during the tournament to feed it into a scouting program? How much information is available there?

Also, I know OPR means offensive power rating, but what does this actually mean?

IIRC, OPR is the expected points contribution of any given robot to an alliance.

DPR... I don't think anybody's ever come up with a good way to calculate that. First you have to find a way to calculate a defensive score...

Ether 28-01-2012 23:21

Re: OPR Formula
 
Quote:

Originally Posted by EricH (Post 1115601)
IIRC, OPR is the expected points contribution of any given robot to an alliance.

DPR... I don't think anybody's ever come up with a good way to calculate that. First you have to find a way to calculate a defensive score...

Couldn't you do it the same way Tom said he did the OPR, with the following twist?

Set up the equations like so:

red1+red2+red3 = blue_alliance_score

... then solve the system.

The lower the number, the better the DPR. Like golf.

Ed Law 28-01-2012 23:34

Re: OPR Formula
 
If you want to learn more about OPR, CCWM, DPR, PMR, please refer to

http://www.chiefdelphi.com/media/papers/2174

I will post an updated 2012 version of the presentation file shortly.

EricH 29-01-2012 00:07

Re: OPR Formula
 
Quote:

Originally Posted by Ether (Post 1115630)
Couldn't you do it the same way Tom said he did the OPR, with the following twist?

Set up the equations like so:

red1+red2+red3 = blue_alliance_score

... then solve the system.

The lower the number, the better the DPR. Like golf.

Possibly. The hardest part about DPR is that a low blue_alliance_score could come from two possible sources. It could be that one or more red robots are playing really good defense. But, it could be that the blue alliance has a very low combined OPR (read: needs better offense even without defense being played). Without having an OPR-to-score comparison built in, there is no real way to determine whether red is playing good defense or blue is playing bad offense.

You might be able to do it with

red1+red2+red3 = blue_alliance_OPR - blue_alliance_score

and the higher the score the better (due to the OPR-score) but that involves knowing the blue alliance's combined OPR.

Ed Law 29-01-2012 00:48

Re: OPR Formula
 
Quote:

Originally Posted by EricH (Post 1115676)
Possibly. The hardest part about DPR is that a low blue_alliance_score could come from two possible sources. It could be that one or more red robots are playing really good defense. But, it could be that the blue alliance has a very low combined OPR (read: needs better offense even without defense being played). Without having an OPR-to-score comparison built in, there is no real way to determine whether red is playing good defense or blue is playing bad offense.

You might be able to do it with

red1+red2+red3 = blue_alliance_OPR - blue_alliance_score

and the higher the score the better (due to the OPR-score) but that involves knowing the blue alliance's combined OPR.

Numerically, DPR = OPR - CCWM (calculated contribution to winning margin). A team will have high DPR if their CCWM is low or negative comparing to OPR. Low DPR means a team is good in defense. Basically it means they do not allow their opponents to score much.
I do not agree with low DPR is a result of opposing alliance's inability to score. Over a number of matches, those teams with low OPRs will also cause other teams to experience the same thing. A team's DPR will only be higher or lower based on how they perform on average comparing to other teams. Remember OPR, DPR and CCWM are all calculations of that team's calculated contribution.

Tom Line 29-01-2012 00:54

Re: OPR Formula
 
Quote:

Originally Posted by plnyyanks (Post 1115499)
How's this? I just threw it together by scraping all the competitions and putting them in one big file.

Also, some fun facts I found:
- there were 5,258 FRC matches played in 2011
- There were 357,981 points scored total
- The average individual alliance score was 34.04 points
- The average total number of points per match was 68.08311145 points
- The highest alliance score was 147 points

Phil, can you explain how you got the info from twitter?

Basel A 29-01-2012 01:02

Re: OPR Formula
 
Quote:

Originally Posted by Ed Law (Post 1115698)
Numerically, DPR = OPR - CCWM (calculated contribution to winning margin). A team will have high DPR if their CCWM is low or negative comparing to OPR. Low DPR means a team is good in defense. Basically it means they do not allow their opponents to score much.
I do not agree with low DPR is a result of opposing alliance's inability to score. Over a number of matches, those teams with low OPRs will also cause other teams to experience the same thing. A team's DPR will only be higher or lower based on how they perform on average comparing to other teams. Remember OPR, DPR and CCWM are all calculations of that team's calculated contribution.

The problem with DPR is that when teams do not play defence, DPR can be unpredictable. While it will take into account offensive hoarding by the team (if applicable), this is not always significant compared to mostly-random fluctuations, including schedule.

Occasionally, DPR will take into account non-random factors other than the team's robot, though. In 2011, a team's human player could play a significant role in determining opponents score. A human player's output (# of tubes thrown) and accuracy (% of tubes picked up by own alliance) definitely affect opponent score, for example. A human player who threw many tubes or wasn't very accurate could result in a team having a high DPR.

In 2012, human players aren't a factor, but hoarding as an alliance strategy certainly is (note that an alliance could control 15 of the 18 balls at a time). A low DPR by a team not playing defence would probably be indicative of such a strategy.

plnyyanks 29-01-2012 08:01

Re: OPR Formula
 
Quote:

Originally Posted by Tom Line (Post 1115700)
Phil, can you explain how you got the info from twitter?

I didn't get it from twitter. I got it from the web based results (with a URL like this: http://www2.usfirst.org/2011comp/eve...chresults.html) by just going through all the event codes and putting it as a parameter in an excel query that would get the data from http://www2.usfirst.org/2011comp/events/event_code/matchresults.htm. Then, I just put them all in the table I posted.

To get this data from twitter, you'd have to use the API, and I'm not sure to go about that. Maybe you could fetch tweets using JSON?

stingray27 29-01-2012 12:18

Re: OPR Formula
 
1 Attachment(s)
Hey guys,

I took what all of you have contributed (great post by the way, very helpful) and constructed an excel file to do RUSH's post-competition analysis, or other competition scouting for states and nationals. So i wrote a macro (not very efficient at those, sorry) and it creates webquery files, obtains the data, and organizes it for however many teams are in the tournament. The only problem I am having is the OPR calculations. Can someone look at my macro and see what they can do about adding an OPR calculation formula or something? Or give me some feedback on how i can improve it cause I really am not too good at these. Thanks.

brennonbrimhall 29-01-2012 15:22

Re: OPR Formula
 
Quote:

Originally Posted by Ether (Post 1115630)
Couldn't you do it the same way Tom said he did the OPR, with the following twist?

Set up the equations like so:

red1+red2+red3 = blue_alliance_score

... then solve the system.

The lower the number, the better the DPR. Like golf.

That's along the same lines I was thinking. If you could calculate the opposing score, then you would have your DPR.

Tom Line 29-01-2012 16:20

Re: OPR Formula
 
Quote:

Originally Posted by stingray27 (Post 1115818)
Hey guys,

I took what all of you have contributed (great post by the way, very helpful) and constructed an excel file to do RUSH's post-competition analysis, or other competition scouting for states and nationals. So i wrote a macro (not very efficient at those, sorry) and it creates webquery files, obtains the data, and organizes it for however many teams are in the tournament. The only problem I am having is the OPR calculations. Can someone look at my macro and see what they can do about adding an OPR calculation formula or something? Or give me some feedback on how i can improve it cause I really am not too good at these. Thanks.

Stingray, nice work! I'm going to include that in our OPR this year so we can auto-update it on the fly. Really outstanding.

Ed Law 29-01-2012 23:29

Re: OPR Formula
 
Quote:

Originally Posted by stingray27 (Post 1115818)
Hey guys,

I took what all of you have contributed (great post by the way, very helpful) and constructed an excel file to do RUSH's post-competition analysis, or other competition scouting for states and nationals. So i wrote a macro (not very efficient at those, sorry) and it creates webquery files, obtains the data, and organizes it for however many teams are in the tournament. The only problem I am having is the OPR calculations. Can someone look at my macro and see what they can do about adding an OPR calculation formula or something? Or give me some feedback on how i can improve it cause I really am not too good at these. Thanks.

Hi,

Nice work. If you want your spreadsheet to calculate OPR from the results that you get from the web query, you are welcome to copy any of the macros that I published. I did not put protection on them to allow other teams to use them and customize for their own use. However if that is all you are going to do, I don't see the purpose of it except as a learning process since I publish OPR/CCWM results of every regional and district after each week of competition and I have been doing it for the last 4 years. Please refer to the following white paper.
http://www.chiefdelphi.com/media/papers/2174
You will not see the weekly published spreadsheets from prior years since I delete them at the end of the season and only keep the last one.

Ether 30-01-2012 19:45

Re: OPR Formula
 
1 Attachment(s)
Quote:

Originally Posted by plnyyanks (Post 1115499)
How's this? I just threw it together by scraping all the competitions and putting them in one big file.

Also, some fun facts I found:
- there were 5,258 FRC matches played in 2011
- There were 357,981 points scored total
- The average individual alliance score was 34.04 points
- The average total number of points per match was 68.08311145 points
- The highest alliance score was 147 points

Attachment shows OPR, CCWM, & DPR scores obtained by solving the 2052 simultaneous equations obtained for the 2052 teams in that "one big file".

On my 8-year-old computer, it took ½ second to read the file and create the 2052x2052 matrix. It took 19 seconds to factor the matrix and compute OPR, CCWM, and DPR.


DMetalKong 30-01-2012 21:24

Re: OPR Formula
 
1 Attachment(s)
Quote:

Originally Posted by Ether (Post 1116708)
Attachment shows OPR, CCWM, & DPR scores obtained by solving the 2052 simultaneous equations obtained for the 2052 teams in that "one big file".

On my 8-year-old computer, it took ½ second to read the file and create the 2052x2052 matrix. It took 19 seconds to factor the matrix and compute OPR, CCWM, and DPR.


And just for kicks attached is a histogram of the CCWM scores. I find it interesting how normal in shape the distribution is; I would have expected it to have a longer tail on the right than is apparent.

Ed Law 31-01-2012 11:31

Re: OPR Formula
 
Quote:

Originally Posted by Ether (Post 1116708)
Attachment shows OPR, CCWM, & DPR scores obtained by solving the 2052 simultaneous equations obtained for the 2052 teams in that "one big file".

On my 8-year-old computer, it took ½ second to read the file and create the 2052x2052 matrix. It took 19 seconds to factor the matrix and compute OPR, CCWM, and DPR.


Hi Ether,

The numbers you have is slightly different than mine. Do you include elimination round matches?

Your 8-year-old computer must have been quite a powerful computer 8 years ago. Or is there a solver you used that is faster than the Cholesky Decomposition that I used. Here is the statistics that my son got when he was a junior in his independent study math class.

Computer Model Hewlett-Packard HP ProBook 6555b
Platform Mobile
OS Version Microsoft Windows XP Professional
CPU AMD Turion(tm) II P520 Dual-Core Processor
Memory 2807 MB

Here are the data table from tests: (time in seconds)
Size Gauss-Jordan method LU Factorization Cholesky Decomposition
100 0 0 0
300 9 1 0
500 46 8 1
750 159 27 4
1000 383 64 11
1400 1056 178 30
1800 2278 384 63

This was the 2010 data and it took 63 seconds on that slow machine.

Ether 31-01-2012 15:07

Re: OPR Formula
 
1 Attachment(s)
Hi Ed,

The numbers you have is slightly different than mine. Do you include elimination round matches?
I used all the data in the "one big file" that Phil attached to post#8 in this thread. That file contains only raw data (no metadata) so I can't say for certain what Phil included.

@Phil: Can you jump in here and answer Ed's question?

Your 8-year-old computer must have been quite a powerful computer 8 years ago.
Pentium D 3.4GHz 1GB

Or is there a solver you used that is faster than the Cholesky Decomposition that I used.
I also used Cholesky, but all Choleskys are not created equal. There are various implementations. Some are column-oriented and some are row-oriented; some are in-place and some are not. It makes a difference. The one I used is a slightly modified version of one that I selected sometime back in the late 80s after testing several different algorithms from various texts. It's optimized for memory access. The 19 seconds was for a 2052x2052 matrix using double precision (64 bit) floats for the matrix and Intel extended precision 80-bit floats for intermediate calculations.

I just re-ran it with single-precision (32 bit) floats and it took a little less than 12 seconds to factor the 2052x2052 matrix.

1800 2278 384 63
This was the 2010 data and it took 63 seconds on that slow machine.
That's 63 seconds for an 1800x1800 matrix. Since Cholesky goes as O3, that would take ~93 seconds for a 2052x2052 matrix.

How are you computing the results in the "Worldrank" tab in the Team_2834 2011_Scouting_Database Championship v4 spreadsheet? My version of Excel (2000) only has 256 columns - not enough to hold a 2052x2052 matrix. I assume you are crunching the numbers in some other app?

I also computed the OPR & CCWM for the data (qualification matches only) in the link that Tom Line included in his post#4 in this thread. Attached are my results. The columns are Team#, OPR, CCWM, and DPR. If you would run your computation on the same data we could compare apples to apples.



plnyyanks 31-01-2012 15:56

Re: OPR Formula
 
2 Attachment(s)
Quote:

Originally Posted by Ether (Post 1117179)
@Phil: Can you jump in here and answer Ed's question?

You know, I might have actually forgot to put elimination rounds into that file. I forgot that I had to specifically tell excel to import a second table. Attached is a revised version of my entire workbook. Sorry about that, guys.

EDIT:
Quote:

Originally Posted by Ether (Post 1117179)
That file contains only raw data (no metadata) so I can't say for certain what Phil included.

I attached another file that has some more information - regional names, match times, etc

Andrew Schreiber 31-01-2012 16:01

Re: OPR Formula
 
Quote:

Originally Posted by plnyyanks (Post 1117206)
You know, I might have actually forgot to put elimination rounds into that file. I forgot that I had to specifically tell excel to import a second table. Attached is a revised version of my entire workbook. Sorry about that, guys.

Understand that in the twitter feed there is a lot of garbage data too. Various test posts as well as practice matches.

Ether 31-01-2012 16:25

Re: OPR Formula
 
1 Attachment(s)
Quote:

Originally Posted by plnyyanks (Post 1117206)
You know, I might have actually forgot to put elimination rounds into that file. I forgot that I had to specifically tell excel to import a second table. Attached is a revised version of my entire workbook. Sorry about that, guys.

Attached is analysis for the data in the tab named "All Matches", less lines 5526, 5766, 6004, and 6196 (DQ).

Columns are Team#, OPR, CCWM, and DPR


Ed Law 31-01-2012 16:54

Re: OPR Formula
 
Ether,

Your republished numbers are very close to mine now. I also used double precision. My implementation is done in Excel using VBA. I do not actually put the 2053 X 2053 matrix inside the spreadsheet so it works in older version. The program read in the match results and assemble the matrix. It is just stored in the memory for the calculation. Solving the equations inside Excel using VBA is probably slower than outside in another app. Tom Line mentioned they are solving the equations using Excel built-in solver. I am curious what algorithm they use and how fast that would be.

How come you only have 2052 teams? I have 2053 teams in 2011.

Ether 31-01-2012 18:58

Re: OPR Formula
 
Quote:

Originally Posted by Ed Law (Post 1117250)
Ether,

Your republished numbers are very close to mine now. I also used double precision. My implementation is done in Excel using VBA. I do not actually put the 2053 X 2053 matrix inside the spreadsheet so it works in older version. The program read in the match results and assemble the matrix. It is just stored in the memory for the calculation. Solving the equations inside Excel using VBA is probably slower than outside in another app. Tom Line mentioned they are solving the equations using Excel built-in solver. I am curious what algorithm they use and how fast that would be.

How come you only have 2052 teams? I have 2053 teams in 2011.


Column " B" of the "Worldrank" tab of your Team_2834 2011_Scouting_Database Championship v4b.xls spreadsheet has
has teams 1366 and 2627 which were not in Phil's file. Phil's file has team 1702 which is not in your spreadsheet. So we still aren't using the same data. Do you have (or could you quickly generate) a single file in XLS, CSV, fixed-field, or whitespace-delimited format which has all the data you used1?

Matrix factor time for double-precision 2052x2052 matrix elements with double-precision intermediate calculations (instead of Intel extended precision 80-bit) is 12.4 seconds.

I didn't know that the Solver could be used by a macro to operate on a matrix in memory. I'll have to look into that. Even so, I'm surprised that they let you solve a 2052x2052 matrix using Solver. The Solver in Excel is a limited (but still quite capable) version of a commercial product from a third party named Frontline.

1 with fields red1, red2, red3, blue1, blue2, blue3, red_alliance_score, blue_alliance_ score


Ed Law 31-01-2012 23:54

Re: OPR Formula
 
1 Attachment(s)
Quote:

Originally Posted by Ether (Post 1117327)
Column " B" of the "Worldrank" tab of your Team_2834 2011_Scouting_Database Championship v4b.xls spreadsheet has
has teams 1366 and 2627 which were not in Phil's file. Phil's file has team 1702 which is not in your spreadsheet. So we still aren't using the same data. Do you have (or could you quickly generate) a single file in XLS, CSV, fixed-field, or whitespace-delimited format which has all the data you used1?

Matrix factor time for double-precision 2052x2052 matrix elements with double-precision intermediate calculations (instead of Intel extended precision 80-bit) is 12.4 seconds.

I didn't know that the Solver could be used by a macro to operate on a matrix in memory. I'll have to look into that. Even so, I'm surprised that they let you solve a 2052x2052 matrix using Solver. The Solver in Excel is a limited (but still quite capable) version of a commercial product from a third party named Frontline.

1 with fields red1, red2, red3, blue1, blue2, blue3, red_alliance_score, blue_alliance_ score


1702 registered for Los Angeles Regional but did not compete. 1366 did compete at Los Angeles Regional. 2627 is a Michigan team and attended Ann Arbor district last year.
I have attached the data I used. I am sure we will get the same results.
I did not use the Excel build in Solver. The algorithm I used was implemented by Sergey Bochkanov at the University of Tennessee

Ether 01-02-2012 00:56

Re: OPR Formula
 
Quote:

Originally Posted by Ed Law (Post 1117594)
I have attached the data I used. I am sure we will get the same results.

Yup. Identical.

Quote:

I did not use the Excel build in Solver.
Yes, I understood that. The remark in my previous post about Solver was in reference to your earlier post mentioning that Tom Line was using Solver.

Quote:

The algorithm I used was implemented by Sergey Bochkanov at the University of Tennessee
Would that be ALGLIB ?


JewishDan18 01-02-2012 01:32

Re: OPR Formula
 
Quote:

Originally Posted by brennonbrimhall (Post 1115315)
This is going to sound extremely stupid, but what is the formula for OPR?

Thanks in advance.

If you find me some time, I can whiteboard you through it :P

Ed Law 01-02-2012 01:54

Re: OPR Formula
 
Quote:

Originally Posted by Ether (Post 1117638)
Yup. Identical.



Yes, I understood that. The remark in my previous post about Solver was in reference to your earlier post mentioning that Tom Line was using Solver.



Would that be ALGLIB ?


Yes, it is.

Ether 03-02-2012 11:19

Re: OPR Formula
 
Quote:

Originally Posted by brennonbrimhall (Post 1115315)
This is going to sound extremely stupid, but what is the formula for OPR?


The "short" answer is, the "formula" for OPR is

[A][OPR]~[SCORE]

...where OPR for a given team is one of the N elements of the [OPR] Nx1 column vector approximate solution to the overdetermined system of linear equations shown above. N is the number of teams, M is the number of matches, and [SCORE] is a (2M)x1 column vector of alliance scores for each match in the database being used to do the computation. [A] is a (2M)xN matrix generated from the database1.

There are several different methods for finding an approximate solution to an overdetermined system of linear equations1, but for this particular problem using Normal Equations and Cholesky factorization to find the least squares solution is perhaps the most common.

Normal Equations solution method:

Code:

Multiply both sides of [A][OPR]~[SCORE] by the transpose of [A]:

[A]T[A][OPR]=[A]T[SCORE]

which can be re-written as

[P][OPR]=[S]    (see footnote 2 below)

...where [P]=[A]T[A] and [S]=[A]T[SCORE]

then use Cholesky factorization (see footnote 3 below)
to find the lower triangular matrix [L] such that

[L][L]T=[P]

to get

[L][L]T[OPR]=[S]

now substitute [y] for [L]T[OPR] to get

[L][y]=[S]

and use forward substitution to solve for [y]

then, with [y] known, use backward substitution to solve

[L]T[OPR]=[y]

for [OPR]



1 I can provide the details if anyone's interested

2 The matrix [P] and the vector [S] can be constructed directly from the database, rather than constructing [A] and [SCORES]. In fact, doing so is quicker and requires less memory. I show all the steps in order to make it clear that [OPR] is an approximate solution to the overdetermined data in the database, and that approximate solutions other than least squares are possible.

3 [P]=[A]T[A] will be symmetric positive definite

MarkOfDinosaur 04-02-2012 17:06

Re: OPR Formula
 
I am having trouble understanding OPR. I had thought I had gotten it, but my results seem wrong. I'm pretty sure the problem lies with how i am performing the cholesky decomposition. I don't understand how to make a macro for it. I have looked into Ed Law's workbooks, but I still don't understand. Would it be possible for someone to explain how cholesky decomposition works, or is that too complicated?
Thanks

Ether 04-02-2012 17:59

Re: OPR Formula
 
1 Attachment(s)
Quote:

Originally Posted by MarkOfDinosaur (Post 1119942)
I am having trouble understanding OPR. I had thought I had gotten it, but my results seem wrong. I'm pretty sure the problem lies with how i am performing the cholesky decomposition. I don't understand how to make a macro for it. I have looked into Ed Law's workbooks, but I still don't understand. Would it be possible for someone to explain how cholesky decomposition works, or is that too complicated?
Thanks

Would you like to test your Cholesky implementation first to see if that is really the problem?

Attached is a 64x64 test matrix and its Cholesky factorization.

Both files are CSV so Excel should be able to open them directly.


Tom Line 04-02-2012 20:17

Re: OPR Formula
 
We're actually using matrix functions built into excel - no solver and no VB. It's three or four different pages of calculations. The first is the data, the second is the data sorted into the matrix, then we do the inverse matrix function, and output the final OPR values.

While it isn't the example I used to create our spreadsheet, this page will show you exactly how we go about it. Only the newer versions (2010 and newer) will allow large enough matrices to do the math.

http://www.duncanwil.co.uk/simult.html

Ether 04-02-2012 20:27

Re: OPR Formula
 
Quote:

Originally Posted by Tom Line (Post 1120085)
We're actually using matrix functions built into excel - no solver and no VB. It's three or four different pages of calculations. The first is the data, the second is the data sorted into the matrix, then we do the inverse matrix function, and output the final OPR values.

While it isn't the example I used to create our spreadsheet, this page will show you exactly how we go about it. Only the newer versions (2010 and newer) will allow large enough matrices to do the math.

http://www.duncanwil.co.uk/simult.html

Hi Tom,

Just curious: How long does it take to invert a 2053x2053 matrix in Excel?


Ether 04-02-2012 22:33

Re: OPR Formula
 
1 Attachment(s)

Attached is a 2053x2053 invertible matrix.

Would someone be willing to pull it into Excel 2010 (or newer) and test how long it takes to invert it1?

Thank you.



1how to invert a matrix in Excel: http://opim.wharton.upenn.edu/~guign...matrix_inv.pdf


Tom Line 05-02-2012 00:02

Re: OPR Formula
 
Excel 2010, 5 minutes 30 seconds.

i3 core @ 2.13, 8 GB ram, windows 7 64 bit home premium.

Ether 05-02-2012 00:28

Re: OPR Formula
 
1 Attachment(s)
Quote:

Originally Posted by Tom Line (Post 1120254)
Excel 2010, 5 minutes 30 seconds.

i3 core @ 2.13, 8 GB ram, windows 7 64 bit home premium.

Thanks Tom.

An optimized Cholesky algorithm solves the 2053x2053 system in a little over 12 seconds on a 3.4GHz Pentium D with 1GB RAM 32bit WinXP Pro SP3.


MarkOfDinosaur 06-02-2012 22:22

Re: OPR Formula
 
Quote:

Originally Posted by Ether (Post 1119962)
Would you like to test your Cholesky implementation first to see if that is really the problem?

Attached is a 64x64 test matrix and its Cholesky factorization.

Both files are CSV so Excel should be able to open them directly.


Ok, it works, thanks. Now, where do I go from here?

Ether 06-02-2012 23:12

Re: OPR Formula
 
Quote:

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

What version of Excel do you have?

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


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?



Ben Martin 26-02-2012 13:49

Re: OPR Formula
 
Quote:

Originally Posted by Ether (Post 1135024)
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?



I tried adapting the file to do this, but my current computing resources lack the memory to pull this off with my current algorithm. It does pull data and calculate for single competitions, though.

Ether 26-02-2012 15:16

Re: OPR Formula
 
Quote:

Originally Posted by BMartin 234 (Post 1135127)
I tried adapting the file to do this, but my current computing resources lack the memory to pull this off with my current algorithm. It does pull data and calculate for single competitions, though.

I see you are using Excel 2007 Mac. Is the problem a limit in the maximum number of columns in a worksheet?

If so, there are options:
1) You could upgrade to Excel 2010 which I believe has substantially expanded the maximum number of columns in a worksheet

2) You could construct the matrix in a VBA macro instead of spreadsheet cells and do the math on it there.
If you do option 2, you should seriously consider factoring the matrix instead of inverting. It's far faster and less susceptible to numerical instability.



Ben Martin 26-02-2012 15:23

Re: OPR Formula
 
Quote:

Originally Posted by Ether (Post 1135177)
I see you are using Excel 2007 Mac. Is the problem a limit in the maximum number of columns in a worksheet?

If so, there are options:
1) You could upgrade to Excel 2010 which I believe has substantially expanded the maximum number of columns in a worksheet

2) You could construct the matrix in a VBA macro instead of spreadsheet cells and do the math on it there.
If you do option 2, you should seriously consider factoring the matrix instead of inverting. It's far faster and less susceptible to numerical instability.



1) Nope, already using Excel 2010 on a Purdue University Windows computer.
2) Already doing this, all the calculations are done in code

I'll look into factoring. This was a quick-and-dirty, how easy can I make this solution originally intended for just finding OPR's for a given regional.

Ether 26-02-2012 15:34

Re: OPR Formula
 
Quote:

Originally Posted by BMartin 234 (Post 1135182)
1) Nope, already using Excel 2010 on a Purdue University Windows computer.

I was going by what was posted here.


Quote:

Already doing this, all the calculations are done in code
Why are you running out of memory? Even 2 Gig should be plenty, no?


Quote:

I'll look into factoring. This was a quick-and-dirty, how easy can I make this solution originally intended for just finding OPR's for a given regional.
Google Cholesky. It's not hard to code.



MarkOfDinosaur 26-02-2012 17:21

Re: OPR Formula
 
Finally got it. Thanks for all your help Ether. Phew, it's very satisfying to finally have it working. Thanks again.

Ether 26-02-2012 17:39

Re: OPR Formula
 
Quote:

Originally Posted by MarkOfDinosaur (Post 1135233)
Finally got it. Thanks for all your help Ether. Phew, it's very satisfying to finally have it working. Thanks again.

Way to hang in there !!!




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

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