Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/11/19 16:30:22 (5 years ago)
Author:
msemenki
Message:

#2988:

  1. The file system was changed, folders was added and part of files was transferred in these folders.
  2. HelpFunctions class was divided on 2 parts: HelpFuctions for common purposes static functions and SelfConfiguration that include functions for self-configuration mechanism realization (is used in EMMSucsessMap).
  3. Parts of self-configuration mechanism was transferred from EMMSucsessMap.cs to SelfConfiguration.cs. Now EMMSucsessMap used SelfConfiguration like one of data member. Other parts of project was adopted for this changing.
  4. FileComunication class was added. It include the majority of functions for printing to files or reading from files. Here were realized possibility to write and read to hl files.
  5. ModelTreeNode.cs has additional possibility - to write sub-model in string (then it is possible to write it in file).
  6. InfixExpressionFormatter.cs can work with TreeModelNode.
  7. Possibility for different map types to be readable from files was extended and cheeked.
  8. Such parameters like - ClusterNumbers, ClusterNumbersShow, NegbourNumber, NegbourType (that is used only in several maps) was transferred from EMMAlgorithm to Map Parameters. Now EMMBaseMap class inherited from ParameterizedNamedItem (not from Item). And EMMIslandMap and EMMNetworkMap contains their parameters (constructors was modified). CreationMap calls functions were simplified.
  9. Functions for different distance metric calculation was added. Now, it is possible to calculate different types of distances between models (with different random values of constants).
  10. DistanceParametr was added. Now maps can be created according different types of distance calculations.
  11. The class EMMClustering has new name KMeansClusterizationAlgorithm. On KMeansClusterizationAlgorithm bug with bloating of centroids list was fixed. Algorithm was adopted for working with different type of distance metric and get maximum number of iterations.
  12. Possibilities for constants optimization in sub-models an whole tree was added. EMMAlgorithm get new function for evaluation of individuals (and some additional technical stuff for that). Function for trees with model in usual tree transformation and back was added.
  13. EMMAlgorithm was divided on 2 parts:
  • EMMAlgorithm, that contain evolutionary algorithm working with sub-models, and use ready to use maps;
  • ModelSetPreparation, that contain distance calculation, model set simplification and map creation.
Location:
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/Maps
Files:
1 added
1 moved

Legend:

