How to find Global Clustering Coefficient of graph? - graph

I start learning network analysis & its metrics calculation from last week. Don't have enough knowledge. Can anyone check this ?
The formula of finding the global clustering co-efficient is,
C = (3 * Number of Triangles) / (Number of connected triples of vertices)
I calculate the global clustering co-efficient as,
Number of Triangles = 2
(as there are 2 directly connected triangles in the graph i-e Node4->Node5->Node6 and Node1->Node3->Node4)
Number of connected triples of vertices = 4
(as Node1, Node2, Node3 & Node6 have three vertices connected)
C = (3 * 2) / 4 = 1.5
I don't know I do it correctly or not. Can anyone check this ? or correct me If I am wrong

The denominator must count all triples with 2 or 3 edges.
So, the the given graph we have the following triples:
5-4-6
6-5-4, 6-4-2, 6-5-2
4-6-1, 4-5-1, 4-6-3, 4-5-3, 4-1-3, 4-6-5
1-4-3, 1-3-2, 1-4-2
3-4-1, 3-1-7, 3-4-7
7-3-2
2-7-1, 2-1-6, 2-7-6
This gives a total of 20 triples, so the gcc is 2*3/20 = 0.3.
This algorithm is implemented in python's networkx package. The code for this example is:
import networkx as nx
g = nx.Graph()
g.add_edges_from([(5,6), (5,4), (4,6), (4,1), (4,3), (3,1), (3,7), (7,2), (1,2), (6,2)])
print(nx.transitivity(g))

Related

determine suitable values for the parameters of the distance function for this graph

Hi I've been learning data mining and came across this question. I couldn't seem to figure it out myself.
So we have an undirected graph(without attributes) G = (V,E) and want to detect nodes that are outliers within that graph.
an outlier O in dataset D is defined as:
|{o'|dist(o,o'}≤ r}|/|D|≤ π, where D = V.
How can we define the distance function dist between
a pair of nodes? How can we determine suitable values for the parameters r and π?
The distance between two nodes in a graph could be defined as
number_of_intermeidate_nodes + 1
For Determining r and π ,
It can be done empirically that best suits your data.Try for different values of r and π

Periodic and Aperiodic directed graphs

I am a bit confused on how to distinguish a directed graph to be aperiodic or periodic. Wikipedia says this about aperiodic graphs:
'In the mathematical area of graph theory, a directed graph is said to be aperiodic if there is no integer k > 1 that divides the length of every cycle of the graph.'
For example is the graph below aperiodic or periodic. I believe the graph is not periodic but by wikipedia's definition it is periodic since integer k = 2 divides all cycles in the graph (AC and ACDB)
It would be great if someone could provide a method to distinguish if a graph is aperiodic or periodic. Maybe provide some examples of periodic and aperiodic graphs to help explain.
Thank you.
Here's a short python implementation based on Networkx, for finding wether a graph is periodic:
import networkx as nx
from math import gcd
from functools import reduce
G = nx.DiGraph()
G.add_edges_from([('A', 'C'), ('C', 'D'), ('D', 'B'), ('B', 'A'), ('C', 'A')])
cycles = list(nx.algorithms.cycles.simple_cycles(G))
cycles_sizes = [len(c) for c in cycles]
cycles_gcd = reduce(gcd, cycles_sizes)
is_periodic = cycles_gcd > 1
print("is_periodic: {}".format(is_periodic))
The code does the following:
Build the graph from your example (by specifying the edges).
List all cycles (AC and ACDB).
List all cycles sizes [2, 4].
Find greatest common denominator (GCD).
If GCD is 1 it means the graph is aperiodic, otherwise it's periodic by definition.
The graph you have given above in not aperiodic as it has the period of 2. (i.e. every node can return to itself in multiples of 2 steps)
You can play with different examples to get better intuition, and also visualize your graph by adding:
import matplotlib.pyplot as plt
nx.draw_networkx(G, with_labels=True)
plt.show()

Graph Theory (degree of the vertices of a graph when it can be partitioned into two trees)

