public static PINQCollection <Pair <int> > JointDegrees(this PINQCollection <Pair <int> > graph) { var aDegrees = graph.DPCount(x => x.a, (k, i) => new Pair <int>(k, i - 1)); var bDegrees = graph.DPCount(x => x.b, (k, i) => new Pair <int>(k, i - 1)); var aDegEdge = graph.Join(aDegrees, edge => edge.a, pair => pair.a, (edge, pair) => new Pair <Pair <int>, int>(edge, pair.b)); var bDegEdge = graph.Join(bDegrees, edge => edge.b, pair => pair.a, (edge, pair) => new Pair <Pair <int>, int>(edge, pair.b)); return(aDegEdge.Join(bDegEdge, aTriple => aTriple.a, bTriple => bTriple.a, (aTriple, bTriple) => new Pair <int>(aTriple.b, bTriple.b))); }
public static void Clustering(this PINQCollection <Pair <int> > graph, double epsilon) { //order the graph before, it improves both number of triangles and clustering coefficient graph = graph.Select(edge => new Pair <int>(Math.Min(edge.a, edge.b), Math.Max(edge.a, edge.b))); var length2Path = graph.Join(graph, x => x.b, y => y.a, x => x.a, y => y.b, (k, x, y) => new Triple(x, k, y)).Where(node => node.a != node.c); var triangles = graph.Intersect(length2Path.Select(x => new Pair <int>(x.a, x.c))); Console.WriteLine("the number of triangles is: {0}", triangles.Count(x => true, epsilon)[true]); }
public static PINQCollection <Triple> jddTriangles(this PINQCollection <Pair <int> > graph, Pair <int>[] buckets, double epsilon) { bool symmetry = false; if (symmetry) { var symmGraph = graph.Select(edge => new Pair <int>(edge.b, edge.a)); var undirectedGraph = graph.Concat(symmGraph); graph = undirectedGraph; //I need to double the buckets (maybe is not correct to double) for (int i = 0; i < buckets.Length; i++) { buckets[i].a = buckets[i].a * 2; buckets[i].b = buckets[i].b * 2; } } // does a DPCount, but then immediately replaces the degree with the bucket. //var aBuckets = graph.DPCount(x => x.a, (k, i) => new Pair<int>(k, buckets.Where(bucket => i < bucket.a).First().a)); //var bBuckets = graph.DPCount(x => x.b, (k, i) => new Pair<int>(k, buckets.Where(bucket => i < bucket.b).First().b)); //var aDegEdge = graph.Join(aBuckets, edge => edge.a, pair => pair.a, (edge, pair) => new Pair<Pair<int>, int>(edge, pair.b)); //var bDegEdge = graph.Join(bBuckets, edge => edge.b, pair => pair.a, (edge, pair) => new Pair<Pair<int>, int>(edge, pair.b)); var aDegrees = graph.DPCount(x => x.a, (k, i) => new Pair <int>(k, i)); var bDegrees = graph.DPCount(x => x.b, (k, i) => new Pair <int>(k, i)); var aDegEdge = graph.Join(aDegrees, edge => edge.a, pair => pair.a, (edge, pair) => new Pair <Pair <int>, int>(edge, pair.b)); var bDegEdge = graph.Join(bDegrees, edge => edge.b, pair => pair.a, (edge, pair) => new Pair <Pair <int>, int>(edge, pair.b)); var edgeDegree = aDegEdge.Join(bDegEdge, aTriple => aTriple.a, bTriple => bTriple.a, (aTriple, bTriple) => new Triple <Pair <int>, int, int>(aTriple.a, aTriple.b, bTriple.b)); //create a a path of length 3 with the degrees of each node involved var abc = edgeDegree.Join(edgeDegree, x => x.a.b, y => y.a.a, (x, y) => new Triple(x.b, x.c, y.c)); return(abc); }
public static Count <Triple> Triangles(this PINQCollection <Pair <int> > graph, double epsilon) { var degrees = graph.DPCount(edge => edge.a, (k, i) => new Pair <int>(k, i - 1)); var len2paths = graph.Join(graph, edge1 => edge1.b, edge2 => edge2.a, (edge1, edge2) => new Triple(edge1.a, edge1.b, edge2.b)); var abcDb = len2paths.Join(degrees, path => path.b, degr => degr.a, (path, degr) => new Pair <Triple, int>(path, degr.b)); var bcaDc = abcDb.Select(pair => new Pair <Triple, int>(new Triple(pair.a.b, pair.a.c, pair.a.a), pair.b)); var cabDa = abcDb.Select(pair => new Pair <Triple, int>(new Triple(pair.a.c, pair.a.a, pair.a.b), pair.b)); var results = abcDb.Join(bcaDc, abc => abc.a, bca => bca.a, (abc, bca) => new Pair <Triple, Pair <int> >(abc.a, new Pair <int>(abc.b, bca.b))) .Join(cabDa, abc => abc.a, cab => cab.a, (abc, cab) => new Triple(cab.b, abc.b.a, abc.b.b)); return(results.Count(x => x, epsilon)); }
public static void TrianglesByDegree(this PINQCollection <Pair <int> > graph, double epsilon) { Console.WriteLine("in TrianglesByDegree..."); // form (b, db) pairs each with weight 1/2 var bDegs = graph.GroupBy(e => e.a, e => e.b, (k, i) => new VertexData(k, i)); // form length 2 paths (a,b,c) weight 1/2db. var path = graph.Join(graph, x => x.b, y => y.a, x => x.a, y => y.b, (key, x, y) => new Triple(x, key, y));//.Where(x => x.a != x.c); // form ((a,b,c), db) tuples, with weights 1/2db(1 + db). var abc = path.Join(bDegs, x => x.b, y => y.name, x => x, y => y.edges.Length, (key, x, y) => new Pair <Triple, int>(x, y)); // rotate to get ((c,a,b),db) or equivalently ((a,b,c),dc) var cab = abc.Select(x => new Pair <Triple, int>(new Triple(x.a.c, x.a.a, x.a.b), x.b)); // rotate to get ((b,c,a),db) or equivalently ((a,b,c),da) var bca = abc.Select(x => new Pair <Triple, int>(new Triple(x.a.b, x.a.c, x.a.a), x.b)); // form length ((a,b,c),da,db) tuples with weight 1/2(da(1+da) + db(1 +db)) var tuple = abc.Join(bca, x => x.a, y => y.a, x => x.b, y => y.b, (key, x, y) => new Pair <Triple, Pair>(key, new Pair(y, x))); // form length ((a,b,c),da,db,db) tuples with weight 1/2(da(1+da) + db(1+db) + dc(1+dc)) var tuple2 = tuple.Join(cab, x => x.a, y => y.a, x => x.b, y => y.b, (key, x, y) => new Pair <Triple, Triple>(key, new Triple(x.a, x.b, y))); // transform to (da,db,dc) tuples where da < db < dc var tris = tuple2.Select(x => x.b); tris = tris.Select(x => new Triple(Math.Min(Math.Min(x.a, x.b), x.c), median(x.a, x.b, x.c), Math.Max(x.a, Math.Max(x.b, x.c)))); // return the noisy histogram var result = tris.Count(x => x, epsilon); }