32 double *
rscale, *prold, *prnew, *prtmp;
33 double fromsinks,
error;
43 prold = gk_dsmalloc(nrows, 0,
"gk_rw_PageRank: prnew");
44 prnew = gk_dsmalloc(nrows, 0,
"gk_rw_PageRank: prold");
45 rscale = gk_dsmalloc(nrows, 0,
"gk_rw_PageRank: rscale");
49 for (i=0; i<nrows; i++) {
50 for (j=rowptr[i]; j<rowptr[i+1]; j++)
51 rscale[i] += rowval[j];
53 rscale[
i] = 1.0/rscale[
i];
57 for (i=0; i<nrows; i++)
61 for (iter=0; iter<max_niter; iter++) {
63 gk_dset(nrows, 0.0, prnew);
68 for (fromsinks=0.0, i=0; i<nrows; i++) {
70 fromsinks += prold[
i];
74 for (i=0; i<nrows; i++) {
75 for (j=rowptr[i]; j<rowptr[i+1]; j++)
76 prnew[rowind[j]] += prold[i]*rscale[i]*rowval[j];
80 for (i=0; i<nrows; i++) {
81 prnew[
i] = lamda*(fromsinks*pr[
i]+prnew[
i]) + (1.0-lamda)*pr[
i];
85 for (error=0.0, i=0; i<nrows; i++)
86 error = (
fabs(prnew[i]-prold[i]) > error ?
fabs(prnew[i]-prold[i]) :
error);
95 for (i=0; i<nrows; i++)
100 return (
int)(iter+1);
#define gk_SWAP(a, b, tmp)
iterator iter(handle obj)
void gk_free(void **ptr1,...)
int gk_rw_PageRank(gk_csr_t *mat, float lamda, float eps, int max_niter, float *pr)