-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathasMatrix.cpp
More file actions
76 lines (68 loc) · 1.66 KB
/
Copy pathasMatrix.cpp
File metadata and controls
76 lines (68 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
NumericMatrix eloRunAsMatrix(NumericMatrix mat, NumericVector initialElos, LogicalVector group)
{
// this function uses 1-based indexing, since the incoming matrix does, too
double nTeams = initialElos.size();
double nGames = mat.nrow();
double nOut = sum(group);
int nBoth = (mat.ncol() - 4) / 2;
NumericMatrix out(nOut, nTeams);
NumericVector curr(nTeams);
curr = clone(initialElos);
int outRow = 0;
for(int i = 0; i < nGames; i++)
{
for(int j = 0; j < nBoth; j++)
{
double tm = mat(i, j);
if(tm > 0)
{
curr[tm - 1] = mat(i, nBoth + 4 + j);
}
}
if(group[i])
{
out(outRow, _) = curr;
outRow++;
}
}
return out;
}
// [[Rcpp::export]]
NumericMatrix eloRunRegressedAsMatrix(NumericMatrix mat, NumericVector initialElos,
NumericMatrix regMat, LogicalVector regress, LogicalVector group)
{
// this function uses 1-based indexing, since the incoming matrix does, too
double nTeams = initialElos.size();
double nGames = mat.nrow();
double nOut = sum(group);
int nBoth = (mat.ncol() - 4) / 2;
NumericMatrix out(nOut, nTeams);
NumericVector curr(nTeams);
curr = clone(initialElos);
int regRow = 0, outRow = 0;
for(int i = 0; i < nGames; i++)
{
if(i > 0 && regress[i - 1])
{
curr = regMat(regRow, _);
regRow++;
}
for(int j = 0; j < nBoth; j++)
{
double tm = mat(i, j);
if(tm > 0)
{
curr[tm - 1] = mat(i, nBoth + 4 + j);
}
}
if(group[i])
{
out(outRow, _) = curr;
outRow++;
}
}
return out;
}