Unmodified
Added
Removed
  • branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/Maps/EMMBaseMap.cs

    r17133 r17134  
    2525using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2626using HeuristicLab.Problems.DataAnalysis.Symbolic;
    27 using HeuristicLab.Random;
    2827using System.Collections.Generic;
    2928using System.IO;
     
    3231namespace HeuristicLab.Algorithms.EvolvmentModelsOfModels {
    3332  [StorableType("83CF9650-98FF-454B-9072-82EA4D39C752")]
    34   public abstract class EMMMapBase<T> : Item where T : class {
     33  public abstract class EMMMapBase<T> : ParameterizedNamedItem where T : class {
    3534    #region data members
    3635    [Storable]
    37     public List<T> ModelSet { get; set; }
     36    public List<T> ModelSet { get; protected set; }
    3837    [Storable]
    3938    public List<List<int>> Map { get; set; }
     39    public string DistanceParametr { get; set; }
    4040    #endregion
    4141    #region constructors
     
    4444    public EMMMapBase() {
    4545      Map = new List<List<int>>();
     46      DistanceParametr = "Symbolic";
    4647    }
    47     public EMMMapBase(EMMMapBase<T> original, Cloner cloner) {
     48    public EMMMapBase(EMMMapBase<T> original, Cloner cloner) : base(original, cloner) {
    4849      if (original.ModelSet != null) {
    4950        if (original.ModelSet is List<ISymbolicExpressionTree> originalSet && ModelSet is List<ISymbolicExpressionTree> set)
     
    5455        Map = original.Map.Select(x => x.ToList()).ToList();
    5556      }
     57      DistanceParametr = original.DistanceParametr;
    5658    }
    5759    #endregion
    5860    #region map creation functions
    59     protected double[,] CalculateDistances() {
    60       double[,] distances;
    61       if (ModelSet is List<ISymbolicExpressionTree> set) {
    62         distances = SymbolicExpressionTreeHash.ComputeSimilarityMatrix(set, simplify: false, strict: true);
    63       } else { /// for future work
    64         distances = new double[ModelSet.Count, ModelSet.Count];
    65         for (int i = 0; i < ModelSet.Count - 1; i++) {
    66           for (int j = 0; j <= i; j++) {
    67             distances[i, j] = 0;
    68           }
    69         }
    70       }
    71       for (int i = 0; i < ModelSet.Count - 1; i++) {
    72         for (int j = i + 1; j < ModelSet.Count; j++) {
    73           distances[j, i] = distances[i, j] = 1 - distances[i, j];
    74         }
    75       }
    76       return distances;
    77     }
    78     public abstract void CreateMap(IRandom random, int k);
     61
     62    public abstract void CreateMap(IRandom random);
    7963    public void MapCreationPrepare(IEnumerable<T> trees) {
    8064      ModelSet = trees.ToList();
     65    }
     66    public virtual void CreateMap(IRandom random, ISymbolicDataAnalysisSingleObjectiveProblem problem) {
     67      if (Map != null) {
     68        Map.Clear();
     69      }
     70      CreateMap(random);
     71    }
     72    public virtual void CreateMap(IRandom random, double[,] totalDistance) {
     73      if (Map != null) {
     74        Map.Clear();
     75      }
     76      CreateMap(random);
    8177    }
    8278
     
    9591    #endregion
    9692    #region map and files
    97     public void MapRead(IRandom random, IEnumerable<T> trees, string fileName = "Map.txt") {
     93    public virtual void MapRead(IEnumerable<T> trees) {
    9894      ModelSet = trees.ToList();
    99       MapFromFileRead(fileName);
    100       if (this is EMMIslandMap island) { island.ClusterNumbersCalculate(); }
    101       if (this is EMMNetworkMap one) { one.NeghboorNumber = Map[0].Count; }
    10295    }
    10396    public void WriteMapToTxtFile(IRandom random) {
    104       string s = random.ToString();
    105       string fileName = "Map";
     97      string s = random.NextDouble().ToString();
     98      string fileName = "MapToAnalize";
    10699      fileName += s;
     100      fileName += DistanceParametr;
    107101      fileName += ".txt";
    108102      File.WriteAllLines(fileName, MapToString());
    109103      string fileName2 = "MapToSee";
    110104      fileName2 += s;
     105      fileName2 += DistanceParametr;
    111106      fileName2 += ".txt";
    112107      File.WriteAllLines(fileName2, MapToSee());
     108      string fileName3 = "Map";
     109      fileName3 += DistanceParametr;
     110      fileName3 += ".txt";
     111      File.WriteAllLines(fileName3, MapToStoreInFile());
    113112    }
    114     public string[] MapToString() { // Function that preapre Map to printing in .txt File: create a set of strings for future reading by computer
     113    public string[] MapToString() { // Function that prepare Map to printing in .txt File: create a set of strings for future analyzing
     114      string[] s;
     115      s = new string[Map.Count];
     116      for (int i = 0; i < Map.Count; i++) {
     117        s[i] = i.ToString() + ": ";
     118        for (int j = 0; j < Map[i].Count; j++) {
     119          s[i] += Map[i][j].ToString();
     120          s[i] += " ";
     121        }
     122        if (this is EMMIslandMap island) {
     123          s[i] += "  Average distance:" + island.AverageDistance[i].ToString();
     124        }
     125      }
     126      return s;
     127    }
     128    public virtual string[] MapToStoreInFile() { // Function that prepare Map to printing in .txt File: create a set of strings for future reading by computer
    115129      string[] s;
    116130      s = new string[Map.Count];
     
    119133        for (int j = 0; j < Map[i].Count; j++) {
    120134          s[i] += Map[i][j].ToString();
    121           s[i] += " ";
     135          if (j != (Map[i].Count - 1)) { s[i] += " "; }
    122136        }
    123137      }
     
    140154      }
    141155      return s;
    142     }
    143     public void MapFromFileRead(string fileName) {
    144       string input = File.ReadAllText(fileName);
    145       int i = 0;
    146       foreach (var row in input.Split('\n')) {
    147         Map.Add(new List<int>());
    148         foreach (var col in row.Trim().Split(' ')) {
    149           Map[i].Add(int.Parse(col.Trim()));
    150         }
    151         i++;
    152       }
    153156    }
    154157    #endregion
     
    173176      treeNode.Tree = new SymbolicExpressionTree(NewModelForMutation(random, out treeNumber, treeNumber2).Root);
    174177      treeNode.TreeNumber = treeNumber;
    175       SetLocalParametersForTree(random, 0.5, treeNode.Tree);
    176     }
    177     public void SetLocalParametersForTree(IRandom random, double shakingFactor, ISymbolicExpressionTree tree) {
    178       foreach (var node in tree.IterateNodesPrefix().Where(x => x.HasLocalParameters)) {
    179         if (node is VariableTreeNode variableTreeNode) {
    180           var symbol = variableTreeNode.Symbol;
    181           variableTreeNode.Weight = NormalDistributedRandom.NextDouble(random, symbol.WeightManipulatorMu, symbol.WeightManipulatorSigma);
    182         } else {
    183           node.ResetLocalParameters(random);
    184         }
    185       }
     178      HelpFunctions.SetLocalParametersForTree(random, 0.5, treeNode.Tree);
    186179    }
    187180    public virtual void MapUpDate(Dictionary<ISymbolicExpressionTree, double> population) { }
Note: See TracChangeset for help on using the changeset viewer.