Navigation | Overlay |
---|---|
t Navigate files | h Toggle hits |
y Change url to tip of branch | m Toggle misses |
b / v Jump to prev/next hit line | p Toggle partial |
z / x Jump to prev/next missed or partial line | 1..9 Toggle flags |
shift + o Open current page in GitHub | a Toggle all on |
/ or ? Show keyboard shortcuts dialog | c Toggle context lines or commits |
1 |
#include <Rcpp.h> |
|
2 |
using namespace Rcpp; |
|
3 |
|
|
4 |
// [[Rcpp::export]]
|
|
5 | 1 |
NumericMatrix approx_relative(NumericVector Nu, |
6 |
NumericVector Nd, |
|
7 |
IntegerMatrix P, |
|
8 |
bool iterative, |
|
9 |
int max_iter) { |
|
10 | 1 |
int n=Nu.size(); |
11 | 1 |
NumericMatrix rrp(n,n); |
12 | 1 |
for(int x=0;x<(n-1);++x){ |
13 | 1 |
for(int y=x+1;y<n;++y){ |
14 | 1 |
if(P(y,x)==1){ |
15 |
rrp(y,x)=1; |
|
16 |
rrp(x,y)=0; |
|
17 |
}
|
|
18 | 1 |
else if(P(x,y)==1){ |
19 | 1 |
rrp(y,x)=0; |
20 | 1 |
rrp(x,y)=1; |
21 |
}
|
|
22 |
else{ |
|
23 | 1 |
rrp(y,x)=double(Nu[y]+1)*(Nd[x]+1)/double((Nd[y]+1)*(Nu[x]+1)+(Nu[y]+1)*(Nd[x]+1)); |
24 | 1 |
rrp(x,y)=1-rrp(y,x); |
25 |
}
|
|
26 |
}
|
|
27 |
}
|
|
28 | 1 |
if(iterative){ |
29 | 1 |
for(int it=0; it<max_iter-1; ++it){ |
30 | 1 |
for(int i=0; i<n; ++i){ |
31 | 1 |
Nu[i]=sum(rrp(i,_)); |
32 | 1 |
Nd[i]=sum(rrp(_,i)); |
33 |
}
|
|
34 | 1 |
for(int x=0;x<(n-1);++x){ |
35 | 1 |
for(int y=x+1;y<n;++y){ |
36 | 1 |
if(P(y,x)==1){ |
37 |
rrp(y,x)=1; |
|
38 |
rrp(x,y)=0; |
|
39 |
}
|
|
40 | 1 |
else if(P(x,y)==1){ |
41 | 1 |
rrp(y,x)=0; |
42 | 1 |
rrp(x,y)=1; |
43 |
}
|
|
44 |
else{ |
|
45 |
rrp(y,x)=double(Nu[y]+1)*(Nd[x]+1)/double((Nd[y]+1)*(Nu[x]+1)+(Nu[y]+1)*(Nd[x]+1)); |
|
46 |
rrp(x,y)=1-rrp(y,x); |
|
47 |
}
|
|
48 |
}
|
|
49 |
}
|
|
50 |
}
|
|
51 |
}
|
|
52 | 1 |
return rrp; |
53 |
}
|
Read our documentation on viewing source code .