3 // [[Rcpp::depends(BH, bigmemory)]]
4 #include <bigmemory/MatrixAccessor.hpp>
11 //' computeMedoidsIndices
13 //' Compute medoids indices
15 //' @param pMedoids External pointer
16 //' @param ref_series reference series
18 //' @return A map serie number -> medoid index
20 IntegerVector
computeMedoidsIndices(SEXP pMedoids
, NumericMatrix ref_series
)
22 XPtr
<BigMatrix
> pMed(pMedoids
);
23 MatrixAccessor
<double> medoids
= MatrixAccessor
<double>(*pMed
);
24 int nb_series
= ref_series
.ncol(),
27 IntegerVector
mi(nb_series
);
29 for (int i
=0; i
<nb_series
; i
++)
31 // mi[i] <- which.min( rowSums( sweep(medoids, 2, ref_series[i,], '-')^2 ) )
33 double best_dist
= DBL_MAX
;
34 for (int j
=0; j
<K
; j
++)
37 for (int k
=0; k
<L
; k
++)
39 double delta
= ref_series(k
,i
) - *(medoids
[j
]+k
);
40 dist_ij
+= delta
* delta
;
42 if (dist_ij
< best_dist
)
44 mi
[i
] = j
+1; //R indices start at 1