- Timestamp:
- 06/03/19 14:15:11 (6 years ago)
- Location:
- branches/2988_ModelsOfModels2
- Files:
-
- 3 added
- 2 deleted
- 18 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM ¶
- Property svn:ignore
-
TabularUnified
old new 12 12 *.nuget.props 13 13 *.nuget.targets 14 Plugin.cs
-
- Property svn:ignore
-
TabularUnified branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMAlgorithm.cs ¶
r16899 r17002 29 29 using HeuristicLab.Selection; 30 30 using System.Collections.Generic; 31 using System.IO;32 31 using System.Linq; 33 32 using CancellationToken = System.Threading.CancellationToken; … … 35 34 36 35 namespace HeuristicLab.Algorithms.EvolvmentModelsOfModels { 37 [Item("Evolvment ModelsOfModels Algorithm", "EMM implementation")]36 [Item("Evolvment Models Of Models Algorithm (EMM) ", "EMM implementation")] 38 37 [Creatable(CreatableAttribute.Categories.PopulationBasedAlgorithms, Priority = 125)] 39 38 [StorableType("AD23B21F-089A-4C6C-AD2E-1B01E7939CF5")] 40 39 public class EMMAlgorithm : EvolvmentModelsOfModelsAlgorithmBase { 41 40 public EMMAlgorithm() : base() { } 42 protected EMMAlgorithm(EMMAlgorithm original, Cloner cloner) : base(original, cloner) { 43 //if (original.Map != null) { 44 // Map = cloner.Clone(original.Map); 45 //} 46 } 41 protected EMMAlgorithm(EMMAlgorithm original, Cloner cloner) : base(original, cloner) { } 47 42 public override IDeepCloneable Clone(Cloner cloner) { 48 43 return new EMMAlgorithm(this, cloner); … … 53 48 54 49 protected override void Run(CancellationToken cancellationToken) { 55 InfixExpressionParser parser = new InfixExpressionParser();56 var trees = File.ReadAllLines(InputFileParameter.Value.Value).Select(parser.Parse);57 50 if (AlgorithmImplemetationType.Value == "Read") { 58 51 Map.MapRead(RandomParameter.Value, trees, "Map.txt"); 59 52 } else { 60 Map.MapCreationPrepare( RandomParameter.Value, trees, ClusterNumbersParameter.Value.Value);53 Map.MapCreationPrepare(trees); 61 54 Map.CreateMap(RandomParameter.Value, ClusterNumbersParameter.Value.Value); 62 // Map.WriteMapToTxtFile(RandomParameter.Value); 63 } 64 65 ClusterNumbersShowParameter.Value.Value = Map.K; 55 // Map.WriteMapToTxtFile(RandomParameter.Value); хайв этого не любит.. ворчит 56 } 57 ClusterNumbersShowParameter.Value.Value = Map.Map.Count; 66 58 67 59 if (AlgorithmImplemetationType.Value == "OnlyMap") { … … 74 66 if (!globalScope.Variables.ContainsKey("TreeModelMap")) 75 67 globalScope.Variables.Add(new Variable("TreeModelMap", Map)); 68 if (!globalScope.Variables.ContainsKey("Map")) 69 globalScope.Variables.Add(new Variable("Map", Map)); 76 70 EMMAlgorithmRun(cancellationToken); 77 71 } … … 84 78 bestSelector.QualityParameter.ActualName = "Quality"; 85 79 86 var populationSize = PopulationSize.Value;87 80 var maximumEvaluatedSolutions = MaximumEvaluatedSolutions.Value; 88 81 var crossover = Crossover; 89 82 var selector = Selector; 90 var groupSize = GroupSize.Value;91 83 var crossoverProbability = CrossoverProbability.Value; 92 84 var mutator = Mutator; … … 143 135 var op3 = executionContext.CreateChildOperation(evaluator, childScope); 144 136 ExecuteOperation(executionContext, innerToken, op3); 145 var qualities = (DoubleValue)childScope.Variables["Quality"].Value; 146 var childSolution = new EMMSolution(childScope); 147 // set child qualities 148 childSolution.Qualities = qualities; 137 //if (Problem.ProblemData is IRegressionProblemData problemData) { 138 // SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(Problem.SymbolicExpressionTreeInterpreter, (ISymbolicExpressionTree)childScope.Variables["SymbolicExpressionTree"].Value, problemData, problemData.TestIndices, true, 100 /*max iterration*/, true); 139 //} 149 140 ++EvaluatedSolutions; 150 141 Population.Add(new EMMSolution(childScope)); … … 152 143 Population.Add(new EMMSolution(selected.SubScopes[i])); 153 144 } 154 155 145 if (EvaluatedSolutions >= maximumEvaluatedSolutions) { 156 146 break; … … 158 148 159 149 } 150 if (Map is EMMSucsessMap) { 151 var population = new Dictionary<ISymbolicExpressionTree, double>(); 152 foreach (var individ in Population) { 153 var tree = (ISymbolicExpressionTree)(((IScope)individ.Individual).Variables["SymbolicExpressionTree"].Value); 154 population.Add(tree, individ.Qualities.Value); 155 } 156 Map.MapUpDate(population); 157 population.Clear(); 158 } 159 //List<object> A = new List<object>(); 160 //A.Add(new Scope ()); 161 //A.Add(new SymbolicExpressionTree()); 162 160 163 globalScope.SubScopes.Replace(Population.Select(x => (IScope)x.Individual)); 161 164 // run analyzer … … 170 173 171 174 // set the execution context for parameters to allow lookup 172 foreach (var parameter in Problem.Parameters.OfType<IValueParameter>()) { // 173 // we need all of these in order for the wiring of the operators to work 174 globalScope.Variables.Add(new Core.Variable(parameter.Name, parameter.Value)); 175 } 176 globalScope.Variables.Add(new Core.Variable("Results", Results)); // make results available as a parameter for analyzers etc. 175 foreach (var parameter in Problem.Parameters.OfType<IValueParameter>()) { 176 globalScope.Variables.Add(new Variable(parameter.Name, parameter.Value)); 177 } 178 globalScope.Variables.Add(new Variable("Results", Results)); // make results available as a parameter for analyzers etc. 177 179 178 180 var rand = RandomParameter.Value; … … 180 182 rand.Reset(Seed); 181 183 182 var populationSize = PopulationSize.Value;183 184 184 InitializePopulation(executionContext, cancellationToken, rand); 185 186 // initialize data structures for map clustering 187 //var models = new ItemList<ISymbolicExpressionTree>(Map.ModelSet); 188 //var map = new ItemList<ItemList<IntValue>>(); 189 //foreach (var list in Map.Map) { 190 // map.Add(new ItemList<IntValue>(list.Select(x => new IntValue(x)))); 191 //} 192 //var clusterNumber = new ItemList<IntValue>(Map.ClusterNumber.Select(x => new IntValue(x))); 193 //globalScope.Variables.Add(new Variable("Models", models)); 194 //globalScope.Variables.Add(new Variable("Map", map)); 195 //globalScope.Variables.Add(new Variable("ClusterNumber", clusterNumber)); 196 197 EvaluatedSolutions = populationSize; 185 EvaluatedSolutions = PopulationSize.Value; 186 198 187 base.Initialize(cancellationToken); 199 188 } 189 200 190 private void InitializePopulation(ExecutionContext executionContext, CancellationToken cancellationToken, IRandom random) { 191 Population = new List<IEMMSolution>(); 192 var evaluator = Problem.Evaluator; 201 193 var creator = Problem.SolutionCreator; 202 var evaluator = Problem.Evaluator;203 var populationSize = PopulationSize.Value;204 Population = new List<IEMMSolution>(populationSize);205 206 194 var parentScope = executionContext.Scope; //main scope for the next step work 207 // first, create all individuals208 for (int i = 0; i < populationSize; ++i) {195 // first, create all individuals 196 for (int i = 0; i < PopulationSize.Value; ++i) { 209 197 var childScope = new Scope(i.ToString()) { Parent = parentScope }; 210 198 ExecuteOperation(executionContext, cancellationToken, executionContext.CreateChildOperation(creator, childScope)); … … 212 200 var tree = (ISymbolicExpressionTree)childScope.Variables[name].Value; 213 201 foreach (var node in tree.IterateNodesPostfix().OfType<TreeModelTreeNode>()) { 214 node.Tree = Map.NewModelForInizializtion(random, out int cluster, out int treeNumber); 215 node.SetLocalParameters(random, 0.5); 216 node.ClusterNumer = cluster; 217 node.TreeNumber = treeNumber; 202 Map.NodeManipulationForInizializtion(random, node); 218 203 } 219 204 parentScope.SubScopes.Add(childScope); 220 205 } 221 222 206 // then, evaluate them and update qualities 223 for (int i = 0; i < populationSize; ++i) {207 for (int i = 0; i < PopulationSize.Value; ++i) { 224 208 var childScope = parentScope.SubScopes[i]; 225 209 ExecuteOperation(executionContext, cancellationToken, executionContext.CreateChildOperation(evaluator, childScope)); 226 227 var qualities = (DoubleValue)childScope.Variables["Quality"].Value; 228 var solution = new EMMSolution(childScope); // Create solution and push individual inside 229 230 solution.Qualities = qualities; 231 Population.Add(solution); // push solution to Population 232 } 233 } 210 Population.Add(new EMMSolution(childScope)); // Create solution and push individual inside. push solution to Population 211 } 212 } 213 214 // next function was not tested in real work 234 215 private void LocalDecent(ISymbolicDataAnalysisSingleObjectiveProblem problem, CancellationToken cancellationToken, IScope childScope) { 235 216 int maxStepNumber = 100; 236 var creator = Problem.SolutionCreator; 237 var name = ((ISymbolicExpressionTreeCreator)creator).SymbolicExpressionTreeParameter.ActualName; 217 var name = ((ISymbolicExpressionTreeCreator)Problem.SolutionCreator).SymbolicExpressionTreeParameter.ActualName; 238 218 var tree = (ISymbolicExpressionTree)childScope.Variables[name].Value; 239 var evaluator = problem.Evaluator;240 219 var oldTree = tree.Clone(); 241 ExecuteOperation(executionContext, cancellationToken, executionContext.CreateChildOperation( evaluator, childScope));220 ExecuteOperation(executionContext, cancellationToken, executionContext.CreateChildOperation(problem.Evaluator, childScope)); 242 221 var rand = RandomParameter.Value; 243 222 if (SetSeedRandomly) Seed = RandomSeedGenerator.GetSeed(); … … 259 238 return maxStepNumber; 260 239 } 261 void ModelChange(TreeModelTreeNode a, IRandom rand, CancellationToken cancellationToken, IScope childScope) {262 int treeNumber = a.TreeNumber;263 var oldSubTree = (ISymbolicExpressionTree) a.Tree.Clone();240 void ModelChange(TreeModelTreeNode tree, IRandom rand, CancellationToken cancellationToken, IScope childScope) { 241 int treeNumber = tree.TreeNumber; 242 var oldSubTree = (ISymbolicExpressionTree)tree.Tree.Clone(); 264 243 double oldQuality = ((DoubleValue)childScope.Variables["Quality"].Value).Value; 265 int cluster = Map.ClusterNumber[treeNumber]; 244 int cluster; 245 if (Map is EMMIslandMap map) 246 cluster = map.ClusterNumber[treeNumber]; 247 else cluster = treeNumber; 266 248 int newTreeNumber = rand.Next(Map.Map[cluster].Count); 267 a.Tree = (ISymbolicExpressionTree)Map.ModelSet[newTreeNumber].Clone();268 a.Tree.Root.ShakeLocalParameters(rand, 1);249 tree.Tree = (ISymbolicExpressionTree)Map.ModelSet[newTreeNumber].Clone(); 250 tree.Tree.Root.ShakeLocalParameters(rand, 1); 269 251 var evaluator = Problem.Evaluator; 270 252 ExecuteOperation(executionContext, cancellationToken, executionContext.CreateChildOperation(evaluator, childScope)); 271 253 double currentQuality = ((DoubleValue)childScope.Variables["Quality"].Value).Value; 272 254 if (oldQuality > currentQuality) { 273 a.Tree = (ISymbolicExpressionTree)oldSubTree.Clone();255 tree.Tree = (ISymbolicExpressionTree)oldSubTree.Clone(); 274 256 ((DoubleValue)childScope.Variables["Quality"].Value).Value = oldQuality; 275 257 } -
TabularUnified branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMBaseAlgorithm.cs ¶
r16899 r17002 35 35 using System; 36 36 using System.Collections.Generic; 37 using System.IO; 37 38 using System.Linq; 38 39 using CancellationToken = System.Threading.CancellationToken; … … 56 57 [Storable] 57 58 protected ExecutionState previousExecutionState; 59 [Storable] 60 protected IEnumerable<ISymbolicExpressionTree> trees; 58 61 59 62 [Storable] … … 77 80 private const string ClusterNumbersParameterName = "ClusterNumbers"; 78 81 private const string ClusterNumbersShowParameterName = "ClusterNumbersShow"; 79 private const string AlgorithmImplementationTypeParameterName = "AlgorithmImpleme tationType";82 private const string AlgorithmImplementationTypeParameterName = "AlgorithmImplementationType"; 80 83 private const string MapParameterName = "Map"; 81 84 private const string NegbourTypeParameterName = "NegbourType"; … … 250 253 ParameterizeSelectors(); 251 254 255 //begin hack ... 256 InputFile.ValueChanged += InputFile_ValueChanged; 257 InfixExpressionParser parser = new InfixExpressionParser(); 258 trees = File.ReadAllLines(InputFileParameter.Value.Value).Select(parser.Parse).ToArray(); 259 // end hack 260 252 261 ProblemChanged += EvolvmentModelsOfModelsAlgorithmBase_ProblemChanged; 253 262 MapParameterUpdate(); 254 } 263 264 } 265 266 // also hack vvvvvvvvv 267 private void InputFile_ValueChanged(object sender, EventArgs e) { 268 InfixExpressionParser parser = new InfixExpressionParser(); 269 trees = File.ReadAllLines(InputFileParameter.Value.Value).Select(parser.Parse); 270 } 271 // remove again ^^^^^^^^^ 255 272 256 273 private void EvolvmentModelsOfModelsAlgorithmBase_ProblemChanged(object sender, EventArgs e) { … … 271 288 { 272 289 new EMMIslandMap(), 273 new EMMNetworkMap(neghboorNumber) 290 new EMMNetworkMap(neghboorNumber), 291 new EMMDisatanceMap(), 292 new EMMRankMap(), 293 new EMMSucsessMap (), 294 new EMMZeroMap () 274 295 }; 275 296 foreach (var t in mapTypes) { … … 314 335 globalScope = cloner.Clone(original.globalScope); 315 336 } 337 338 // hack 339 trees = original.trees.Select(x => cloner.Clone(x)).ToArray(); 316 340 } 317 341 -
TabularUnified branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMBaseMap.cs ¶
r16899 r17002 25 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 26 using HeuristicLab.Problems.DataAnalysis.Symbolic; 27 using HeuristicLab.Random; 27 28 using System.Collections.Generic; 28 29 using System.IO; … … 32 33 [StorableType("83CF9650-98FF-454B-9072-82EA4D39C752")] 33 34 public abstract class EMMMapBase<T> : Item where T : class { 35 #region data members 34 36 [Storable] 35 37 public List<T> ModelSet { get; set; } 36 38 [Storable] 37 public List<int> ClusterNumber { get; set; }38 [Storable]39 39 public List<List<int>> Map { get; set; } 40 [Storable] 41 public double[,] Distances { get; set; } 42 [Storable] 43 public int K { get; protected set; } 44 45 protected void CalculateDistances() { 46 if (ModelSet is List<ISymbolicExpressionTree> set) { 47 Distances = SymbolicExpressionTreeHash.ComputeSimilarityMatrix(set, simplify: false, strict: true); 48 } else { /// for future work 49 for (int i = 0; i < ModelSet.Count - 1; i++) { 50 for (int j = 0; j <= i; j++) { 51 Distances[i, j] = 0; 52 } 53 } 54 } 55 for (int i = 0; i < ModelSet.Count - 1; i++) { 56 for (int j = i + 1; j < ModelSet.Count; j++) { 57 Distances[j, i] = Distances[i, j] = 1 - Distances[i, j]; 58 } 59 } 60 61 } 62 public abstract void CreateMap(IRandom random, int k); 63 public abstract T NewModelForInizializtionNotTree(IRandom random, out int cluster, out int treeNumber); 64 public ISymbolicExpressionTree NewModelForInizializtion(IRandom random, out int cluster, out int treeNumber) { 65 treeNumber = random.Next(ModelSet.Count); 66 cluster = ClusterNumber[treeNumber]; 67 if (ModelSet[treeNumber] is ISymbolicExpressionTree model) 68 return (ISymbolicExpressionTree)(model.Clone()); 69 return new SymbolicExpressionTree(); 70 } 71 40 #endregion 41 #region constructors 72 42 [StorableConstructor] 73 43 protected EMMMapBase(StorableConstructorFlag _) : base(_) { } 74 protected EMMMapBase() : this(1) { } 75 public EMMMapBase(int k) { 76 K = k; 77 ClusterNumber = new List<int>(); 44 public EMMMapBase() { 78 45 Map = new List<List<int>>(); 79 46 } … … 84 51 else ModelSet = original.ModelSet.ToList(); /// check this if you want to use it 85 52 } 86 if (original.ClusterNumber != null) {87 ClusterNumber = original.ClusterNumber.ToList();88 }89 53 if (original.Map != null) { 90 54 Map = original.Map.Select(x => x.ToList()).ToList(); 91 55 } 92 K = original.K;93 56 } 94 //public EMMMapBase(IRandom random, IEnumerable<T> trees, int k) : this(k) { 95 // // constructor that should be used in case of creation of a new map from the start point 96 // ModelSet = trees.ToList(); 97 // CalculateDistances(); 98 // CreateMap(random, k); 99 //} 100 //public EMMMapBase(IRandom random, IEnumerable<T> trees, string fileName = "Map.txt") : this(1) { 101 // // constructor that shoud be used in case of using of "old" map, that was previously created and now shoud be readed from file 102 // ModelSet = trees.ToList(); 103 // MapFromFileRead(fileName); 104 // K = Map.Count; 105 // MapPreparation(); 106 //} 107 public void MapCreationPrepare(IRandom random, IEnumerable<T> trees, int k) { 57 #endregion 58 #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); 79 public void MapCreationPrepare(IEnumerable<T> trees) { 108 80 ModelSet = trees.ToList(); 109 CalculateDistances();110 CreateMap(random, k);111 81 } 82 83 protected void MapSizeCheck(int k) { 84 if (Map != null) Map.Clear(); 85 else Map = new List<List<int>>(); 86 if (Map.Count != k) { 87 if (Map.Count != 0) { 88 Map.Clear(); 89 } 90 for (int i = 0; i < k; i++) { 91 Map.Add(new List<int>()); 92 } 93 } 94 } 95 #endregion 96 #region map and files 112 97 public void MapRead(IRandom random, IEnumerable<T> trees, string fileName = "Map.txt") { 113 98 ModelSet = trees.ToList(); 114 99 MapFromFileRead(fileName); 115 K = Map.Count; 116 MapPreparation(); 100 if (this is EMMIslandMap island) { island.ClusterNumbersCalculate(); } 117 101 if (this is EMMNetworkMap one) { one.NeghboorNumber = Map[0].Count; } 118 102 } … … 126 110 fileName2 += s; 127 111 fileName2 += ".txt"; 128 File.WriteAllLines(fileName , MapToSee());112 File.WriteAllLines(fileName2, MapToSee()); 129 113 } 130 114 public string[] MapToString() { // Function that preapre Map to printing in .txt File: create a set of strings for future reading by computer 131 115 string[] s; 132 s = new string[ K];133 for (int i = 0; i < K; i++) {116 s = new string[Map.Count]; 117 for (int i = 0; i < Map.Count; i++) { 134 118 s[i] = ""; 135 119 for (int j = 0; j < Map[i].Count; j++) { … … 146 130 s[0] = "ClusterNumber" + "," + "ModelNumber" + "," + "Model"; 147 131 for (int i = 1; i < ((ModelSet.Count) + 1); i++) { 148 s[i] = ClusterNumber[i - 1].ToString() + "," + (i - 1).ToString() + ","; 132 s[i] = ""; 133 if (this is EMMIslandMap island) { 134 s[i] += island.ClusterNumber[i - 1].ToString() + ","; 135 } 136 s[i] += (i - 1).ToString() + ","; 149 137 if (ModelSet[i - 1] is ISymbolicExpressionTree model) { 150 138 s[i] += fmt.Format(model); … … 164 152 } 165 153 } 166 protected void MapSizeCheck() { 167 if (Map != null) Map.Clear(); 168 else Map = new List<List<int>>(); 169 if (Map.Count != K) { 170 if (Map.Count != 0) { 171 Map.Clear(); 172 } 173 for (int i = 0; i < K; i++) { 174 Map.Add(new List<int>()); 154 #endregion 155 156 #region map use functions 157 public abstract T NewModelForInizializtionNotTree(IRandom random, out int treeNumber); 158 public ISymbolicExpressionTree NewModelForInizializtion(IRandom random, out int treeNumber) { 159 treeNumber = random.Next(ModelSet.Count); 160 if (ModelSet[treeNumber] is ISymbolicExpressionTree model) 161 return (ISymbolicExpressionTree)(model.Clone()); 162 return new SymbolicExpressionTree(); 163 } 164 public void NodeManipulationForInizializtion(IRandom random, TreeModelTreeNode node) { 165 node.Tree = NewModelForInizializtion(random, out int treeNumber); 166 node.SetLocalParameters(random, 0.5); 167 node.TreeNumber = treeNumber; 168 } 169 public abstract ISymbolicExpressionTree NewModelForMutation(IRandom random, out int treeNumber, int parentTreeNumber); 170 public virtual void NodeForMutationChange(IRandom random, TreeModelTreeNode treeNode) { 171 int treeNumber = treeNode.TreeNumber; 172 int treeNumber2 = treeNode.TreeNumber; 173 treeNode.Tree = new SymbolicExpressionTree(NewModelForMutation(random, out treeNumber, treeNumber2).Root); 174 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); 175 184 } 176 185 } 177 186 } 178 protected void MapPreparation() { 179 for (int i = 0; i < Map.Count; i++) { 180 for (int j = 0; j < Map[i].Count; j++) { 181 ClusterNumber.Add(0); 182 } 183 } 184 for (int i = 0; i < Map.Count; i++) { 185 for (int j = 0; j < Map[i].Count; j++) { 186 ClusterNumber[Map[i][j]] = i; 187 } 188 } 189 } 187 public virtual void MapUpDate(Dictionary<ISymbolicExpressionTree, double> population) { } 188 #endregion 190 189 } 191 190 } -
TabularUnified branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMDisatanceMap.cs ¶
r16899 r17002 1 using HEAL.Attic; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using HEAL.Attic; 2 23 using HeuristicLab.Common; 3 24 using HeuristicLab.Core; 4 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 using System; 5 27 using System.Collections.Generic; 6 28 … … 9 31 [StorableType("456692FB-2149-4359-8106-45D59D2D7FA0")] 10 32 public class EMMDisatanceMap : EMMMapBase<ISymbolicExpressionTree> { 11 12 // Under the work now. Do not take into account =)33 [Storable] 34 public List<List<double>> Probabilities { get; set; } 13 35 #region conctructors 14 36 [StorableConstructor] 15 37 protected EMMDisatanceMap(StorableConstructorFlag _) : base(_) { } 16 public EMMDisatanceMap() : this(1) { }17 38 public override IDeepCloneable Clone(Cloner cloner) { 18 39 return new EMMDisatanceMap(this, cloner); 19 40 } 20 public EMMDisatanceMap( int k) : base(k) { ModelSet = new List<ISymbolicExpressionTree>(); }41 public EMMDisatanceMap() : base() { ModelSet = new List<ISymbolicExpressionTree>(); } 21 42 public EMMDisatanceMap(EMMDisatanceMap original, Cloner cloner) : base(original, cloner) { } 22 43 #endregion 23 #region Map ApplayFunctions44 #region MapCreation 24 45 override public void CreateMap(IRandom random, int k) { 25 K = Map.Count; 26 ApplyDistanceMapCreationAlgorithm(random, Distances, Map, K); 27 for (int i = 0; i < Map.Count; i++) { 28 ClusterNumber.Add(i); 46 47 Probabilities = new List<List<double>>(); 48 MapSizeCheck(ModelSet.Count); 49 ApplyDistanceMapCreationAlgorithm(random, CalculateDistances(), Map, Probabilities); 50 } 51 public static void ApplyDistanceMapCreationAlgorithm(IRandom random, double[,] distances, List<List<int>> map, List<List<double>> probabilities) { 52 int mapSize = distances.GetLength(0); 53 for (int t = 0; t < mapSize; t++) { 54 probabilities.Add(new List<double>()); 55 double tempSum = 0; 56 for (int i = 0; i < mapSize; i++) { 57 tempSum += Math.Log(distances[i, t]); 58 } 59 for (int i = 0; i < mapSize; i++) { 60 if (distances[i, t].IsAlmost(0)) 61 continue; 62 map[t].Add(i); 63 probabilities[t].Add(Math.Log(distances[i, t]) / tempSum); 64 } 29 65 } 30 66 } 31 public static void ApplyDistanceMapCreationAlgorithm(IRandom random, double[,] distances, List<List<int>> map, int k, int neghboorNumber = 10) { 32 int mapSize = distances.GetLength(0); 33 List<double> currentList = new List<double>(); 34 for (int i = 0; i < mapSize; i++) { 35 map.Add(new List<int>()); 36 for (int j = 0; j < mapSize; j++) { 37 currentList.Add(distances[i, j]); 38 } 39 map[i].Add(HelpFunctions.ChooseMinElementIndex(currentList)); 40 while (map[i].Count < neghboorNumber) { 41 map[i].Add(HelpFunctions.ChooseMinElementIndex(currentList, i, map[i])); 42 } 43 currentList.Clear(); 44 } 67 #endregion 68 #region MapApplayFunctions 69 public override ISymbolicExpressionTree NewModelForMutation(IRandom random, out int treeNumber, int parentTreeNumber) { 70 treeNumber = HelpFunctions.OneElementFromListProportionalSelection(random, Probabilities[parentTreeNumber]); 71 return (ISymbolicExpressionTree)ModelSet[treeNumber].Clone(); 45 72 } 46 47 override public ISymbolicExpressionTree NewModelForInizializtionNotTree(IRandom random, out int cluster, out int treeNumber) { 48 return NewModelForInizializtion(random, out cluster, out treeNumber); 73 override public ISymbolicExpressionTree NewModelForInizializtionNotTree(IRandom random, out int treeNumber) { 74 return NewModelForInizializtion(random, out treeNumber); 49 75 } 50 76 #endregion -
TabularUnified branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMIslandMap.cs ¶
r16899 r17002 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 using HeuristicLab.Random; 26 27 using System.Collections.Generic; 28 using System.Linq; 27 29 28 30 namespace HeuristicLab.Algorithms.EvolvmentModelsOfModels { … … 30 32 [StorableType("E4AB04B9-FD5D-47EE-949D-243660754F3A")] 31 33 public class EMMIslandMap : EMMMapBase<ISymbolicExpressionTree> { 34 [Storable] 35 public List<int> ClusterNumber { get; set; } // May be only Island Map really need it 32 36 #region conctructors 33 37 [StorableConstructor] 34 38 protected EMMIslandMap(StorableConstructorFlag _) : base(_) { } 35 public EMMIslandMap() : this(1) { } 39 public EMMIslandMap() { 40 ModelSet = new List<ISymbolicExpressionTree>(); 41 ClusterNumber = new List<int>(); 42 } 36 43 public override IDeepCloneable Clone(Cloner cloner) { 37 44 return new EMMIslandMap(this, cloner); 38 45 } 39 public EMMIslandMap(int k) : base(k) { ModelSet = new List<ISymbolicExpressionTree>(); } 40 public EMMIslandMap(EMMIslandMap original, Cloner cloner) : base(original, cloner) { } 41 // public EMMIslandMap(IRandom random, IEnumerable<ISymbolicExpressionTree> trees, int k, int neghboorNumber) : base(random, trees, k) { } 42 //public EMMIslandMap(IRandom random, IEnumerable<ISymbolicExpressionTree> trees, string fileName = "Map.txt") : base(random, trees, fileName) { } 46 public EMMIslandMap(EMMIslandMap original, Cloner cloner) : base(original, cloner) { 47 if (original.ClusterNumber != null) { 48 ClusterNumber = original.ClusterNumber.ToList(); 49 } 50 } 43 51 #endregion 44 52 #region MapApplayFunctions 45 53 override public void CreateMap(IRandom random, int k) { 46 K = EMModelsClusterizationAlgorithm.ApplyClusteringAlgorithm(random, Distances, ClusterNumber, k); 47 MapSizeCheck(); 54 55 k = EMModelsClusterizationAlgorithm.ApplyClusteringAlgorithm(random, CalculateDistances(), ClusterNumber, k); 56 MapSizeCheck(k); 48 57 for (int i = 0; i < ModelSet.Count; i++) { 49 58 Map[ClusterNumber[i]].Add(i); 50 59 } 51 60 } 52 override public ISymbolicExpressionTree NewModelForInizializtionNotTree(IRandom random, out int cluster, out int treeNumber) { 53 return NewModelForInizializtion(random, out cluster, out treeNumber); 61 override public ISymbolicExpressionTree NewModelForInizializtionNotTree(IRandom random, out int treeNumber) { 62 return NewModelForInizializtion(random, out treeNumber); 63 } 64 65 public override ISymbolicExpressionTree NewModelForMutation(IRandom random, out int treeNumber, int parentTreeNumber) { 66 if (parentTreeNumber == -10) { 67 treeNumber = random.Next(ModelSet.Count); 68 } else { 69 treeNumber = Map[ClusterNumber[parentTreeNumber]].SampleRandom(random); 70 } 71 return (ISymbolicExpressionTree)ModelSet[treeNumber].Clone(); 72 } 73 public void ClusterNumbersCalculate() { // May be it should be transported to Child Clase (IslandMap) 74 for (int i = 0; i < Map.Count; i++) { 75 for (int j = 0; j < Map[i].Count; j++) { 76 ClusterNumber.Add(0); 77 } 78 } 79 for (int i = 0; i < Map.Count; i++) { 80 for (int j = 0; j < Map[i].Count; j++) { 81 ClusterNumber[Map[i][j]] = i; 82 } 83 } 54 84 } 55 85 #endregion -
TabularUnified branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMMultyPointsMutator.cs ¶
r16899 r17002 27 27 using HeuristicLab.Parameters; 28 28 using HeuristicLab.Problems.DataAnalysis.Symbolic; 29 using HeuristicLab.Random;30 29 using System.Collections.Generic; 31 30 using System.Linq; … … 44 43 } 45 44 public List<ISymbolicExpressionTree> ModelSet => MapParameter.ActualValue.ModelSet; 46 public List<int> ClusterNumber => MapParameter.ActualValue.ClusterNumber;47 45 public List<List<int>> Map => MapParameter.ActualValue.Map; 48 46 public PercentValue MutationProbability => MutationProbabilityParameter.ActualValue; … … 61 59 62 60 protected override void Manipulate(IRandom random, ISymbolicExpressionTree symbolicExpressionTree) { 63 EMMOnePointMutatorPart(random, symbolicExpressionTree, ModelSet, ClusterNumber,Map, MutationProbability);61 EMMOnePointMutatorPart(random, symbolicExpressionTree, ModelSet, Map, MutationProbability); 64 62 } 65 63 private static bool SymbolTypeCheck(ISymbol nSymbol, IEnumerable<ISymbol> allSymbols) { … … 70 68 return false; 71 69 } 72 public static void EMMOnePointMutatorPart(IRandom random, ISymbolicExpressionTree symbolicExpressionTree, List<ISymbolicExpressionTree> modelSet, List<int> clusterNumber, List<List<int>> map, PercentValue mutationProbability) {70 public void EMMOnePointMutatorPart(IRandom random, ISymbolicExpressionTree symbolicExpressionTree, List<ISymbolicExpressionTree> modelSet, List<List<int>> map, PercentValue mutationProbability) { 73 71 74 72 List<ISymbol> allowedSymbols = new List<ISymbol>(); … … 93 91 } 94 92 int pTemp = random.Next(map.Count); 95 if (node is TreeModelTreeNode treeNode) { pTemp = treeNode. ClusterNumer; } //remeber the cluster number93 if (node is TreeModelTreeNode treeNode) { pTemp = treeNode.TreeNumber; } //remeber the cluster number 96 94 var weights = allowedSymbols.Select(s => s.InitialFrequency).ToList(); // set up probabilities 97 95 … … 102 100 103 101 if (node is TreeModelTreeNode treeNode2) { // make rigth mutation for tree model 104 treeNode2.TreeNumber = map[pTemp].SampleRandom(random); 105 treeNode2.Tree = (ISymbolicExpressionTree)modelSet[treeNode2.TreeNumber].Clone(); 106 treeNode2.ClusterNumer = pTemp; 107 treeNode2.SetLocalParameters(random, 1); 102 treeNode2.TreeNumber = pTemp; 103 MapParameter.ActualValue.NodeForMutationChange(random, treeNode2); 108 104 } else if (node.HasLocalParameters) { // make local parametrs set up for other node types 109 105 node.ResetLocalParameters(random); -
TabularUnified branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMMultyPointsMutatorNodeTypeSaving.cs ¶
r16899 r17002 27 27 using HeuristicLab.Parameters; 28 28 using HeuristicLab.Problems.DataAnalysis.Symbolic; 29 using HeuristicLab.Random;30 29 using System.Collections.Generic; 31 30 using System.Linq; … … 42 41 } 43 42 public List<ISymbolicExpressionTree> ModelSet => MapParameter.ActualValue.ModelSet; 44 public List<int> ClusterNumber => MapParameter.ActualValue.ClusterNumber;45 43 public List<List<int>> Map => MapParameter.ActualValue.Map; 46 44 … … 64 62 65 63 protected override void Manipulate(IRandom random, ISymbolicExpressionTree symbolicExpressionTree) { 66 EMMOnePointMutatorPart(random, symbolicExpressionTree, ModelSet, ClusterNumber,Map, MutationProbability);64 EMMOnePointMutatorPart(random, symbolicExpressionTree, ModelSet, Map, MutationProbability); 67 65 } 68 66 private static bool SymbolTypeCheck(ISymbol nSymbol, IEnumerable<ISymbol> allSymbols) { … … 73 71 return false; 74 72 } 75 public static void EMMOnePointMutatorPart(IRandom random, ISymbolicExpressionTree symbolicExpressionTree, List<ISymbolicExpressionTree> modelSet, List<int> clusterNumber, List<List<int>> map, PercentValue mutationProbability) {73 public void EMMOnePointMutatorPart(IRandom random, ISymbolicExpressionTree symbolicExpressionTree, List<ISymbolicExpressionTree> modelSet, List<List<int>> map, PercentValue mutationProbability) { 76 74 77 75 List<ISymbol> allowedSymbols = new List<ISymbol>(); … … 95 93 allowedSymbols.Add(node.Symbol); 96 94 } 97 int pTemp = random.Next(m ap.Count);98 if (node is TreeModelTreeNode treeNode) { pTemp = treeNode. ClusterNumer; } //remeber the cluster number95 int pTemp = random.Next(modelSet.Count); 96 if (node is TreeModelTreeNode treeNode) { pTemp = treeNode.TreeNumber; } //remeber the cluster number 99 97 var weights = allowedSymbols.Select(s => s.InitialFrequency).ToList(); // set up probabilities 100 98 … … 105 103 106 104 if (node is TreeModelTreeNode treeNode2) { // make rigth mutation for tree model 107 treeNode2.TreeNumber = map[pTemp].SampleRandom(random); 108 treeNode2.Tree = (ISymbolicExpressionTree)modelSet[treeNode2.TreeNumber].Clone(); 109 treeNode2.ClusterNumer = pTemp; 110 treeNode2.SetLocalParameters(random, 1); 105 treeNode2.TreeNumber = pTemp; 106 MapParameter.ActualValue.NodeForMutationChange(random, treeNode2); 111 107 } else if (node.HasLocalParameters) { // make local parametrs set up for other node types 112 108 node.ResetLocalParameters(random); -
TabularUnified branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMMutators.cs ¶
r16899 r17002 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Data;26 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 26 using HeuristicLab.Parameters; 28 27 using HeuristicLab.Problems.DataAnalysis.Symbolic; 29 using HeuristicLab.Random;30 28 using System.Collections.Generic; 31 29 using System.Linq; … … 43 41 44 42 public List<ISymbolicExpressionTree> ModelSet => MapParameter.ActualValue.ModelSet; 45 public List<int> ClusterNumber => MapParameter.ActualValue.ClusterNumber;46 43 public List<List<int>> Map => MapParameter.ActualValue.Map; 47 44 … … 58 55 59 56 protected override void Manipulate(IRandom random, ISymbolicExpressionTree symbolicExpressionTree) { 60 EMMMutatorsPart(random, symbolicExpressionTree, ModelSet, ClusterNumber,Map);57 EMMMutatorsPart(random, symbolicExpressionTree, ModelSet, Map); 61 58 } 62 public static void EMMMutatorsPart(IRandom random, ISymbolicExpressionTree symbolicExpressionTree, List<ISymbolicExpressionTree> modelSet, List<int> clusterNumber, List<List<int>> map) {59 public void EMMMutatorsPart(IRandom random, ISymbolicExpressionTree symbolicExpressionTree, List<ISymbolicExpressionTree> modelSet, List<List<int>> map) { 63 60 List<ISymbol> allowedSymbols = new List<ISymbol>(); 64 61 ISymbolicExpressionTreeNode parent; … … 109 106 110 107 if (newNode is TreeModelTreeNode treeNode) { 111 int p = random.Next(map.Count); 112 if (child is TreeModelTreeNode chNode) { p = chNode.ClusterNumer; } 113 treeNode.TreeNumber = map[p].SampleRandom(random); 114 treeNode.Tree = (ISymbolicExpressionTree)modelSet[treeNode.TreeNumber].Clone(); 115 treeNode.ClusterNumer = p; 116 treeNode.SetLocalParameters(random, 0.5); 108 int p = random.Next(modelSet.Count); 109 if (child is TreeModelTreeNode chNode) { p = chNode.TreeNumber; } 110 treeNode.TreeNumber = p; 111 MapParameter.ActualValue.NodeForMutationChange(random, treeNode); 117 112 } else if (newNode.HasLocalParameters) 118 113 newNode.ResetLocalParameters(random); -
TabularUnified branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMNetworkMap.cs ¶
r16899 r17002 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 using HeuristicLab.Random; 26 27 using System.Collections.Generic; 27 28 … … 42 43 } 43 44 public EMMNetworkMap(EMMNetworkMap original, Cloner cloner) : base(original, cloner) { NeghboorNumber = original.NeghboorNumber; } 44 //public EMMNetworkMap(IRandom random, IEnumerable<ISymbolicExpressionTree> trees, int k, int neghboorNumber = 10) : this(neghboorNumber) {45 // // constructor that should be used in case of creation of a new map from the start point46 // ModelSet = trees.ToList();47 // CalculateDistances();48 // NeghboorNumber = neghboorNumber; // this shoud be done before map creation, so it is impossible to create tree wisout it49 // CreateMap(random, k);50 //}51 //public EMMNetworkMap(IRandom random, IEnumerable<ISymbolicExpressionTree> trees, string fileName = "Map.txt") : base(random, trees, fileName) {52 // NeghboorNumber = Map[0].Count;53 //}54 45 #endregion 55 46 #region MapTransformation 56 47 override public void CreateMap(IRandom random, int k) { 57 K = Map.Count; 58 ApplyNetworkMapCreationAlgorithm(random, Distances, Map, K, NeghboorNumber); 59 for (int i = 0; i < Map.Count; i++) { 60 ClusterNumber.Add(i); 61 } 48 ApplyNetworkMapCreationAlgorithm(random, CalculateDistances(), Map, NeghboorNumber); 62 49 } 63 public static void ApplyNetworkMapCreationAlgorithm(IRandom random, double[,] distances, List<List<int>> map, int k, intneghboorNumber = 10) {50 public static void ApplyNetworkMapCreationAlgorithm(IRandom random, double[,] distances, List<List<int>> map, int neghboorNumber = 10) { 64 51 int mapSize = distances.GetLength(0); 65 52 List<double> currentList = new List<double>(); … … 78 65 #endregion 79 66 #region Dialog with surroudings 80 override public ISymbolicExpressionTree NewModelForInizializtionNotTree(IRandom random, out int cluster, out int treeNumber) { 81 var newTree = NewModelForInizializtion(random, out cluster, out treeNumber); 67 public override ISymbolicExpressionTree NewModelForMutation(IRandom random, out int treeNumber, int parentTreeNumber) { 68 treeNumber = Map[parentTreeNumber].SampleRandom(random); 69 return (ISymbolicExpressionTree)ModelSet[treeNumber].Clone(); 70 } 71 override public ISymbolicExpressionTree NewModelForInizializtionNotTree(IRandom random, out int treeNumber) { 72 var newTree = NewModelForInizializtion(random, out treeNumber); 82 73 return newTree; 83 74 } -
TabularUnified branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMSolution.cs ¶
r16734 r17002 45 45 Individual = individual; 46 46 } 47 47 public EMMSolution(IScope scope) { 48 Individual = scope; 49 Qualities = (DoubleValue)scope.Variables["Quality"].Value; 50 } 48 51 public EMMSolution(IItem individual, DoubleValue qualities) { 49 52 Individual = individual; … … 62 65 63 66 protected EMMSolution(EMMSolution original, Cloner cloner) : base(original, cloner) { 64 Qualities = original.Qualities;65 Individual = (IItem)original.Individual.Clone(cloner);67 Qualities = cloner.Clone(original.Qualities); 68 Individual = cloner.Clone(original.Individual); 66 69 } 67 70 -
TabularUnified branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/HelpFunctions.cs ¶
r16899 r17002 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 using HeuristicLab.Core; 2 22 using System.Collections.Generic; 3 23 using System.Linq; 4 using System.Text;5 using System.Threading.Tasks;6 using HEAL.Attic;7 24 8 25 namespace HeuristicLab.Algorithms.EvolvmentModelsOfModels { 9 26 class HelpFunctions { 27 public static int OneElementFromListProportionalSelection(IRandom random, List<double> list) { 28 double selectedQuality = random.NextDouble() * list.Sum(); 29 int index = 0; 30 double currentQuality = list[index]; 31 while ((currentQuality < selectedQuality) && (index < list.Count)) { 32 index++; 33 currentQuality += list[index]; 34 } 35 return index; 36 } 10 37 public static int ChooseMinElementIndex(List<double> distances, int currentElement, List<int> previousNumbers) { 11 38 double minValue = 100; … … 28 55 return minElementNumber; 29 56 } 57 30 58 public static bool CheckNumberIsInList(int number, List<int> priviousNumber) { 31 59 foreach (var pNum in priviousNumber) { … … 46 74 return minElementNumber; 47 75 } 76 public static int ChooseMaxElementIndex(List<double> averageClusterDistance) { 77 double maxValue = averageClusterDistance[0]; 78 int maxElementNumber = 0; 79 for (int i = 1; i < averageClusterDistance.Count(); i++) { 80 if (averageClusterDistance[i] > maxValue) { 81 maxValue = averageClusterDistance[i]; 82 maxElementNumber = i; 83 } 84 } 85 return maxElementNumber; 86 } 87 public static double CheckSocialKatre(double socialKarteValue, double value, double stepValue) { 88 if (value > (socialKarteValue + stepValue)) 89 return stepValue; 90 else if (value > socialKarteValue) 91 return (value - socialKarteValue); 92 else return 0; 93 } 94 public static void ProbabilitiesUpDate(List<List<double>> sucsessStatistics, List<double> probabilities) { 95 96 var averageQuality = new List<double>(); 97 foreach (var variant in sucsessStatistics) { 98 if (variant[0] > 0.005) { 99 averageQuality.Add(variant[1] / variant[0]); 100 } else { averageQuality.Add(0); } 101 } 102 int bestModelNumber = ChooseMaxElementIndex(averageQuality); 103 double socialKarte = 1.0 / (probabilities.Count * 20.0); // parameters of method 104 double stepValue = socialKarte / 5.0; 105 double totalChangeValue = 0, changeValue = 0; 106 for (int i = 0; i < probabilities.Count; i++) { 107 changeValue = CheckSocialKatre(socialKarte, probabilities[i], stepValue); 108 totalChangeValue += changeValue; 109 probabilities[i] -= changeValue; 110 } 111 probabilities[bestModelNumber] += totalChangeValue; 112 } 48 113 } 49 114 } -
TabularUnified branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/HeuristicLab.Algorithms.EvolvmentModelsOfModels.csproj ¶
r16899 r17002 128 128 <Compile Include="EMMBaseAlgorithm.cs" /> 129 129 <Compile Include="EMMNetworkMap.cs" /> 130 <Compile Include="EMMSucsessMap.cs" /> 131 <Compile Include="EMMZeroMap.cs" /> 130 132 <Compile Include="HelpFunctions.cs" /> 133 <Compile Include="ModelClustersFrequencyAnalyzer.cs" /> 131 134 <Compile Include="Plugin.cs" /> 132 135 <Compile Include="Properties\AssemblyInfo.cs" /> 136 <Compile Include="EMMRankMap.cs" /> 133 137 </ItemGroup> 134 138 <ItemGroup> -
TabularUnified branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/ModelClustersFrequencyAnalyzer.cs ¶
r16899 r17002 21 21 22 22 using HEAL.Attic; 23 using HeuristicLab.Algorithms.EvolvmentModelsOfModels; 23 24 using HeuristicLab.Analysis; 24 25 using HeuristicLab.Common; … … 43 44 44 45 #region parameter properties 45 [Storable]46 private const string MapParameterName = "Map"; 46 47 public ILookupParameter<DataTable> ModelClustersFrequencyParameter { 47 48 get { return (ILookupParameter<DataTable>)Parameters[ModelClustersFrequencyParameterName]; } 48 49 } 49 [Storable]50 50 public IValueLookupParameter<BoolValue> AggregateModelClustersParameter { 51 51 get { return (IValueLookupParameter<BoolValue>)Parameters[AggregateModelClustersParameterName]; } 52 52 } 53 public ILookupParameter<EMMMapBase<ISymbolicExpressionTree>> MapParameter { 54 get { return (ILookupParameter<EMMMapBase<ISymbolicExpressionTree>>)Parameters[MapParameterName]; } 55 } 56 53 57 #endregion 54 58 #region properties … … 71 75 Parameters.Add(new LookupParameter<DataTable>(ModelClustersFrequencyParameterName, "The relative Model Clusters reference frequencies aggregated over all trees in the population.")); 72 76 Parameters.Add(new ValueLookupParameter<BoolValue>(AggregateModelClustersParameterName, "Switch that determines whether all references to factor Model Clusters should be aggregated regardless of the value. Turn off to analyze all factor variable references with different values separately.", new BoolValue(true))); 77 Parameters.Add(new LookupParameter<EMMMapBase<ISymbolicExpressionTree>>(MapParameterName)); 73 78 } 74 79 … … 103 108 int numberOfValues = datatable.Rows.Select(r => r.Values.Count).DefaultIfEmpty().First(); 104 109 105 foreach (var pair in CalculateModelClustersFrequency(expressions )) {110 foreach (var pair in CalculateModelClustersFrequency(expressions, MapParameter.ActualValue)) { 106 111 if (!datatable.Rows.ContainsKey(pair.Key)) { 107 112 // initialize a new row for the variable and pad with zeros … … 120 125 } 121 126 122 public static IEnumerable<KeyValuePair<string, double>> CalculateModelClustersFrequency(IEnumerable<ISymbolicExpressionTree> trees ) {127 public static IEnumerable<KeyValuePair<string, double>> CalculateModelClustersFrequency(IEnumerable<ISymbolicExpressionTree> trees, EMMMapBase<ISymbolicExpressionTree> map) { 123 128 var modelClustersFrequency = trees 124 .SelectMany(t => GetModelClustersReferences(t ))129 .SelectMany(t => GetModelClustersReferences(t, map)) 125 130 .GroupBy(pair => pair.Key, pair => pair.Value) 126 .ToDictionary(g => g.Key, g => (double)g.Sum());131 .ToDictionary(g => g.Key, g => g.Sum()); 127 132 128 133 double totalNumberOfSymbols = modelClustersFrequency.Values.Sum(); … … 132 137 } 133 138 134 private static IEnumerable<KeyValuePair<string, int>> GetModelClustersReferences(ISymbolicExpressionTree tree) { 135 Dictionary<string, int> references = new Dictionary<string, int>(); 136 foreach (var treeNode in tree.IterateNodesPrefix().OfType<TreeModelTreeNode>()) { 137 string referenceId = "Cluster " + treeNode.ClusterNumer; 138 if (references.ContainsKey(referenceId)) { 139 references[referenceId]++; 139 private static IEnumerable<KeyValuePair<string, double>> GetModelClustersReferences(ISymbolicExpressionTree tree, EMMMapBase<ISymbolicExpressionTree> map) { 140 Dictionary<string, double> references = new Dictionary<string, double>(); 141 if (map is EMMIslandMap island) { 142 foreach (var treeNode in tree.IterateNodesPrefix().OfType<TreeModelTreeNode>()) { 143 string referenceId = "no"; 144 145 referenceId = "Cluster " + island.ClusterNumber[treeNode.TreeNumber]; 146 if (references.ContainsKey(referenceId)) { 147 int a = (int)references[referenceId]; 148 a++; 149 references[referenceId] = a; 150 } else { 151 references[referenceId] = 1; 152 } 153 } 154 } else { 155 if (map is EMMSucsessMap sMap) { 156 for (int i = 0; i < map.ModelSet.Count; i++) { 157 string referenceId = "Tree Probability" + i; 158 references[referenceId] = sMap.Probabilities[i]; 159 } 140 160 } else { 141 references[referenceId] = 1; 161 string referenceId = "no"; 162 references[referenceId] = 0; 142 163 } 143 164 } -
TabularUnified branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/Plugin.cs.frame ¶
r16722 r17002 28 28 [Plugin("HeuristicLab.Algorithms.EMMAlgorithm", "3.3.15.$WCREV$")] 29 29 [PluginFile("HeuristicLab.Algorithms.EMMAlgorithm-3.3.dll", PluginFileType.Assembly)] 30 [PluginDependency("HeuristicLab.Algorithms.DataAnalysis", "3.4")] 30 31 [PluginDependency("HeuristicLab.Analysis", "3.3")] 31 32 [PluginDependency("HeuristicLab.Collections", "3.3")] … … 33 34 [PluginDependency("HeuristicLab.Core", "3.3")] 34 35 [PluginDependency("HeuristicLab.Data", "3.3")] 36 [PluginDependency("HeuristicLab.Encodings.SymbolicExpressionTreeEncoding", "3.4")] 35 37 [PluginDependency("HeuristicLab.Operators", "3.3")] 36 38 [PluginDependency("HeuristicLab.Optimization", "3.3")] 37 [PluginDependency("HeuristicLab.Optimization.Operators", "3.3")]38 39 [PluginDependency("HeuristicLab.Parameters", "3.3")] 39 [PluginDependency("HeuristicLab.P ersistence", "3.3")]40 [PluginDependency("HeuristicLab.Problems.DataAnalysis.Symbolic", "3.4")] 40 41 [PluginDependency("HeuristicLab.Random", "3.3")] 41 42 [PluginDependency("HeuristicLab.Selection", "3.3")] -
TabularUnified branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/ModelsFrequencyAnalyzer.cs ¶
r16899 r17002 43 43 44 44 #region parameter properties 45 [Storable] 45 46 46 public ILookupParameter<DataTable> ModelFrequencyParameter { 47 47 get { return (ILookupParameter<DataTable>)Parameters[ModelsFrequencyParameterName]; } 48 48 } 49 [Storable] 49 50 50 public IValueLookupParameter<BoolValue> AggregateModelParameter { 51 51 get { return (IValueLookupParameter<BoolValue>)Parameters[AggregateModelParameterName]; } -
TabularUnified branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/TerminalNodesFrequencyAnalyzer.cs ¶
r16899 r17002 43 43 44 44 #region parameter properties 45 [Storable]46 45 public ILookupParameter<DataTable> TerminalNodesFrequencyParameter { 47 46 get { return (ILookupParameter<DataTable>)Parameters[TerminalNodesFrequencyParameterName]; } 48 47 } 49 [Storable]50 48 public IValueLookupParameter<BoolValue> AggregateTerminalNodesParameter { 51 49 get { return (IValueLookupParameter<BoolValue>)Parameters[AggregateTerminalNodesParameterName]; } -
TabularUnified branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj ¶
r16760 r17002 216 216 <Compile Include="Analyzers\MinAverageMaxSymbolicExpressionTreeVariablesNumberAnalyzer.cs" /> 217 217 <Compile Include="Analyzers\MinAverageMaxSymbolicExpressionTreeComplexcityAnalyzer.cs" /> 218 <Compile Include="Analyzers\ModelClustersFrequencyAnalyzer.cs" />219 218 <Compile Include="Analyzers\ModelsFrequencyAnalyzer.cs" /> 220 219 <Compile Include="Analyzers\SymbolicDataAnalysisBottomUpDiversityAnalyzer.cs" /> -
TabularUnified branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/ModelTreeNode.cs ¶
r16899 r17002 39 39 set { tree = value; } 40 40 } 41 int clusterNumer = -10; 42 int treeNumber = 0; 43 public int ClusterNumer { 44 get { return clusterNumer; } 45 set { clusterNumer = value; } 46 } 41 [Storable] 42 int treeNumber = -10; 47 43 public int TreeNumber { 48 44 get { return treeNumber; } … … 51 47 52 48 [StorableConstructor] 53 private TreeModelTreeNode(StorableConstructorFlag _) : base(_) { 54 ClusterNumer = -10; 55 } 49 private TreeModelTreeNode(StorableConstructorFlag _) : base(_) { } 56 50 57 51 private TreeModelTreeNode(TreeModelTreeNode original, Cloner cloner) 58 52 : base(original, cloner) { 59 53 tree = (ISymbolicExpressionTree)original.tree.Clone(cloner); 60 ClusterNumer = original.ClusterNumer;61 54 TreeNumber = original.TreeNumber; 62 55 } 63 56 64 57 private TreeModelTreeNode() : base() { } 65 public TreeModelTreeNode(TreeModel treeModelSymbol) : base(treeModelSymbol) { 66 ClusterNumer = -10; 67 } 58 public TreeModelTreeNode(TreeModel treeModelSymbol) : base(treeModelSymbol) { } 68 59 69 60 public override bool HasLocalParameters {
Note: See TracChangeset
for help on using the changeset viewer.