sensasi-delight / eigenvector-centrality-php
A PHP library that help you calculates the Eigenvector Centrality value of an undirected graph. Eigenvector Centrality is one of the Social Network Analysis algorithms.
Requires
- php: 5.4 - 8
- markrogoyski/math-php: 1 - 2
This package is auto-updated.
Last update: 2024-12-10 00:16:30 UTC
README
A PHP library that help you calculates the Eigenvector Centrality value of an undirected graph. Eigenvector Centrality is one of the Social Network Analysis algorithms.
Installation
Install using composer:
composer require sensasi-delight/eigenvector-centrality-php
Usage
The usage examples of this library are also available on examples folder.
-
Make a Graph object
use SensasiDelight\Graph; $g = new Graph;
-
Define the nodes (optional)
$g->add_node('v1'); $g->add_node('v2'); $g->add_node('v3'); $g->add_node('v4'); $g->add_node('v5');
or
$g->add_nodes_from([ 'v1', 'v2', 'v3', 'v4', 'v5', ]);
-
Define the edges
$g->add_edge('v1', 'v2'); $g->add_edge('v1', 'v4'); $g->add_edge('v2', 'v3'); $g->add_edge('v2', 'v4'); $g->add_edge('v2', 'v5'); $g->add_edge('v3', 'v4');
or
$g->add_edges_from([ ['v1', 'v2'], ['v1', 'v4'], ['v2', 'v3'], ['v2', 'v4'], ['v2', 'v5'], ['v3', 'v4'] ]);
-
Get and print the Eigenvector Centrality value
$result = $g->get_eigenvector_centrality(); print_r($result);
it's should be returning output:
Array ( [v1] => 0.4119172769405 [v2] => 0.58253899962505 [v3] => 0.4119172769405 [v4] => 0.52368294422478 [v5] => 0.21691657788138 )
Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project.
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
). - Commit your Changes (
git commit -m 'Add some AmazingFeature'
). - Push to the Branch (
git push origin feature/AmazingFeature
). - Open a Pull Request.
License
The code is released under the MIT license.
Contact
- ✉ Email - zainadam.id@gmail.com
- 🐤 Twitter - @sensasi_DELIGHT