-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVariety.cs
53 lines (48 loc) · 1.67 KB
/
Variety.cs
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
using MNCD.Core;
using System;
namespace MNCD.Evaluation.MultiLayer
{
/// <summary>
/// Implements variety.
/// Based on:
/// Finding Redundant and Complementary Communities in Multidimensional Networks
/// http://www.michelecoscia.com/wp-content/uploads/2012/08/cosciacikm11.pdf
/// Michele Berlingerio, Michele Coscia, Fosca Giannotti.
/// </summary>
public static class Variety
{
/// <summary>
/// Variety - number of dimensions expressed with the community
/// over the total number of dimensions within the network.
/// </summary>
/// <param name="community">Community for which variety is computed.</param>
/// <param name="network">Network in which community resides.</param>
/// <returns>Variety for community in network.</returns>
public static double Compute(Community community, Network network)
{
if (network.LayerCount <= 1)
{
throw new ArgumentException("Variety can be computed only for multi-layered networkx.");
}
if (community.Size == 0)
{
return 0;
}
var d = network.Layers.Count;
var dc = 0;
var actors = community.Actors;
foreach (var layer in network.Layers)
{
foreach (var edge in layer.Edges)
{
if (actors.Contains(edge.From) && actors.Contains(edge.To))
{
dc++;
break;
}
}
}
return (dc - 1) / (double)(d - 1);
}
}
}