-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitcorr.cpp
28 lines (25 loc) · 870 Bytes
/
bitcorr.cpp
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
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
// calcolo dell'agreement fra bitset
NumericVector compute_bitcor_CPP(NumericMatrix bitvects) {
std::vector<std::vector<double>*>* COR = new std::vector<std::vector<double>*>();
for(int i=0; i<bitvects.nrow(); i++){
COR->push_back(new std::vector<double>());
for(int j=0; j<=i; j++){
COR->at(i)->push_back(0);
for(int k=0;k<bitvects.ncol();k++){
COR->at(i)->at(j) += (bitvects(i,k) == bitvects(j,k))?1:0;
}
COR->at(i)->at(j) /= bitvects.ncol();
}
}
NumericMatrix out(bitvects.nrow(),bitvects.nrow());
for(int i=0; i<bitvects.nrow(); i++){
for(int j=0; j<=i; j++){
out(i,j) = COR->at(i)->at(j);
out(j,i) = COR->at(i)->at(j);
}
}
return out;
}