Show that if the edge set of a graph G(V,E) with n nodes
can be partitioned into 2 trees,
then there is at least one vertex of degree less than 4 in G.
...................................................................................
I have tried to prove this problem with the help of the method of contradiction.
Assume that all vertices of the graph G has degree >= 4.
Assume the graph G is partitioned into two trees T1 and T2.
With the help of the above assumptions the only observation I could make is that for every vertex v in G
degree of v must be greater than or equal to 2 in either T1 or T2.
I don't know how proceed with this. Please help.
If my approach for solving this problem is wrong then please provide a different solution.
You started with a good approach. Lets assume all vertices in G has degree of 4 (or above) and sssume the graph G is partitioned into two trees T1 and T2.
We know that number of edge in tree is n-1 (when n is number of vertices). Therefor in each of T1 and T2 we have n-1 edges (consider n to be |V|) -> combine we have 2n-2 edges in G -> |E| = 2n-2
From the other hand we know that each v in G -> d(v) > 4 . And we know that sum of degree in graph equal to 2|E|. therefor, 2*|E| >= 4*n (I took the minimum degree for each vertex and each edge contribute 2 to the sum of the degree). So we got |E| >= 2*n.
Contradiction -> There is have to be one vertex with degree less then 4

Graph Theory: number of connected triples

In order to find the Global Clustering Coefficient I need to find the number of connected triples. About this graph:
these are the triples that I found:
7-6-5
5-3-7
5-3-1
4-3-7
4-3-1
4-5-6
3-7-6
3-5-6
2-3-4
2-1-7
2-3-5
1-7-6
total: 12 triples.
Moreover, there are 3 triangles, and 1 triangle is equal to 3 triples. So in total there are 12 + 3*3 = 21 triples. Is that correct? And is it possible to find a rule or a method to find all the connected triples in a graph without doing it manually?
summation of k*(k-1)/2, where k is the degree of all nodes.

Maximum number of edges in undirected graph with n vertices with k connected components?

I couldn't answer the question myself because i don't see any similar behavior for all the examples i tried.
The question again:
Maximum number of edges in undirected graph with n vertices with k connected components?
Thanks.
This answer depends on whether your graphs are allowed to have self-loops or not. For simplicity, I'm going to assume they aren't.
If you have a connected component with x nodes in it, the maximum number of edges you can have in that connected component is x(x - 1) / 2. Therefore, if you have n total nodes and k different connected components, you can imagine distributing the nodes into the connected components in a way that maximizes the sum of x(x - 1) / 2 across the connected components.
Specifically, suppose your CC's have n1, ..., nk nodes each. You want to solve the following quadratic program:
Maximize: n1(n1 - 1) / 2 + ... + nk(nk - 1) / 2
Subject to: n1 + ... + nk = n
I'm going to claim that this is maximized when k - 1 of the connected components have 1 node and the last connected component has n - k + 1 nodes in it. Intuitively, this is true because any node you remove from the huge CC will cause a large drop in the number of possible edges that will not be offset by the meager increase in the number of possible edges in the other connected component the node was added to.
Under this setup, the maximum number of possible edges in the k - 1 singleton CC's will be 0 and the maximum number of possible edges in the other CC will be (n - k + 1)(n - k) / 2. Therefore, the total should be (n - k + 1)(n - k) / 2.
Hope this helps!
when graph do not contain self loops and is undirected then the maximum no. of edges are-
(n-k+1)(n-k)/2
It is because maximum number of edges with n vertices is n(n-1)/2. Now for example, if we are making an undirected graph with n=2 (4 vertices) and there are 2 connected components i.e, k=2, then first connected component contains either 3 vertices or 2 vertices, for simplicity we take 3 vertices (Because connected component containing 2 vertices each will not results in maximum number of edges). These 3 vertices must be connected so maximum number of edges between these 3 vertices are 3 i.e, (1->2->3->1) and the second connected component contains only 1 vertex which has no edge. So the maximum number of edges in this case are 3. This implies that replacing n with n-k+1 in the formula for maximum number of edges i.e, n(n-1)/2 will results in (n-k+1)(n-k)/2 which is maximum number of edges that a graph of n vertices with k connected component can have.see image for better understanding
hope it will be helpful!!

Resources