- Timestamp:
- 04/01/19 13:03:13 (5 years ago)
- Location:
- branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM
- Files:
-
- 7 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")]
Note: See TracChangeset
for help on using the changeset viewer.