Exemplo n.º 1
0
 public static LinearLinkage Apply(IRandom random, LinearLinkage p1, LinearLinkage p2) {
   var length = p1.Length;
   var child = new LinearLinkage(length);
   var endNodes = new HashSet<int>();
   for (var i = 0; i < length; i++) {
     if ((p1[i] == i && p2[i] == i)
       || ((p1[i] == i || p2[i] == i) && random.NextDouble() < 0.5)) {
       child[i] = i;
       endNodes.Add(i);
     }
   }
   for (var i = 0; i < length; i++) {
     if (endNodes.Contains(i)) continue;
     var p1End = endNodes.Contains(p1[i]);
     var p2End = endNodes.Contains(p2[i]);
     if ((p1End && p2End) || (!p1End && !p2End)) {
       child[i] = random.NextDouble() < 0.5 ? p1[i] : p2[i];
     } else if (p1End) {
       child[i] = p1[i];
     } else {
       child[i] = p2[i];
     }
   }
   child.LinearizeTreeStructures();
   return child;
 }
        public static void Apply(IRandom random, LinearLinkage lle, int index)
        {
            var groups = lle.Select((val, idx) => Tuple.Create(idx, val))
                         .Where(x => x.Item1 == x.Item2)
                         .Select(x => x.Item2).ToList();
            var z = groups.Count;

            if (random.NextDouble() < 0.5)
            {
                lle[index] = index; // divide the cluster into two
            }
            else
            {
                var c = random.Next(z);
                if (groups[c] > index)
                {
                    lle[index] = groups[c]; // combine the portion with another class
                }
                else
                {
                    // combine the other class here
                    lle[groups[c]] = lle[index];
                    lle[index]     = index;
                }
                lle.LinearizeTreeStructures();
            }
        }
Exemplo n.º 3
0
 public static LinearLinkage Apply(IRandom random, LinearLinkage p1, LinearLinkage p2) {
   var length = p1.Length;
   var child = new LinearLinkage(length);
   var bp = random.Next(length - 1);
   for (var i = 0; i <= bp; i++) child[i] = p1[i];
   for (var i = bp + 1; i < length; i++) child[i] = p2[i];
   child.LinearizeTreeStructures();
   return child;
 }
        public static LinearLinkage Apply(IRandom random, LinearLinkage p1, LinearLinkage p2)
        {
            var length = p1.Length;
            var child  = new LinearLinkage(length);
            var bp     = random.Next(length - 1);

            for (var i = 0; i <= bp; i++)
            {
                child[i] = p1[i];
            }
            for (var i = bp + 1; i < length; i++)
            {
                child[i] = p2[i];
            }
            child.LinearizeTreeStructures();
            return(child);
        }
Exemplo n.º 5
0
    public static void Apply(IRandom random, LinearLinkage lle, int index) {
      var groups = lle.Select((val, idx) => Tuple.Create(idx, val))
                      .Where(x => x.Item1 == x.Item2)
                      .Select(x => x.Item2).ToList();
      var z = groups.Count;

      if (random.NextDouble() < 0.5)
        lle[index] = index; // divide the cluster into two
      else {
        var c = random.Next(z);
        if (groups[c] > index)
          lle[index] = groups[c]; // combine the portion with another class
        else {
          // combine the other class here
          lle[groups[c]] = lle[index];
          lle[index] = index;
        }
        lle.LinearizeTreeStructures();
      }
    }
Exemplo n.º 6
0
        public static LinearLinkage Apply(IRandom random, LinearLinkage p1, LinearLinkage p2)
        {
            var length   = p1.Length;
            var child    = new LinearLinkage(length);
            var endNodes = new HashSet <int>();

            for (var i = 0; i < length; i++)
            {
                if ((p1[i] == i && p2[i] == i) ||
                    ((p1[i] == i || p2[i] == i) && random.NextDouble() < 0.5))
                {
                    child[i] = i;
                    endNodes.Add(i);
                }
            }
            for (var i = 0; i < length; i++)
            {
                if (endNodes.Contains(i))
                {
                    continue;
                }
                var p1End = endNodes.Contains(p1[i]);
                var p2End = endNodes.Contains(p2[i]);
                if ((p1End && p2End) || (!p1End && !p2End))
                {
                    child[i] = random.NextDouble() < 0.5 ? p1[i] : p2[i];
                }
                else if (p1End)
                {
                    child[i] = p1[i];
                }
                else
                {
                    child[i] = p2[i];
                }
            }
            child.LinearizeTreeStructures();
            return(child);
        }