#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 HeuristicLab.Problems.DataAnalysis.Symbolic; using System.Collections.Generic; using System.Linq; namespace HeuristicLab.Algorithms.EvolvmentModelsOfModels { [Item("SucsessMap", "A map of models of models of models")] [StorableType("3880BA82-4CB0-4838-A17A-823E91BC046C")] public class EMMSucsessMap : EMMMapBase { [Storable] public List Probabilities { get; private set; } [Storable] public List> SucsessStatistics { get; private set; } #region conctructors [StorableConstructor] protected EMMSucsessMap(StorableConstructorFlag _) : base(_) { } public override IDeepCloneable Clone(Cloner cloner) { return new EMMSucsessMap(this, cloner); } public EMMSucsessMap() : base() { ModelSet = new List(); SucsessStatistics = new List>(); } public EMMSucsessMap(EMMSucsessMap original, Cloner cloner) : base(original, cloner) { SucsessStatistics = original.SucsessStatistics.Select(x => x.ToList()).ToList(); } #endregion #region MapCreation override public void CreateMap(IRandom random, int k) { Probabilities = new List(); Map.Clear(); Map.Add(new List()); MapSizeCheck(ModelSet.Count); ApplySucsessMapCreationAlgorithm(random, CalculateDistances(), Map, Probabilities, SucsessStatistics); } public static void ApplySucsessMapCreationAlgorithm(IRandom random, double[,] distances, List> map, List probabilities, List> sucsessStatistics) { int mapSize = distances.GetLength(0); for (int t = 0; t < mapSize; t++) { map[t].Add(t); probabilities.Add(1.0 / ((double)(mapSize))); // uniform distribution as start point } } public override void MapUpDate(Dictionary population) { SucsessStatisticCollection(population); HelpFunctions.ProbabilitiesUpDate(SucsessStatistics, Probabilities); } private void SucsessStatisticCollection(Dictionary population) { if (SucsessStatistics.Count != 0) SucsessStatistics.Clear(); for (int t = 0; t < Probabilities.Count; t++) { SucsessStatistics.Add(new List()); SucsessStatistics[t].Add(0); SucsessStatistics[t].Add(0); } foreach (var solution in population) { TreeCheck(solution.Key, solution.Value); } } private void TreeCheck(ISymbolicExpressionTree tree, double treeQuality) { foreach (var treeNode in tree.IterateNodesPrefix().OfType()) { SucsessStatistics[treeNode.TreeNumber][0] += 1; SucsessStatistics[treeNode.TreeNumber][1] += treeQuality; } } #endregion #region MapApplayFunctions public override ISymbolicExpressionTree NewModelForMutation(IRandom random, out int treeNumber, int parentTreeNumber) { treeNumber = Map[HelpFunctions.OneElementFromListProportionalSelection(random, Probabilities)][0]; return (ISymbolicExpressionTree)ModelSet[treeNumber].Clone(); } override public ISymbolicExpressionTree NewModelForInizializtionNotTree(IRandom random, out int treeNumber) { return NewModelForInizializtion(random, out treeNumber); } #endregion } }