예제 #1
0
        public void Trivial()
        {
            var objs = new object[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G' };
            var c = objs.Length;
            var w = new int[c][];
            var gr1 = new[] { 'A', 'B', 'C' };
            var gr2 = new[] { 'D', 'E', 'F', 'G' };
            for (int i = 0; i < c; i++)
            {
                w[i] = new int[c];
                for (int j = 0; j < c; j++)
                {
                    if (i == j)
                        w[i][j] = 200;
                    else if (gr1.Contains((char)objs[i]) && gr1.Contains((char)objs[j]))
                        w[i][j] = 100;
                    else if (gr2.Contains((char)objs[i]) && gr2.Contains((char)objs[j]))
                        w[i][j] = 100;
                    else
                        w[i][j] = 0;
                }

            }
            var m = new Modularity(objs, w);
            Console.WriteLine("Start:" + m.CalcTotalModularity());
            int iter = 1;
            while (m.Iterate(true))
                Console.WriteLine("Iter[" + iter++ + "]:" + m.CalcTotalModularity() + ", nodes=" + m.NodesCount);
            Console.WriteLine("Result:" + m.CalcTotalModularity());
            Console.WriteLine("fin");
            Debug.Assert(m.NodesCount == 2);
        }
예제 #2
0
 public List<Cluster> Work3(int cut = 3, int seed = 1, bool setCoreWeights = false)
 {
     InitEdges();
     Console.WriteLine("Запущена кластеризация второго типа для " + _nodes.Length + " узлов");
     var sw = Stopwatch.StartNew();
     var weights = new int[_nodes.Length][];
     for (int i = 0; i < weights.Length; i++)
     {
         weights[i] = new int[_nodes.Length];
         for (int j = 0; j < _nodes.Length; j++)
             weights[i][j] = i != j ? GetEdge(i, j).Weight - cut : (setCoreWeights ? _nodes[i].Count : 0);//_nodes[i].Chain.Length;
     }
     var m = new Modularity(_nodes, weights, seed);
     Console.WriteLine("Start with:" + m.CalcTotalModularity());
     var iter = 1;
     while (m.Iterate())
         Console.WriteLine("Iter[" + iter++ + "]:" + m.CalcTotalModularity());
     Console.WriteLine("Result:" + m.CalcTotalModularity());
     sw.Stop();
     Console.WriteLine("Кластеризация завершена за " + sw.Elapsed);
     var clusterIds = m.ClasterIds;
     var ret = new List<Cluster>();
     for (int i = 0; i < m.NodesCount; i++)
     {
         // переобозначим элементы каждого кластера
         int id = 0;
         var dic = new Dictionary<int, int>();
         for (int j = 0; j < clusterIds.Length; j++)
         {
             if(clusterIds[j] != i)
                 continue;
             dic.Add(id++,j);
         }
         var nodes = new ElementGroup[dic.Count];
         var edges = new AlignmentResult[dic.Count][];
         for (int j = 0; j < dic.Count; j++)
         {
             nodes[j] = _nodes[dic[j]];
             edges[j] = new AlignmentResult[j];
             for (int k = 0; k < j; k++)
             {
                 edges[j][k] = _edges[dic[j]][dic[k]];
                 if (k == 0)
                 {
                     var tt = Alignment.Align(nodes[j].NucleoChain, nodes[k].NucleoChain, 0, 0);
                     Debug.Assert(tt.Mask == edges[j][k].Mask);
                 }
             }
         }
         ret.Add(new Cluster(ret.Count, nodes, edges));
     }
     return ret;
 }