Changeset 16734 for branches/2988_ModelsOfModels2
- Timestamp:
- 04/01/19 13:03:13 (6 years ago)
- Location:
- branches/2988_ModelsOfModels2
- Files:
-
- 2 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMAlgorithm.cs
r16722 r16734 37 37 [Item("EvolvmentModelsOfModels Algorithm ", "EMM implementation")] 38 38 [Creatable(CreatableAttribute.Categories.PopulationBasedAlgorithms, Priority = 125)] 39 [StorableType(" D02C50E5-8325-496F-8DEA-C23651756846")]39 [StorableType("AD23B21F-089A-4C6C-AD2E-1B01E7939CF5")] 40 40 public class EMMAlgorithm : EvolvmentModelsOfModelsAlgorithmBase { 41 41 public EMMMapTreeModel Map { get; private set; } … … 57 57 InfixExpressionParser parser = new InfixExpressionParser(); 58 58 var trees = File.ReadAllLines(InputFileParameter.Value.Value).Select(parser.Parse); 59 Map = new EMMMapTreeModel(RandomParameter.Value, trees, ClusterNumbersParameter.Value.Value); 60 ClusterNumbersParameter.Value.Value = Map.K; 61 if (previousExecutionState != ExecutionState.Paused) { 62 InitializeAlgorithm(cancellationToken); 63 } 64 globalScope.Variables.Add(new Variable("TreeModelMap", Map)); 65 EMMEvolutionaryAlgorithmRun(cancellationToken); 59 // this.Problem.SymbolicExpressionTreeGrammar; 60 /* Problem.ProblemData.Dataset.ColumnNames.Take(2).ToList(); 61 trees.First().Root.Grammar.ContainsSymbol((IVariable)a). 62 = this.Problem.SymbolicExpressionTreeGrammar;*/ 63 int flag = 1; 64 switch (flag) { 65 case 0: // for case when we want only create map, and do not want made somting also. 66 Map = new EMMMapTreeModel(RandomParameter.Value, trees, ClusterNumbersParameter.Value.Value); 67 ClusterNumbersParameter.Value.Value = Map.K; 68 File.WriteAllLines("Map.txt", Map.MapToString()); 69 File.WriteAllLines("MapToSee.txt", Map.MapToSee()); 70 globalScope = new Scope("Global Scope"); 71 executionContext = new ExecutionContext(null, this, globalScope); 72 break; 73 case 1: // for case when we want read existed map and work with it; 74 Map = new EMMMapTreeModel(RandomParameter.Value, trees); 75 ClusterNumbersParameter.Value.Value = Map.K; 76 if (previousExecutionState != ExecutionState.Paused) { 77 InitializeAlgorithm(cancellationToken); 78 } 79 globalScope.Variables.Add(new Variable("TreeModelMap", Map)); 80 EMMEvolutionaryAlgorithmRun(cancellationToken); 81 break; 82 83 default: //for case of usial from zero step starting 84 Map = new EMMMapTreeModel(RandomParameter.Value, trees, ClusterNumbersParameter.Value.Value); 85 ClusterNumbersParameter.Value.Value = Map.K; 86 if (previousExecutionState != ExecutionState.Paused) { 87 InitializeAlgorithm(cancellationToken); 88 } 89 globalScope.Variables.Add(new Variable("TreeModelMap", Map)); 90 EMMEvolutionaryAlgorithmRun(cancellationToken); 91 break; 92 } 93 66 94 } 67 95 private void EMMEvolutionaryAlgorithmRun(CancellationToken cancellationToken) { … … 201 229 foreach (var node in tree.IterateNodesPostfix().OfType<TreeModelTreeNode>()) { 202 230 node.Tree = Map.NewModelForInizializtion(random, out int cluster, out int treeNumber); 203 node. Tree.Root.ShakeLocalParameters(random, 0.5);231 node.SetLocalParameters(random, 0.5); 204 232 node.ClusterNumer = cluster; 205 233 node.TreeNumber = treeNumber; -
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMBaseAlgorithm.cs
r16722 r16734 40 40 namespace HeuristicLab.Algorithms.EvolvmentModelsOfModels { 41 41 [Item("MOEADAlgorithmBase", "Base class for all MOEA/D algorithm variants.")] 42 [StorableType(" DD721D8A-A4DE-44C1-8D83-7888E8433B5F")]42 [StorableType("A56A396B-965A-4ADE-8A2B-AE3A45F9C239")] 43 43 public abstract class EvolvmentModelsOfModelsAlgorithmBase : FixedDataAnalysisAlgorithm<ISymbolicDataAnalysisSingleObjectiveProblem> { 44 44 #region data members -
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMMapBase.cs
r16722 r16734 25 25 26 26 namespace HeuristicLab.Algorithms.EvolvmentModelsOfModels { 27 [StorableType("8 A5818D6-2B74-4148-AFBC-D36CE6256406")]27 [StorableType("83CF9650-98FF-454B-9072-82EA4D39C752")] 28 28 public abstract class EMMMapBase<T> : Item where T : class { 29 29 public List<T> ModelSet { get; set; } … … 34 34 35 35 protected abstract void CalculateDistances(); 36 p ublicabstract void CreateMap(IRandom random, int k);36 protected abstract void CreateMap(IRandom random, int k); 37 37 public abstract T NewModelForInizializtion(IRandom random, out int cluster, out int treeNumber); 38 38 -
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMMapTreeModel.cs
r16722 r16734 26 26 using HeuristicLab.Problems.DataAnalysis.Symbolic; 27 27 using System.Collections.Generic; 28 using System.IO; 28 29 using System.Linq; 29 30 30 31 namespace HeuristicLab.Algorithms.EvolvmentModelsOfModels { 31 [StorableType("A9AE93F0-E589-44D0-AD34-0E3AA358D669")]32 32 [Item("TreeModelMap", "A map of models of models of models")] 33 [StorableType("E4AB04B9-FD5D-47EE-949D-243660754F3A")] 33 34 public class EMMMapTreeModel : EMMMapBase<ISymbolicExpressionTree> { 34 35 #region conctructors … … 62 63 CreateMap(random, k); 63 64 } 65 public EMMMapTreeModel(IRandom random, IEnumerable<ISymbolicExpressionTree> trees) : this(1) { 66 ModelSet = trees.ToList(); 67 string input = File.ReadAllText("Map.txt"); 68 69 int i = 0; 70 foreach (var row in input.Split('\n')) { 71 Map.Add(new List<int>()); 72 foreach (var col in row.Trim().Split(' ')) { 73 Map[i].Add(int.Parse(col.Trim())); 74 } 75 i++; 76 } 77 K = Map.Count; 78 MapPreparation(); 79 } 64 80 public override IDeepCloneable Clone(Cloner cloner) { 65 81 return new EMMMapTreeModel(this, cloner); … … 75 91 } 76 92 } 77 override p ublicvoid CreateMap(IRandom random, int k) {93 override protected void CreateMap(IRandom random, int k) { 78 94 K = k; 79 95 //Clusterization … … 96 112 } 97 113 } 114 protected void MapPreparation() { 115 for (int i = 0; i < Map.Count; i++) { 116 for (int j = 0; j < Map[i].Count; j++) { 117 ClusterNumber.Add(0); 118 } 119 } 120 for (int i = 0; i < Map.Count; i++) { 121 for (int j = 0; j < Map[i].Count; j++) { 122 ClusterNumber[Map[i][j]] = i; 123 } 124 } 125 } 98 126 #endregion 99 127 #region Dialog with surroudings … … 103 131 return (ISymbolicExpressionTree)ModelSet[treeNumber].Clone(); 104 132 } 133 public string[] MapToString() { 134 string[] s; 135 s = new string[K]; 136 for (int i = 0; i < K; i++) { 137 s[i] = ""; 138 for (int j = 0; j < Map[i].Count; j++) { 139 s[i] += Map[i][j].ToString(); 140 s[i] += " "; 141 } 142 } 143 return s; 144 } 145 public string[] MapToSee() { 146 var fmt = new InfixExpressionFormatter(); 147 string[] s; 148 s = new string[(ModelSet.Count) + 1]; 149 s[0] = "ClusterNumber" + "," + "Modfelnumber" + "," + "Model"; 150 for (int i = 1; i < ((ModelSet.Count) + 1); i++) { 151 s[i] = ClusterNumber[i - 1].ToString() + "," + (i - 1).ToString() + "," + fmt.Format(ModelSet[i - 1]); 152 } 153 return s; 154 } 105 155 106 156 #endregion -
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMMutators.cs
r16722 r16734 32 32 33 33 namespace HeuristicLab.Algorithms.EvolvmentModelsOfModels { 34 [StorableType("92D37E9F-8726-4524-AF8F-F3787641F7B9")]35 34 [Item("EMMChangeNodeTypeManipulation", "Selects a random tree node and changes the symbol.")] 35 [StorableType("990D3946-7F06-48B4-B8DB-F8E308D6304D")] 36 36 public sealed class EMMMutators : SymbolicExpressionTreeManipulator { 37 37 private const int MAX_TRIES = 100; … … 125 125 int p = random.Next(map.Count); 126 126 if (child is TreeModelTreeNode chNode) // in real life never bacame true. It need some cheking 127 p = chNode.ClusterNumer;127 { p = chNode.ClusterNumer; } 128 128 treeNode.TreeNumber = map[p].SampleRandom(random).Value; 129 129 treeNode.Tree = (ISymbolicExpressionTree)modelSet[treeNode.TreeNumber].Clone(); 130 treeNode. Tree.Root.ShakeLocalParameters(random, 0.5);130 treeNode.SetLocalParameters(random, 0.5); 131 131 } else 132 132 newNode.ResetLocalParameters(random); -
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMSolution.cs
r16722 r16734 26 26 // Can be deleted potnetinaly 27 27 namespace HeuristicLab.Algorithms.EvolvmentModelsOfModels { 28 [StorableType("AB38211D-5F52-4420-A606-1C3CB58BA27C")] 28 29 public interface IEMMSolution : IItem { 29 30 IItem Individual { get; set; } … … 31 32 } 32 33 [Item("EMMSolution", "Represents a solution inside the EMM population")] 33 [StorableType(" 708BDF29-AD3F-4AFC-83AE-551A27FF45A0")]34 [StorableType("C0E63430-5000-4592-BBE4-2D3E0EE1AE3F")] 34 35 public class EMMSolution : Item, IEMMSolution { 35 36 [Storable] … … 69 70 } 70 71 [Item("EMMSolution", "Represents a solution inside the EMM population")] 71 [StorableType(" 36929CD1-63A5-4270-8C65-2A8177BCA0AE")]72 [StorableType("559EA31B-2263-4233-900C-EC62120EE580")] 72 73 public class EMMSolution<T> : EMMSolution where T : class, IItem { 73 74 public new T Individual { -
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/Plugin.cs
r16722 r16734 26 26 /// Plugin class for HeuristicLab.Algorithms.EMMAlgorithm plugin. 27 27 /// </summary> 28 [Plugin("HeuristicLab.Algorithms.EMMAlgorithm", "3.3.15.16 565")]28 [Plugin("HeuristicLab.Algorithms.EMMAlgorithm", "3.3.15.16722")] 29 29 [PluginFile("HeuristicLab.Algorithms.EMMAlgorithm-3.3.dll", PluginFileType.Assembly)] 30 30 [PluginDependency("HeuristicLab.Analysis", "3.3")] -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisVariableFrequencyAnalyzer.cs
r16565 r16734 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 22 using HEAL.Attic; 25 23 using HeuristicLab.Analysis; 26 24 using HeuristicLab.Common; … … 30 28 using HeuristicLab.Optimization; 31 29 using HeuristicLab.Parameters; 32 using HEAL.Attic; 30 using System; 31 using System.Collections.Generic; 32 using System.Linq; 33 33 34 34 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r16722 r16734 216 216 <Compile Include="Analyzers\MinAverageMaxSymbolicExpressionTreeVariablesNumberAnalyzer.cs" /> 217 217 <Compile Include="Analyzers\MinAverageMaxSymbolicExpressionTreeComplexcityAnalyzer.cs" /> 218 <Compile Include="Analyzers\ModelClustersFrequencyAnalyzer.cs" /> 219 <Compile Include="Analyzers\ModelsFrequencyAnalyzer.cs" /> 218 220 <Compile Include="Analyzers\SymbolicDataAnalysisBottomUpDiversityAnalyzer.cs" /> 219 221 <Compile Include="Analyzers\SymbolicDataAnalysisBuildingBlockAnalyzer.cs" /> … … 232 234 <SubType>Code</SubType> 233 235 </Compile> 236 <Compile Include="Analyzers\SymbolicDataAnalysisVariableFrequencyAnalyzer.cs" /> 234 237 <Compile Include="Converters\LinearModelToTreeConverter.cs" /> 235 238 <Compile Include="Converters\TreeSimplifier.cs" /> … … 260 263 <Compile Include="SymbolicDataAnalysisModelComplexityCalculator.cs" /> 261 264 <Compile Include="SymbolicDataAnalysisExpressionPruningOperator.cs" /> 262 <Compile Include="Analyzers\SymbolicDataAnalysisVariableFrequencyAnalyzer.cs" />263 265 <Compile Include="Analyzers\SymbolicDataAnalysisAlleleFrequencyAnalyzer.cs" /> 264 266 <Compile Include="Creators\MultiSymbolicDataAnalysisExpressionCreator.cs" /> -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/ModelTreeNode.cs
r16722 r16734 25 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 26 using HeuristicLab.Random; 27 using System.Collections.Generic; 28 27 using System.Linq; 29 28 30 29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 31 [StorableType(" 38C37AED-5B9D-488E-8785-D8FF541D9B4C")]30 [StorableType("44B25E73-6C4D-404C-93E5-42B7D2807CF7")] 32 31 public sealed class TreeModelTreeNode : SymbolicExpressionTreeTerminalNode { 33 32 public new TreeModel Symbol { … … 71 70 get { return true; } 72 71 } 73 //public override void ResetLocalParameters(IRandom random, List<ISymbolicExpressionTree> modelSet, List<List<int>> map, List<int> cLusterNumber) {74 // base.ResetLocalParameters(random);75 // if (ClusterNumer < 0) {76 // //Tree = map.NewModelForInizializtion(ClusterNumer, random);77 // var selectedNodelNumber = random.Next(modelSet.Count);78 // ClusterNumer = cLusterNumber[selectedNodelNumber];79 // TreeNumber = selectedNodelNumber;80 // Tree = (ISymbolicExpressionTree)modelSet[selectedNodelNumber].Clone();81 // } else {82 // //New Model For Mutation Adding83 // var selectedNodelNumber = random.Next(map[ClusterNumer].Count);84 // TreeNumber = selectedNodelNumber;85 // Tree = (ISymbolicExpressionTree)modelSet[map[ClusterNumer][selectedNodelNumber]].Clone();86 // }87 88 //}89 90 72 public override void ShakeLocalParameters(IRandom random, double shakingFactor) { 91 73 base.ShakeLocalParameters(random, shakingFactor); 92 List<ISymbolicExpressionTreeNode> parametricNodes = new List<ISymbolicExpressionTreeNode>(); 93 Tree.Root.ForEachNodePostfix(n => { 94 if (n.HasLocalParameters) parametricNodes.Add(n); 95 }); 96 if (parametricNodes.Count > 0) { 74 var parametricNodes = Tree.IterateNodesPrefix().Where(x => x.HasLocalParameters).ToList(); 75 if (parametricNodes.Any()) { 97 76 var selectedPoint = parametricNodes.SampleRandom(random); 98 selectedPoint.ShakeLocalParameters(random, shakingFactor); 77 if (selectedPoint is VariableTreeNode variableTreeNode) { 78 var symbol = variableTreeNode.Symbol; 79 variableTreeNode.Weight = NormalDistributedRandom.NextDouble(random, symbol.WeightManipulatorMu, symbol.WeightManipulatorSigma); 80 } else { 81 selectedPoint.ShakeLocalParameters(random, shakingFactor); 82 } 83 99 84 } 100 85 } 101 86 public void SetLocalParameters(IRandom random, double shakingFactor) { 87 foreach (var node in Tree.IterateNodesPrefix().Where(x => x.HasLocalParameters)) { 88 if (node is VariableTreeNode variableTreeNode) { 89 var symbol = variableTreeNode.Symbol; 90 variableTreeNode.Weight = NormalDistributedRandom.NextDouble(random, symbol.WeightManipulatorMu, symbol.WeightManipulatorSigma); 91 } else { 92 node.ResetLocalParameters(random); 93 } 94 } 95 } 102 96 public override IDeepCloneable Clone(Cloner cloner) { 103 97 return new TreeModelTreeNode(this, cloner); … … 106 100 public override string ToString() { 107 101 108 string s = "model" + " " +TreeNumber.ToString()+"\n " + new InfixExpressionFormatter().Format(tree);102 string s = "model" + " " + TreeNumber.ToString() + "\n " + new InfixExpressionFormatter().Format(tree); 109 103 return s; 110 104 } -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/TreeModel.cs
r16722 r16734 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 22 using HEAL.Attic; 24 23 using HeuristicLab.Common; 25 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 using HEAL.Attic;27 25 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 28 [StorableType(" F8A6AD96-28D9-4BEC-8392-8B7BA824B085")]26 [StorableType("6F628649-7C71-49F3-862A-0BAB4BADF964")] 29 27 public sealed class TreeModel : Symbol { 30 28 … … 39 37 [StorableConstructor] 40 38 private TreeModel(StorableConstructorFlag _) : base(_) { } 41 private TreeModel(TreeModel original, Cloner cloner) : base(original, cloner) { 42 public TreeModel() : base("TreeModel", "Represents a TreeModel.") { 39 private TreeModel(TreeModel original, Cloner cloner) : base(original, cloner) { } 40 public TreeModel() : base("TreeModel", "Represents a TreeModel.") { } 43 41 public override ISymbolicExpressionTreeNode CreateTreeNode() { 44 return new TreeModelTreeNode(this); } 42 return new TreeModelTreeNode(this); 43 } 45 44 46 45 public override IDeepCloneable Clone(Cloner cloner) {
Note: See TracChangeset
for help on using the changeset viewer.