Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/11/17 11:45:16 (7 years ago)
Author:
mkommend
Message:

#2815: Merged r15301 into stable.

Location:
stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/LinkageTree.cs

    r14186 r15324  
    2727using HeuristicLab.Core;
    2828using HeuristicLab.Encodings.BinaryVectorEncoding;
     29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2930using HeuristicLab.Random;
    3031
     
    3334  // B. W. Goldman and W. F. Punch, "Parameter-less Population Pyramid," GECCO, pp. 785–792, 2014
    3435  // and the original source code in C++11 available from: https://github.com/brianwgoldman/Parameter-less_Population_Pyramid
    35   public class LinkageTree {
     36  [StorableClass]
     37  public class LinkageTree : DeepCloneable {
     38    [Storable]
    3639    private readonly int[][][] occurances;
     40    [Storable]
    3741    private readonly List<int>[] clusters;
     42    [Storable]
    3843    private List<int> clusterOrdering;
     44    [Storable]
    3945    private readonly int length;
     46    [Storable]
    4047    private readonly IRandom rand;
     48    [Storable]
    4149    private bool rebuildRequired = false;
     50
     51
     52    [StorableConstructor]
     53    protected LinkageTree(bool deserializing) : base() { }
     54
     55
     56    protected LinkageTree(LinkageTree original, Cloner cloner) : base(original, cloner) {
     57      occurances = new int[original.occurances.Length][][];
     58      //mkommend: first entry is not used, cf. ctor line 83
     59      for (int i = 1; i < original.occurances.Length; i++) {
     60        occurances[i] = new int[original.occurances[i].Length][];
     61        for (int j = 0; j < original.occurances[i].Length; j++)
     62          occurances[i][j] = original.occurances[i][j].ToArray();
     63      }
     64
     65      clusters = original.clusters.Select(c => c.ToList()).ToArray();
     66      clusterOrdering = new List<int>(original.clusterOrdering);
     67      length = original.length;
     68      rand = cloner.Clone(original.rand);
     69      rebuildRequired = original.rebuildRequired;
     70    }
     71
     72
     73    public override IDeepCloneable Clone(Cloner cloner) {
     74      return new LinkageTree(this, cloner);
     75    }
    4276
    4377    public LinkageTree(int length, IRandom rand) {
     
    93127    // Uses the frequency table to calcuate the entropy distance between two indices.
    94128    // In the GECCO paper, calculates Equation 1
    95     private int[] bits = new int[4];
    96129    private double EntropyDistance(int i, int j) {
     130      int[] bits = new int[4];
    97131      // This ensures you are using the lower triangular part of "occurances"
    98132      if (i < j) {
     
    125159    // by I. Gronau and S. Moran
    126160    // In the GECCO paper, Figure 2 is a simplified version of this algorithm.
    127     private double[][] distances;
    128161    private void Rebuild() {
     162      double[][] distances = null;
    129163      if (distances == null) {
    130164        distances = new double[clusters.Length * 2 - 1][];
Note: See TracChangeset for help on using the changeset viewer.