Browse Source

Implement filter-based modified adaptive algorithm

master
Apostolos Fanakis 6 years ago
parent
commit
3d6bc5d9cf
No known key found for this signature in database GPG Key ID: 56CE2DEDE9F1FB78
  1. 52
      serial/serial_gs_pagerank_functions.c
  2. 6
      serial/serial_gs_pagerank_functions.h

52
serial/serial_gs_pagerank_functions.c

@ -17,10 +17,20 @@ int pagerank(double ***transitionMatrix, double **pagerankVector, Parameters par
double delta, double delta,
*vectorDifference = (double *) malloc(parameters.numberOfPages * sizeof(double)), *vectorDifference = (double *) malloc(parameters.numberOfPages * sizeof(double)),
*previousPagerankVector = (double *) malloc(parameters.numberOfPages * sizeof(double)), *previousPagerankVector = (double *) malloc(parameters.numberOfPages * sizeof(double)),
*convergedPagerankVector = (double *) malloc(parameters.numberOfPages * sizeof(double)); *convergedPagerankVector = (double *) malloc(parameters.numberOfPages * sizeof(double)),
**linksFromConvergedPages = (double **) malloc(parameters.numberOfPages * sizeof(double *)),
*linksFromConvergedPagesPagerankVector = (double *) malloc(parameters.numberOfPages * sizeof(double));
bool *converganceMatrix = (bool *) malloc(parameters.numberOfPages * sizeof(bool));
for (int i=0; i<parameters.numberOfPages; ++i) { for (int i=0; i<parameters.numberOfPages; ++i) {
convergedPagerankVector[i] = 0; convergedPagerankVector[i] = 0;
converganceMatrix[i] = false;
linksFromConvergedPagesPagerankVector[i] = 0;
linksFromConvergedPages[i] = (double *) malloc(parameters.numberOfPages * sizeof(double));
for (int j=0; j<parameters.numberOfPages; ++j) {
linksFromConvergedPages[i][j] = 0;
}
} }
if (parameters.verbose) { if (parameters.verbose) {
@ -30,7 +40,8 @@ int pagerank(double ***transitionMatrix, double **pagerankVector, Parameters par
do { do {
memcpy(previousPagerankVector, *pagerankVector, parameters.numberOfPages * sizeof(double)); memcpy(previousPagerankVector, *pagerankVector, parameters.numberOfPages * sizeof(double));
matrixVectorMultiplication(transitionMatrix, previousPagerankVector, convergedPagerankVector, matrixVectorMultiplication(*transitionMatrix, previousPagerankVector,
linksFromConvergedPagesPagerankVector, convergedPagerankVector,
pagerankVector, parameters.numberOfPages, parameters.dampingFactor); pagerankVector, parameters.numberOfPages, parameters.dampingFactor);
if (parameters.history) { if (parameters.history) {
@ -43,14 +54,32 @@ int pagerank(double ***transitionMatrix, double **pagerankVector, Parameters par
} }
delta = vectorNorm(vectorDifference, parameters.numberOfPages); delta = vectorNorm(vectorDifference, parameters.numberOfPages);
if (!iterations % 5) { if (!iterations % 10) {
for (int i=0; i<parameters.numberOfPages; ++i) { for (int i=0; i<parameters.numberOfPages; ++i) {
double temp = fabs((*pagerankVector)[i] - previousPagerankVector[i]) / fabs(previousPagerankVector[i]); double temp = fabs((*pagerankVector)[i] - previousPagerankVector[i]) / fabs(previousPagerankVector[i]);
if (temp < parameters.convergenceCriterion){ if (temp < parameters.convergenceCriterion){
converganceMatrix[i] = true;
convergedPagerankVector[i] = (*pagerankVector)[i]; convergedPagerankVector[i] = (*pagerankVector)[i];
}
}
for (int i=0; i<parameters.numberOfPages; ++i) {
if (converganceMatrix[i] == true) {
for (int j=0; j<parameters.numberOfPages; ++j){ for (int j=0; j<parameters.numberOfPages; ++j){
if (converganceMatrix[j] == false){
linksFromConvergedPages[i][j] = (*transitionMatrix)[i][j];
}
// Zeros out CN and CC sub-matrices
(*transitionMatrix)[i][j] = 0; (*transitionMatrix)[i][j] = 0;
// Zeros out NC sub-matrix
(*transitionMatrix)[j][i] = 0;
}
double sum = 0;
for (int j=0; j<parameters.numberOfPages; ++j) {
sum += linksFromConvergedPages[i][j] * (*pagerankVector)[j];
} }
linksFromConvergedPagesPagerankVector[i] = sum;
} }
} }
} }
@ -157,25 +186,26 @@ void generateNormalizedTransitionMatrix(double ***transitionMatrix,
* matrixVectorMultiplication calculates the product of the multiplication * matrixVectorMultiplication calculates the product of the multiplication
* between a matrix and the a vector in a cheap way. * between a matrix and the a vector in a cheap way.
*/ */
void matrixVectorMultiplication(double ***matrix, double *vector, void matrixVectorMultiplication(double **transitionMatrix, double *previousPagerankVector,
double *convergedPagerankVector, double **product, int vectorSize, double *linksFromConvergedPagesPagerankVector, double *convergedPagerankVector,
double dampingFactor) { double **pagerankVector, int vectorSize, double dampingFactor) {
double webUniformProbability = 1. / vectorSize; double webUniformProbability = 1. / vectorSize;
for (int i=0; i<vectorSize; ++i) { for (int i=0; i<vectorSize; ++i) {
double sum = 0; double sum = 0;
for (int j=0; j<vectorSize; ++j) { for (int j=0; j<vectorSize; ++j) {
sum += (*matrix)[i][j] * vector[j]; sum += transitionMatrix[i][j] * previousPagerankVector[j];
} }
(*product)[i] = dampingFactor * sum + convergedPagerankVector[i]; (*pagerankVector)[i] = dampingFactor * sum;
} }
double normDifference = vectorNorm(vector, vectorSize) - double normDifference = vectorNorm(previousPagerankVector, vectorSize) -
vectorNorm((*product), vectorSize); vectorNorm(*pagerankVector, vectorSize);
for (int i=0; i<vectorSize; ++i) { for (int i=0; i<vectorSize; ++i) {
(*product)[i] += normDifference * webUniformProbability; (*pagerankVector)[i] += normDifference * webUniformProbability +
linksFromConvergedPagesPagerankVector[i] + convergedPagerankVector[i];
} }
} }

6
serial/serial_gs_pagerank_functions.h

@ -74,9 +74,9 @@ double vectorNorm(double *vector, int vectorSize);
// Function matrixVectorMultiplication calculates the product of the // Function matrixVectorMultiplication calculates the product of the
// multiplication between a matrix and the a vector. // multiplication between a matrix and the a vector.
void matrixVectorMultiplication(double ***matrix, double *vector, void matrixVectorMultiplication(double **transitionMatrix, double *previousPagerankVector,
double *convergedPagerankVector, double **product, int vectorSize, double *linksFromConvergedPagesPagerankVector, double *convergedPagerankVector,
double dampingFactor); double **pagerankVector, int vectorSize, double dampingFactor);
// Function pagerank iteratively calculates the pagerank of each page until // Function pagerank iteratively calculates the pagerank of each page until
// either the convergence criterion is met or the maximum number of iterations // either the convergence criterion is met or the maximum number of iterations

Loading…
Cancel
Save