Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
devuci
bct-cpp
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
bct-cpp
/
eigenvector_centrality.cpp
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
58 lines (49 loc) · 1.49 KB
master
Breadcrumbs
bct-cpp
/
eigenvector_centrality.cpp
Copy path
Top
File metadata and controls
Code
Blame
58 lines (49 loc) · 1.49 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <cmath>
#include "bct.h"
/*
* Finds the dominant eigenvector using power iteration. Adapted from
* NetworkX v1.4 eigenvector_centrality.
*
* http://www.mathworks.de/matlabcentral/fx_files/7978/1/mPowerEig.c
* http://en.wikipedia.org/wiki/Power_iteration
*/
VECTOR_T* BCT_NAMESPACE::eigenvector_centrality(const MATRIX_T* G) {
if (safe_mode) check_status(G, SQUARE, "eigenvector_centrality");
FP_T tol = 1e-6; // Ensures that the average value is stable at 1e-6
int maxiter = 1000;
int N = G->size1;
VECTOR_T* x = VECTOR_ID(alloc)(N);
VECTOR_T* xlast = VECTOR_ID(alloc)(N);
// Note that this starting vector is already normalized (elements sum to 1)
FP_T startval = 1.0 / (FP_T)N;
VECTOR_ID(set_all)(x, startval);
FP_T evec_norm;
FP_T err;
FP_T newval;
for (int iter = 0; iter < maxiter; iter++) {
err = 0.0;
VECTOR_ID(memcpy)(xlast, x);
VECTOR_ID(set_zero)(x);
#ifdef _OPENMP
#pragma omp parallel for private(newval) shared(x, xlast)
#endif
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
newval = VECTOR_ID(get)(x, i) + VECTOR_ID(get)(xlast, j) * MATRIX_ID(get)(G, i, j);
VECTOR_ID(set)(x, i, newval);
}
}
// Normalize vector
evec_norm = norm(x, 2);
VECTOR_ID(scale)(x, 1.0 / evec_norm);
// Check convergence
for (int i = 0; i < (int)x->size; i++) {
err += std::abs(VECTOR_ID(get)(x, i) - VECTOR_ID(get)(xlast, i));
}
if (err < (FP_T)N * tol) {
break; // End power iteration
}
}
VECTOR_ID(free)(xlast);
return x;
}
You can’t perform that action at this time.