-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add the src folder and update the documentation
- Loading branch information
1 parent
9affc08
commit aeae6cb
Showing
5 changed files
with
103 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.o | ||
*.so | ||
*.dll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Generated by using Rcpp::compileAttributes() -> do not edit by hand | ||
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 | ||
|
||
#include <Rcpp.h> | ||
|
||
using namespace Rcpp; | ||
|
||
// jaccard_coeff | ||
NumericMatrix jaccard_coeff(NumericMatrix idx, bool weight); | ||
RcppExport SEXP _monocle_jaccard_coeff(SEXP idxSEXP, SEXP weightSEXP) { | ||
BEGIN_RCPP | ||
Rcpp::RObject rcpp_result_gen; | ||
Rcpp::RNGScope rcpp_rngScope_gen; | ||
Rcpp::traits::input_parameter< NumericMatrix >::type idx(idxSEXP); | ||
Rcpp::traits::input_parameter< bool >::type weight(weightSEXP); | ||
rcpp_result_gen = Rcpp::wrap(jaccard_coeff(idx, weight)); | ||
return rcpp_result_gen; | ||
END_RCPP | ||
} | ||
|
||
static const R_CallMethodDef CallEntries[] = { | ||
{"_monocle_jaccard_coeff", (DL_FUNC) &_monocle_jaccard_coeff, 2}, | ||
{NULL, NULL, 0} | ||
}; | ||
|
||
RcppExport void R_init_monocle(DllInfo *dll) { | ||
R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); | ||
R_useDynamicSymbols(dll, FALSE); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include <Rcpp.h> | ||
using namespace Rcpp; | ||
|
||
// Compute jaccard coefficient between nearest-neighbor sets | ||
// | ||
// Weights of both i->j and j->i are recorded if they have intersection. In this case | ||
// w(i->j) should be equal to w(j->i). In some case i->j has weights while j<-i has no | ||
// intersections, only w(i->j) is recorded. This is determinded in code `if(u>0)`. | ||
// In this way, the undirected graph is symmetrized by halfing the weight | ||
// in code `weights(r, 2) = u/(2.0*ncol - u)/2`. | ||
// | ||
// Author: Chen Hao, Date: 25/09/2015; updated by Xiaojie Qiu Nov. 12, 2017 | ||
|
||
|
||
// [[Rcpp::export]] | ||
NumericMatrix jaccard_coeff(NumericMatrix idx, bool weight) { | ||
int nrow = idx.nrow(), ncol = idx.ncol(), r = 0; | ||
NumericMatrix weights(nrow*ncol, 3); | ||
|
||
for(int i = 0; i < nrow; i ++) { | ||
for(int j = 0; j < ncol; j ++) { | ||
int k = idx(i,j) - 1; | ||
|
||
weights(r, 0) = i + 1; | ||
weights(r, 1) = k + 1; | ||
weights(r, 2) = 1; | ||
|
||
if(weight == TRUE) { | ||
|
||
NumericVector nodei = idx(i, _); | ||
NumericVector nodej = idx(k, _); | ||
|
||
int u = intersect(nodei, nodej).size(); // count intersection number | ||
int v = 2 * ncol - u; // count union number | ||
|
||
if(u>0) { | ||
// weights(r, 0) = i + 1; | ||
// weights(r, 1) = k + 1; | ||
// weights(r, 2) = u / (2.0 * ncol - u) / 2; // symmetrize the graph | ||
|
||
weights(r, 2) = u / v; // normalize the values | ||
} | ||
} | ||
|
||
r ++; | ||
|
||
} | ||
} | ||
|
||
weights(_, 2) = weights(_, 2) / max(weights(_, 2)); | ||
|
||
return weights; | ||
} | ||
|
||
/*** | ||
edges$C = jaccard_dist | ||
edges = subset(edges, C != 0) | ||
edges$C = edges$C/max(edges$C) | ||
*/ |