#region License Information /* HeuristicLab * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using HEAL.Attic; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; using System; using System.Collections.Generic; namespace HeuristicLab.Algorithms.EvolvmentModelsOfModels { [Item("DistanceMap", "A map of models of models of models")] [StorableType("456692FB-2149-4359-8106-45D59D2D7FA0")] public class EMMDisatanceMap : EMMMapBase { [Storable] public List> Probabilities { get; set; } #region conctructors [StorableConstructor] protected EMMDisatanceMap(StorableConstructorFlag _) : base(_) { } public override IDeepCloneable Clone(Cloner cloner) { return new EMMDisatanceMap(this, cloner); } public EMMDisatanceMap() : base() { ModelSet = new List(); } public EMMDisatanceMap(EMMDisatanceMap original, Cloner cloner) : base(original, cloner) { } #endregion #region MapCreation override public void CreateMap(IRandom random, int k) { Probabilities = new List>(); MapSizeCheck(ModelSet.Count); ApplyDistanceMapCreationAlgorithm(random, CalculateDistances(), Map, Probabilities); } public static void ApplyDistanceMapCreationAlgorithm(IRandom random, double[,] distances, List> map, List> probabilities) { int mapSize = distances.GetLength(0); for (int t = 0; t < mapSize; t++) { probabilities.Add(new List()); double tempSum = 0; for (int i = 0; i < mapSize; i++) { tempSum += Math.Log(distances[i, t]); } for (int i = 0; i < mapSize; i++) { if (distances[i, t].IsAlmost(0)) continue; map[t].Add(i); probabilities[t].Add(Math.Log(distances[i, t]) / tempSum); } } } #endregion #region MapApplayFunctions public override ISymbolicExpressionTree NewModelForMutation(IRandom random, out int treeNumber, int parentTreeNumber) { treeNumber = HelpFunctions.OneElementFromListProportionalSelection(random, Probabilities[parentTreeNumber]); return (ISymbolicExpressionTree)ModelSet[treeNumber].Clone(); } override public ISymbolicExpressionTree NewModelForInizializtionNotTree(IRandom random, out int treeNumber) { return NewModelForInizializtion(random, out treeNumber); } #endregion } }