graphology-metrics
Advanced tools
Comparing version 1.6.0 to 1.6.1
@@ -17,3 +17,3 @@ /** | ||
attributes: { | ||
centrality: 'beetweennessCentrality', | ||
centrality: 'betweennessCentrality', | ||
weight: 'weight' | ||
@@ -130,5 +130,5 @@ }, | ||
*/ | ||
var beetweennessCentrality = abstractBetweennessCentrality.bind(null, false); | ||
beetweennessCentrality.assign = abstractBetweennessCentrality.bind(null, true); | ||
var betweennessCentrality = abstractBetweennessCentrality.bind(null, false); | ||
betweennessCentrality.assign = abstractBetweennessCentrality.bind(null, true); | ||
module.exports = beetweennessCentrality; | ||
module.exports = betweennessCentrality; |
@@ -15,7 +15,8 @@ /** | ||
* | ||
* @param {boolean} assign - Whether to assign the result to the nodes. | ||
* @param {string} method - Method of the graph to get the degree. | ||
* @param {Graph} graph - A graphology instance. | ||
* @param {object} [options] - Options: | ||
* @param {string} [attribute] - Name of the attribute to assign. | ||
* @param {boolean} assign - Whether to assign the result to the nodes. | ||
* @param {string} method - Method of the graph to get the degree. | ||
* @param {Graph} graph - A graphology instance. | ||
* @param {object} [options] - Options: | ||
* @param {object} [attributes] - Custom attribute names: | ||
* @param {string} [centrality] - Name of the attribute to assign. | ||
* @return {object|void} | ||
@@ -35,4 +36,6 @@ */ | ||
var attribute = options.attribute || name; | ||
var attributes = options.attributes || {}; | ||
var centralityAttribute = attributes.centrality || name; | ||
// Variables | ||
@@ -59,3 +62,3 @@ var order = graph.order, | ||
if (assign) | ||
graph.setNodeAttribute(node, attribute, centrality); | ||
graph.setNodeAttribute(node, centralityAttribute, centrality); | ||
else | ||
@@ -62,0 +65,0 @@ centralities[node] = centrality; |
@@ -110,2 +110,6 @@ /** | ||
// When the graph has only one node, its density is 0 | ||
if (order < 2) | ||
return 0; | ||
// Guessing type & multi | ||
@@ -112,0 +116,0 @@ if (type === null) |
@@ -11,3 +11,3 @@ /** | ||
* - if there are a->b and b->a : consider a<->b | ||
* - if there is a-> only or b->a only : consider ALSO a<->b | ||
* - if there is a->b only or b->a only : consider ALSO a<->b | ||
* - if there are a->b , b->a with differents weights, only one is considered | ||
@@ -14,0 +14,0 @@ * |
{ | ||
"name": "graphology-metrics", | ||
"version": "1.6.0", | ||
"version": "1.6.1", | ||
"description": "Miscellaneous graph metrics for graphology.", | ||
@@ -45,16 +45,22 @@ "main": "index.js", | ||
"@yomguithereal/eslint-config": "^4.0.0", | ||
"chai": "^4.0.0", | ||
"eslint": "^4.18.2", | ||
"graphology": "^0.11.2", | ||
"graphology-generators": "^0.9.0", | ||
"mocha": "^5.0.4" | ||
"chai": "^4.2.0", | ||
"eslint": "^6.6.0", | ||
"graphology": "^0.14.1", | ||
"graphology-generators": "^0.10.1", | ||
"mocha": "^6.2.2" | ||
}, | ||
"eslintConfig": { | ||
"extends": "@yomguithereal/eslint-config" | ||
"extends": "@yomguithereal/eslint-config", | ||
"rules": { | ||
"space-before-function-paren": [ | ||
2, | ||
"never" | ||
] | ||
} | ||
}, | ||
"dependencies": { | ||
"graphology-shortest-path": "^1.0.1", | ||
"graphology-utils": "^1.3.0", | ||
"lodash": "^4.17.5" | ||
"graphology-utils": "^1.3.1", | ||
"lodash": "^4.17.11" | ||
} | ||
} |
119
README.md
@@ -24,2 +24,3 @@ [![Build Status](https://travis-ci.org/graphology/graphology-metrics.svg)](https://travis-ci.org/graphology/graphology-metrics) | ||
* [Degree](#degree) | ||
* [Centrality](#centrality) | ||
@@ -30,2 +31,6 @@ - [Betweenness centrality](#betweenness-centrality) | ||
*Attributes metrics* | ||
* [Modalities](#modalities) | ||
### Density | ||
@@ -148,2 +153,71 @@ | ||
### Degree | ||
Returns degree information for every node in the graph. Note that [`graphology`](https://graphology.github.io)'s API already gives you access to this information through `#.degree` etc. So only consider this function as a convenience to extract/assign all degrees at once. | ||
```js | ||
import degree from 'graphology-metrics/degree'; | ||
import degree, { | ||
inDegree, | ||
outDegree, | ||
undirectedDegree, | ||
directedDegree, | ||
allDegree | ||
} from 'graphology-metrics/degree'; | ||
// To extract degree information for every node | ||
const degrees = degree(graph); | ||
>>> {node1: 34, node2: 45, ...} | ||
// To extract only in degree information for every node | ||
const inDegrees = inDegree(graph); | ||
// To extract full degree breakdown for every node | ||
const degrees = allDegree(graph); | ||
>>> { // Assuming the graph is directed | ||
node1: { | ||
inDegree: 2, | ||
outDegree: 36 | ||
}, | ||
... | ||
} | ||
// To map degree information to node attributes | ||
degree.assign(graph); | ||
graph.getNodeAttribute(node, 'degree'); | ||
>>> 45 | ||
// To map only degree & in degree to node attributes | ||
allDegree.assign(graph, {types: ['degree', 'inDegree']}); | ||
// To map only degree & in degree with different names | ||
allDegree( | ||
graph, | ||
{ | ||
attributes: { | ||
inDegree: 'in', | ||
outDegree: 'out' | ||
}, | ||
types: ['inDegree', 'outDegree'] | ||
} | ||
) | ||
>>> { | ||
1: {in: 1, out: 1}, | ||
... | ||
} | ||
``` | ||
*Arguments* | ||
* **graph** *Graph*: target graph. | ||
* **options** *?object*: options: | ||
- **attributes** *?object*: Custom attribute names: | ||
+ **degree** *?string*: Name of the mixed degree attribute. | ||
+ **inDegree** *?string*: Name of the mixed inDegree attribute. | ||
+ **outDegree** *?string*: Name of the mixed outDegree attribute. | ||
+ **undirectedDegree** *?string*: Name of the mixed undirectedDegree attribute. | ||
+ **directedDegree** *?string*: Name of the mixed directedDegree attribute. | ||
- **types** *?array*: List of degree types to extract. | ||
### Centrality | ||
@@ -164,3 +238,3 @@ | ||
// To directly map the result onto nodes' attributes (`beetweennessCentrality`): | ||
// To directly map the result onto nodes' attributes (`betweennessCentrality`): | ||
betweennessCentrality.assign(graph); | ||
@@ -202,3 +276,3 @@ | ||
// To directly map the result onto a custom attribute: | ||
degreeCentrality.assign(graph, {attribute: 'myCentrality'}); | ||
degreeCentrality.assign(graph, {attributes: {centrality: 'myCentrality'}}); | ||
``` | ||
@@ -210,3 +284,4 @@ | ||
* **options** *?object*: options: | ||
* **attribute** *?string*: name of the centrality attribute. | ||
* **attributes** *?object*: custom attribute names: | ||
* **centrality** *?string* [`degreeCentrality`]: name of the centrality attribute to assign. | ||
@@ -258,2 +333,38 @@ ### Weighted degree | ||
- **weightedDegree** *?string* [`weightedDegree`]: name of the attribute to assign. | ||
* **averaged** *?boolean* [`false`]: return averaged weighted degree. | ||
### Modalities | ||
Method returning a node categorical attribute's modalities and related statistics. | ||
```js | ||
import modalities from 'graphology-metrics/modalities'; | ||
// Retrieving the 'type' attribute's modalities | ||
const info = modalities(graph, 'type'); | ||
>>> { | ||
value1: { | ||
nodes: 34, | ||
internalEdges: 277, | ||
internalDensity: 0.03, | ||
externalEdges: 45, | ||
externalDensity: 0.05, | ||
inboundEdges: 67, | ||
inboundDensity: 0.07, | ||
outboundEdges: 124, | ||
outboundDensity: 0.003 | ||
}, | ||
... | ||
} | ||
// Retrieving modalities info for several attributes at once | ||
const info = modalities(graph, ['type', 'lang']); | ||
>>> { | ||
type: {...}, | ||
lang: {...} | ||
} | ||
``` | ||
*Arguments* | ||
* **graph** *Graph*: target graph. | ||
* **attribute** *string|array*: target categorical attribute or array of categorical attributes. |
@@ -28,3 +28,2 @@ /** | ||
* @param {string} [weightedDegree] - Name of the attribute to set. | ||
* @param {boolean} [averaged] - Return averaged weighted degree? | ||
* | ||
@@ -42,3 +41,2 @@ * Signature n°2 - computing weighted degree for a single node: | ||
* @param {string} [weightedDegree] - Name of the attribute to set. | ||
* @param {boolean} [averaged] - Return averaged weighted degrees? | ||
* | ||
@@ -73,7 +71,4 @@ * @return {object|void} | ||
var averaged = options.averaged === true; | ||
var edges, | ||
d, | ||
W, | ||
w, | ||
@@ -84,3 +79,3 @@ i, | ||
// Computing weighted degree for a single node | ||
if (singleNode) { | ||
if (singleNode) { | ||
edges = graph[edgeGetter](singleNode); | ||
@@ -96,6 +91,3 @@ d = 0; | ||
if (averaged) | ||
d /= l || 1; | ||
if (assign) { | ||
if (assign) { | ||
graph.setNodeAttribute(singleNode, weightedDegreeAttribute, d); | ||
@@ -129,5 +121,2 @@ return; | ||
if (averaged) | ||
d /= m || 1; | ||
if (assign) | ||
@@ -134,0 +123,0 @@ graph.setNodeAttribute(node, weightedDegreeAttribute, d); |
@@ -43,2 +43,2 @@ /** | ||
return W; | ||
} | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42981
14
956
364
Updatedgraphology-utils@^1.3.1
Updatedlodash@^4.17.11