Beispiel #1
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;
 }
Beispiel #2
0
 public Cluster(int clusterId, ElementGroup[] nodes, AlignmentResult[][] edges)
 {
     ClusterId = clusterId;
     Nodes = nodes;
     Edges = edges;
 }
Beispiel #3
0
 public void InitEdges()
 {
     if (_edges != null)
         return;
     Console.WriteLine("Запущен рассчёт рёбер для " + _nodes.Length + " узлов");
     var sw = Stopwatch.StartNew();
     var edges = new AlignmentResult[_nodes.Length][];
     Parallel.For(0, edges.Length, new ParallelOptions {MaxDegreeOfParallelism = 4},
         i =>
         {
             edges[i] = new AlignmentResult[i];
             for (var j = 0; j < i; j++)
                 edges[i][j] = Alignment.Align(_nodes[i].NucleoChain, _nodes[j].NucleoChain, i, j);
         });
     //for (var i = 0; i < edges.Length; i++)
     //{
     //    edges[i] = new AlignmentResult[i];
     //    for (var j = 0; j < i; j++)
     //        edges[i][j] = Alignment.Align(_nodes[i].NucleoChain, _nodes[j].NucleoChain, i, j);
     //}
     _edges = edges;
     sw.Stop();
     Console.WriteLine("Рёбра рассчитаны за " + sw.Elapsed);
 }