#include#include #include using namespace std;int main(int argc, const char * argv[]){ double sum = 0.0; double qcur[5] = {1,1,1,1,1},qnext[5],qmid[5]; double S[5][5] = {0,0.5,0.5,0,0.5,0.25,0,0,0,0,0.25,0,0,1,0.5,0.25,0.5,0.5,0,0,0.25,0,0,0,0}; double G[5][5]; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { G[i][j] = 0.85 * S[i][j] + 0.01; cout<<G[i][j]<<',';//看下G里的数据是什么 } } cout<<endl; while (sum < 0.1) { for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { qnext[i] += G[i][j] * qcur[j]; } qmid[i] = qnext[i]; } for (int k = 0 ; k < 5; k++) { qcur[k] = qmid[k]; } for (int i = 0; i < 5; i++) { sum += (qnext[i] + qcur[i]) * (qnext[i] + qcur[i]); } sum = sqrt(sum); } for (int i = 0; i < 5; i++) { cout<<fixed<<setprecision(2)<<qnext[i]<<" "; } return 0;}
PageRank算法,大家一起学习。自己按照谷歌的思路书写的。
最新推荐文章于 2024-09-04 21:39:45 发布