1
#include <Rcpp.h>
2
using namespace Rcpp;
3

4
// [[Rcpp::export]]
5 1
NumericVector approx_glpom(NumericMatrix P) {
6 1
  int n=P.ncol();
7 1
  NumericVector rapprox(n);
8 1
  IntegerVector elements = seq(0, rapprox.size()-1);
9 1
  IntegerVector Lxvec(n);
10 1
  IntegerVector Lyvec(n);
11 1
  IntegerVector Sxvec(n);
12 1
  std::vector<int> intersec;
13 1
  std::vector<int> diff;
14 1
  List Ix(n);
15 1
  List Sx(n); 
16 1
  for(int i=0;i<n;++i){
17 1
    rapprox[i]=sum(P(_,i))+1;
18 1
    Lxvec=elements[(P(_,i)==0) & (P(i,_)==0)];
19 1
    Ix[i]=Lxvec[Lxvec!=i];
20 1
    Sx[i]=elements[P(_,i)==1];
21
  }
22 1
  for(int x=0;x<n;++x){
23 1
    Lxvec=Ix[x];
24 1
    Sxvec=Sx[x];
25 1
    for(int j=0; j<Lxvec.size();++j){
26 1
      std::vector<int> intersec;
27 1
      std::vector<int> diff;
28 1
      int y=Lxvec[j];
29 1
      Lyvec=Ix[y];
30
      
31 1
      set_intersection(Sxvec.begin(),Sxvec.end(),Lyvec.begin(),Lyvec.end(),std::back_inserter(intersec));
32
      
33 1
      set_difference(Lyvec.begin(), Lyvec.end(), Lxvec.begin(), Lxvec.end(),std::inserter(diff, diff.begin()));
34 1
      rapprox[x]+=double(intersec.size()+1)/double(diff.size()+1);
35
    }
36
  }
37 1
  return rapprox;
38
}
39

40

Read our documentation on viewing source code .

Loading