change output
This commit is contained in:
parent
9e130fa992
commit
106125e049
17
src/main.c
17
src/main.c
@ -12,7 +12,6 @@
|
||||
void test_stationary_distribution(const char *path) {
|
||||
struct timeval tvstart, tvend;
|
||||
|
||||
// Read and prepare the matrix
|
||||
gettimeofday(&tvstart, NULL);
|
||||
SparseMatrix *matrix = read_sparse_matrix_from_mtx(path);
|
||||
convert_to_stochastic(matrix);
|
||||
@ -22,32 +21,20 @@ void test_stationary_distribution(const char *path) {
|
||||
double epsilon = 1e-10;
|
||||
double alpha = 0.8;
|
||||
|
||||
// pagerank
|
||||
gettimeofday(&tvstart, NULL);
|
||||
double *pi_power = pagerank(matrix, epsilon, alpha);
|
||||
gettimeofday(&tvend, NULL);
|
||||
print_time_diff("Pagerank", &tvstart, &tvend);
|
||||
|
||||
// nable delta
|
||||
gettimeofday(&tvstart, NULL);
|
||||
double *pi_new = gauss_seidel_pagerank(matrix, epsilon, alpha);
|
||||
|
||||
gettimeofday(&tvend, NULL);
|
||||
print_time_diff("Gauss Seidel algorithm", &tvstart, &tvend);
|
||||
print_time_diff("Gauss-Seidel:", &tvstart, &tvend);
|
||||
|
||||
// Compare results
|
||||
double diff = diff_norm_vector(pi_power, pi_new, matrix->num_nodes);
|
||||
printf("Difference between power method and new algorithm: %.16f\n", diff);
|
||||
printf("Difference norm Pagerank and Gauss-Seidel: %.16f\n", diff);
|
||||
|
||||
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
printf("pi_old: %.16f\n", pi_power[i]);
|
||||
printf("pi_new: %.16f\n", pi_new[i]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
// Clean up
|
||||
free(pi_power);
|
||||
free(pi_new);
|
||||
free_sparse_matrix(matrix);
|
||||
|
@ -19,7 +19,6 @@ double* power_algorithm(const SparseMatrix *matrix, double epsilon) {
|
||||
init_vector(pi, N, 1.0/(double)N);
|
||||
pi2 = power_algorithm_step(matrix, pi);
|
||||
while (diff_norm_vector(pi, pi2, N)>epsilon) {
|
||||
printf("step\n");
|
||||
memcpy(pi, pi2, vecsize);
|
||||
pi2 = power_algorithm_step(matrix, pi);
|
||||
}
|
||||
@ -65,12 +64,15 @@ double* pagerank(const SparseMatrix *matrix, double epsilon, double alpha) {
|
||||
pi = pi_new;
|
||||
pi_new = malloc(vec_size);
|
||||
|
||||
if ((++iter)%1 == 0) {
|
||||
printf("Iteration %d: diff = %.16f\n", iter, diff);
|
||||
}
|
||||
// if ((++iter)%1 == 0) {
|
||||
// printf("Iteration %d: diff = %.16f\n", iter, diff);
|
||||
// }
|
||||
++iter;
|
||||
free(temp);
|
||||
} while (diff > epsilon);
|
||||
|
||||
printf("Pagerank: %d Iterations\n", iter);
|
||||
|
||||
free(pi_new);
|
||||
free(f);
|
||||
return pi;
|
||||
|
Loading…
x
Reference in New Issue
Block a user