示例#1
0
 public static Count <int> InDegSeq <T>(this PINQCollection <Pair <T> > edges, double epsilon) where T : IEquatable <T>
 {
     return(edges.Select(x => x.b)
            .Transpose()
            .Transpose()
            .Count(i => i, epsilon));
 }
示例#2
0
        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]);
        }
示例#3
0
        public static void Triangles(this PINQCollection <Pair <int> > graph, Pair <int>[] buckets, double epsilon)
        {
            var symmGraph       = graph.Select(edge => new Pair <int>(edge.b, edge.a));
            var undirectedGraph = graph.Concat(symmGraph);

            var abc = undirectedGraph.Join(undirectedGraph, x => x.b, y => y.a, (x, y) => new Triple(x.a, x.b, y.b));
            var bca = abc.Select(x => new Triple(x.b, x.c, x.a));
            var cab = abc.Select(x => new Triple(x.c, x.a, x.b));

            var result = abc.Intersect(bca).Intersect(cab);

            Console.WriteLine("triangles: {0}", result.Count(x => true, epsilon)[true]);
        }
示例#4
0
        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);
        }