You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

NormalizeCommonNeighbors.c 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include "mex.h"
  2. void commonNeighbors(mwIndex* ir, mwIndex* jc, double* pr, double *numNeighbors, mwSize n, mwIndex* ir_out, mwIndex* jc_out, double* pr_out)
  3. {
  4. //double averageNeighbors;
  5. int minNumNeighbors;
  6. int currCol = 0, nnzCurrCol, startIdx, stopIdx, i, j, currRow;
  7. int nnz = jc[n];
  8. jc_out[n] = jc[n];
  9. printf("nnz = %d\n", nnz);
  10. for (currCol = 0; currCol < n; currCol++)
  11. {
  12. jc_out[currCol] = jc[currCol];
  13. /*
  14. printf("jc_out[currCol] = %d, ", jc_out[currCol]);
  15. printf("currCol = %d\n ", currCol);
  16. */
  17. nnzCurrCol = jc[currCol + 1] - jc[currCol];
  18. /*printf("nnzCurrCol = %d ", nnzCurrCol);*/
  19. startIdx = jc[currCol];
  20. /*printf("startIdx = %d ", startIdx);*/
  21. stopIdx = jc[currCol + 1];
  22. /*printf("stopIdx = %d\n", stopIdx);*/
  23. for(i = startIdx; i < stopIdx; i++)
  24. {
  25. currRow = ir[i];
  26. //averageNeighbors = (numNeighbors[currRow] + numNeighbors[currCol]) / 2;
  27. minNumNeighbors = numNeighbors[currRow];
  28. if (minNumNeighbors > numNeighbors[currCol])
  29. {
  30. minNumNeighbors = numNeighbors[currCol];
  31. }
  32. /*printf("currRow = %d, currCol = %d, average neighbors = %f\n", currRow, currCol, averageNeighbors);*/
  33. //pr_out[i] = pr[i] / averageNeighbors;
  34. pr_out[i] = pr[i] / minNumNeighbors;
  35. ir_out[i] = ir[i];
  36. }
  37. }
  38. }
  39. /* The gateway function
  40. //this function accepts two parameters:
  41. //1. a sparse affinity matrix (should be the number of common neighbors between nodes i and j
  42. //2. an array with the number of neighbors of each node
  43. */
  44. void mexFunction( int nlhs, mxArray *plhs[],
  45. int nrhs, const mxArray *prhs[])
  46. {
  47. /* variable declarations here */
  48. mwIndex* ir;
  49. mwIndex* jc;
  50. double* pr;
  51. mwIndex* ir_out;
  52. mwIndex* jc_out;
  53. double* pr_out;
  54. double* numNeighbors;
  55. mwSize n;
  56. int i;
  57. /*printf("nlhs = %d, nrhs = %d\n", nlhs, nrhs);*/
  58. ir = mxGetIr(prhs[0]);
  59. jc = mxGetJc(prhs[0]);
  60. pr = mxGetPr(prhs[0]);
  61. numNeighbors = mxGetPr(prhs[1]);
  62. n = mxGetN(prhs[1]);
  63. plhs[0] = mxCreateSparse(n,n, jc[n], mxREAL);
  64. ir_out = mxGetIr(plhs[0]);
  65. jc_out = mxGetJc(plhs[0]);
  66. pr_out = mxGetPr(plhs[0]);
  67. /*
  68. //printf("pr_out = %d", pr_out);
  69. //printf("n = %d\n",n);
  70. //printf("ir[0] = %d, jc[0] = %d, pr[0] = %f\n", ir[0], jc[0], pr[0]);
  71. //printf("numNeighbors[0] = %f, numNeighbors[1] = %f\n", numNeighbors[0], numNeighbors[1]);
  72. */
  73. commonNeighbors(ir, jc, pr, numNeighbors, n, ir_out, jc_out, pr_out);
  74. }