Class: OPRCalc::ScoreSet
- Inherits:
-
Object
- Object
- OPRCalc::ScoreSet
- Defined in:
- lib/opr-calc/score_set.rb
Instance Attribute Summary collapse
-
#ablue ⇒ Object
Returns the value of attribute ablue.
-
#ared ⇒ Object
Returns the value of attribute ared.
-
#scoreblue ⇒ Object
Returns the value of attribute scoreblue.
-
#scorered ⇒ Object
Returns the value of attribute scorered.
Instance Method Summary collapse
-
#ccwm(recalc = false) ⇒ Object
Calculated contribution to winning margin: the average amount of points that a team contributes to their alliance’s winning margin.
-
#dpr(recalc = false) ⇒ Object
Defensive power rating: the average amount of points that a team lets the other alliance score.
-
#initialize(ared, ablue, scorered, scoreblue) ⇒ ScoreSet
constructor
A new instance of ScoreSet.
-
#opr(recalc = false) ⇒ Object
Offensive power rating: the average amount of points that a team contributes to their alliance’s score.
-
#opr_calculate(a, score) ⇒ Object
base matrix equation: [A] = [SCORE] define [A]^t to be [A] transpose define [P] to be [A]^t define [S] to be [A]^t equation is now [P] = [S] refactor [P] as [L]^t using cholesky [L] is a lower triangular matrix and [L]^t an upper Therefore [L]^t = [S] define [Y] = [L]^t equation is now [L] = [S] find [Y] through forward substitution find [OPR] through back substitution.
Constructor Details
#initialize(ared, ablue, scorered, scoreblue) ⇒ ScoreSet
Returns a new instance of ScoreSet.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/opr-calc/score_set.rb', line 43 def initialize(ared, ablue, scorered, scoreblue) raise TypeError, "ared must be a Matrix" unless ared.is_a? Matrix raise TypeError, "ablue must be a Matrix" unless ablue.is_a? Matrix raise TypeError, "scorered must be a Matrix" unless scorered.is_a? Matrix raise TypeError, "scoreblue must be a Matrix" unless scoreblue.is_a? Matrix @ared = ared @ablue = ablue @scorered = scorered @scoreblue = scoreblue end |
Instance Attribute Details
#ablue ⇒ Object
Returns the value of attribute ablue.
21 22 23 |
# File 'lib/opr-calc/score_set.rb', line 21 def ablue @ablue end |
#ared ⇒ Object
Returns the value of attribute ared.
21 22 23 |
# File 'lib/opr-calc/score_set.rb', line 21 def ared @ared end |
#scoreblue ⇒ Object
Returns the value of attribute scoreblue.
21 22 23 |
# File 'lib/opr-calc/score_set.rb', line 21 def scoreblue @scoreblue end |
#scorered ⇒ Object
Returns the value of attribute scorered.
21 22 23 |
# File 'lib/opr-calc/score_set.rb', line 21 def scorered @scorered end |
Instance Method Details
#ccwm(recalc = false) ⇒ Object
Calculated contribution to winning margin: the average amount of points that a team contributes to their alliance’s winning margin. This is high for a good team.
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/opr-calc/score_set.rb', line 192 def ccwm(recalc = false) if !@ccwm || recalc || @ccwm_recalc a = alliance_smooshey @ared, @ablue red_wm = Matrix.build(@scorered.row_size, @scorered.column_size) do |row, column| @scorered[row, column] - @scoreblue[row, column] end blue_wm = Matrix.build(@scoreblue.row_size, @scoreblue.column_size) do |row, column| @scoreblue[row, column] - @scorered[row, column] end score = alliance_smooshey red_wm, blue_wm @ccwm = opr_calculate a, score @ccwm_recalc = false end @ccwm end |
#dpr(recalc = false) ⇒ Object
Defensive power rating: the average amount of points that a team lets the other alliance score. This is low for a good team.
178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/opr-calc/score_set.rb', line 178 def dpr(recalc = false) if !@dpr || recalc || @dpr_recalc a = alliance_smooshey @ared, @ablue score = alliance_smooshey @scoreblue, @scorered # intentionally swapped, that's how dpr works. @dpr = opr_calculate a, score @dpr_recalc = false end @dpr end |
#opr(recalc = false) ⇒ Object
Offensive power rating: the average amount of points that a team contributes to their alliance’s score. This is high for a good team.
164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/opr-calc/score_set.rb', line 164 def opr(recalc = false) if !@opr || recalc || @opr_recalc a = alliance_smooshey @ared, @ablue score = alliance_smooshey @scorered, @scoreblue @opr = opr_calculate a, score @opr_recalc = false end @opr end |
#opr_calculate(a, score) ⇒ Object
base matrix equation: [A] = [SCORE] define [A]^t to be [A] transpose define [P] to be [A]^t define [S] to be [A]^t equation is now [P] = [S] refactor [P] as [L]^t using cholesky
- L
-
is a lower triangular matrix and [L]^t an upper
Therefore [L]^t = [S] define [Y] = [L]^t equation is now [L] = [S] find [Y] through forward substitution find [OPR] through back substitution
149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/opr-calc/score_set.rb', line 149 def opr_calculate(a, score) p = a.t * a s = a.t * score l = p.cholesky_factor # l.output # l.t.output y = forward_substitute l, s back_substitute l.t, y end |