- Timestamp:
- 04/04/19 14:33:12 (6 years ago)
- Location:
- branches/2988_ModelsOfModels2
- Files:
-
- 3 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMAlgorithm.cs
r16734 r16760 28 28 using HeuristicLab.Random; 29 29 using HeuristicLab.Selection; 30 using System; 30 31 using System.Collections.Generic; 31 32 using System.IO; … … 61 62 trees.First().Root.Grammar.ContainsSymbol((IVariable)a). 62 63 = 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); 64 int neghboorNumber = 10; 65 switch (MapCreationType.Value) { // Configure Map type and it's parameters: IslandMap, FullMap and Percent, Number 66 case "IslandMap": break; 67 case "FullMap": 68 ClusterNumbersParameter.Value.Value = trees.Count(); 69 switch (NegbourType.Value) { 70 case "Percent": neghboorNumber = Convert.ToInt32((Convert.ToDouble(ClusterNumbersParameter.Value.Value)) * (Convert.ToDouble(NegbourNumber.Value)) / 100.0); break; 71 case "Number": neghboorNumber = NegbourNumber.Value; break; 72 default: neghboorNumber = NegbourNumber.Value; break; 73 } 74 break; 75 default: MapCreationType.Value = "IslandMap"; break; 76 } 77 switch (AlgorithmImplemetationType.Value) { //Configure type of algorithm application 78 case "OnlyMapCreation": // for case when we want only create map, and do not want made somting also. OnlyMapCreation, CrateMapAndGo, ReadMapAndGo 79 Map = new EMMMapTreeModel(RandomParameter.Value, trees, ClusterNumbersParameter.Value.Value, neghboorNumber); 67 80 ClusterNumbersParameter.Value.Value = Map.K; 68 81 File.WriteAllLines("Map.txt", Map.MapToString()); … … 71 84 executionContext = new ExecutionContext(null, this, globalScope); 72 85 break; 73 case 1: // for case when we want read existed map and work with it;86 case "ReadMapAndGo": // for case when we want read existed map and work with it; 74 87 Map = new EMMMapTreeModel(RandomParameter.Value, trees); 75 88 ClusterNumbersParameter.Value.Value = Map.K; … … 78 91 } 79 92 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); 93 EMMAlgorithmRun(cancellationToken); 94 break; 95 case "CreateMapAndGo": 96 Map = new EMMMapTreeModel(RandomParameter.Value, trees, ClusterNumbersParameter.Value.Value, neghboorNumber); 85 97 ClusterNumbersParameter.Value.Value = Map.K; 86 98 if (previousExecutionState != ExecutionState.Paused) { … … 88 100 } 89 101 globalScope.Variables.Add(new Variable("TreeModelMap", Map)); 90 EMMEvolutionaryAlgorithmRun(cancellationToken); 91 break; 92 } 93 94 } 95 private void EMMEvolutionaryAlgorithmRun(CancellationToken cancellationToken) { 102 File.WriteAllLines("Map.txt", Map.MapToString()); 103 File.WriteAllLines("MapToSee.txt", Map.MapToSee()); 104 EMMAlgorithmRun(cancellationToken); 105 break; 106 default: //for case of usial from zero step starting 107 AlgorithmImplemetationType.Value = "CreateMapAndGo"; 108 Map = new EMMMapTreeModel(RandomParameter.Value, trees, ClusterNumbersParameter.Value.Value, neghboorNumber); 109 ClusterNumbersParameter.Value.Value = Map.K; 110 File.WriteAllLines("Map.txt", Map.MapToString()); 111 File.WriteAllLines("MapToSee.txt", Map.MapToSee()); 112 if (previousExecutionState != ExecutionState.Paused) { 113 InitializeAlgorithm(cancellationToken); 114 } 115 globalScope.Variables.Add(new Variable("TreeModelMap", Map)); 116 EMMAlgorithmRun(cancellationToken); 117 break; 118 } 119 120 } 121 private void EMMAlgorithmRun(CancellationToken cancellationToken) { 96 122 var bestSelector = new BestSelector(); 97 123 bestSelector.CopySelected = new BoolValue(false); … … 116 142 var innerToken = new CancellationToken(); 117 143 118 while ( evaluatedSolutions < maximumEvaluatedSolutions && !cancellationToken.IsCancellationRequested) {144 while (EvaluatedSolutions < maximumEvaluatedSolutions && !cancellationToken.IsCancellationRequested) { 119 145 120 146 var op4 = executionContext.CreateChildOperation(bestSelector, executionContext.Scope); // select elites … … 125 151 var selected = executionContext.Scope.SubScopes.Single(x => x.Name == "Selected"); 126 152 executionContext.Scope.SubScopes.AddRange(selected.SubScopes); 127 population.Clear();128 population.AddRange(selected.SubScopes.Select(x => new EMMSolution(x)));153 Population.Clear(); 154 Population.AddRange(selected.SubScopes.Select(x => new EMMSolution(x))); 129 155 executionContext.Scope.SubScopes.Remove(remaining); 130 156 executionContext.Scope.SubScopes.Remove(selected); 131 157 132 var op = executionContext.CreateChildOperation(selector, executionContext.Scope);// select the rest of the population158 var op = executionContext.CreateChildOperation(selector, executionContext.Scope);// select the rest of the Population 133 159 ExecuteOperation(executionContext, innerToken, op); 134 160 … … 163 189 // set child qualities 164 190 childSolution.Qualities = qualities; 165 ++ evaluatedSolutions;166 population.Add(new EMMSolution(childScope));191 ++EvaluatedSolutions; 192 Population.Add(new EMMSolution(childScope)); 167 193 } else {// no crossover or mutation were applied, a child was not produced, do nothing 168 population.Add(new EMMSolution(selected.SubScopes[i]));169 } 170 171 if ( evaluatedSolutions >= maximumEvaluatedSolutions) {194 Population.Add(new EMMSolution(selected.SubScopes[i])); 195 } 196 197 if (EvaluatedSolutions >= maximumEvaluatedSolutions) { 172 198 break; 173 199 } 174 200 175 201 } 176 globalScope.SubScopes.Replace( population.Select(x => (IScope)x.Individual));202 globalScope.SubScopes.Replace(Population.Select(x => (IScope)x.Individual)); 177 203 // run analyzer 178 204 var analyze = executionContext.CreateChildOperation(analyzer, globalScope); 179 205 ExecuteOperation(executionContext, innerToken, analyze); 180 Results.AddOrUpdateResult("Evaluated Solutions", new IntValue( evaluatedSolutions));206 Results.AddOrUpdateResult("Evaluated Solutions", new IntValue(EvaluatedSolutions)); 181 207 } 182 208 } … … 211 237 globalScope.Variables.Add(new Core.Variable("ClusterNumber", clusterNumber)); 212 238 213 evaluatedSolutions = populationSize;239 EvaluatedSolutions = populationSize; 214 240 base.Initialize(cancellationToken); 215 241 } … … 218 244 var evaluator = Problem.Evaluator; 219 245 var populationSize = PopulationSize.Value; 220 population = new List<IEMMSolution>(populationSize);246 Population = new List<IEMMSolution>(populationSize); 221 247 222 248 var parentScope = executionContext.Scope; //main scope for the next step work … … 245 271 246 272 solution.Qualities = qualities; 247 population.Add(solution); // push solution to population273 Population.Add(solution); // push solution to Population 248 274 } 249 275 } -
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMBaseAlgorithm.cs
r16734 r16760 44 44 #region data members 45 45 [Storable] 46 protected IList<IEMMSolution> solutions; 47 [Storable] 48 protected List<IEMMSolution> population; 49 [Storable] 50 protected List<IEMMSolution> offspringPopulation; 51 [Storable] 52 protected List<IEMMSolution> jointPopulation; 53 [Storable] 54 protected int evaluatedSolutions; 46 protected IList<IEMMSolution> Solutions; 47 [Storable] 48 protected List<IEMMSolution> Population; 49 [Storable] 50 protected int EvaluatedSolutions; 55 51 [Storable] 56 52 protected ExecutionContext executionContext; … … 76 72 private const string InputFileParameterName = "InputFile"; 77 73 private const string ClusterNumbersParameterName = "ClusterNumbers"; 78 74 private const string AlgorithmImplementationTypeParameterName = "AlgorithmImplemetationType"; 75 private const string MapCreationTypeParameterName = "MapCreationType"; 76 private const string NegbourTypeParameterName = "NegbourType"; 77 private const string NegbourNumberParameterName = "NegbourNumber"; 79 78 public IValueParameter<MultiAnalyzer> AnalyzerParameter { 80 79 get { return (ValueParameter<MultiAnalyzer>)Parameters[AnalyzerParameterName]; } … … 85 84 public IValueParameter<IntValue> ClusterNumbersParameter { 86 85 get { return (IValueParameter<IntValue>)Parameters[ClusterNumbersParameterName]; } 86 } 87 public IFixedValueParameter<StringValue> AlgorithmImplementationTypeParameter { 88 get { return (IFixedValueParameter<StringValue>)Parameters[AlgorithmImplementationTypeParameterName]; } 89 } 90 public IFixedValueParameter<StringValue> MapCreationTypeParameter { 91 get { return (IFixedValueParameter<StringValue>)Parameters[MapCreationTypeParameterName]; } 92 } 93 public IFixedValueParameter<StringValue> NegbourTypeParameter { 94 get { return (IFixedValueParameter<StringValue>)Parameters[NegbourTypeParameterName]; } 95 } 96 public IFixedValueParameter<IntValue> NegbourNumberParameter { 97 get { return (IFixedValueParameter<IntValue>)Parameters[NegbourNumberParameterName]; } 87 98 } 88 99 public IFixedValueParameter<StringValue> InputFileParameter { … … 133 144 set { ClusterNumbersParameter.Value = value; } 134 145 } 146 public StringValue AlgorithmImplemetationType { 147 get { return AlgorithmImplementationTypeParameter.Value; } 148 set { AlgorithmImplementationTypeParameter.Value.Value = value.Value; } 149 } 150 public StringValue MapCreationType { 151 get { return MapCreationTypeParameter.Value; } 152 set { MapCreationTypeParameter.Value.Value = value.Value; } 153 } 154 public StringValue NegbourType { 155 get { return NegbourTypeParameter.Value; } 156 set { NegbourTypeParameter.Value.Value = value.Value; } 157 } 158 public IntValue NegbourNumber { 159 get { return NegbourNumberParameter.Value; } 160 set { NegbourNumberParameter.Value.Value = value.Value; } 161 } 135 162 public StringValue InputFile { 136 163 get { return InputFileParameter.Value; } … … 186 213 187 214 Parameters.Add(new FixedValueParameter<IntValue>(SeedParameterName, "The random seed used to initialize the new pseudo random number generator.", new IntValue(0))); 188 Parameters.Add(new FixedValueParameter<StringValue>(InputFileParameterName, "The file with set of models that will be .", new StringValue("input.txt"))); 215 Parameters.Add(new FixedValueParameter<StringValue>(InputFileParameterName, "The file with set of models that will be.", new StringValue("input.txt"))); 216 Parameters.Add(new FixedValueParameter<StringValue>(AlgorithmImplementationTypeParameterName, "The Type of possible algorith, implemetation, choose one: OnlyMapCreation, CreateMapAndGo, ReadMapAndGo.", new StringValue("CreateMapAndGo"))); 217 Parameters.Add(new FixedValueParameter<StringValue>(MapCreationTypeParameterName, "The type of map crearion algorithm. Use one from: IslandMap, FullMap.", new StringValue("IslandMap"))); 218 Parameters.Add(new FixedValueParameter<IntValue>(NegbourNumberParameterName, "The parametr for FullMap type of map crearion algorithm. Use one from: 10, 20.", new IntValue(10))); 219 Parameters.Add(new FixedValueParameter<StringValue>(NegbourTypeParameterName, "The parametr for FullMap type of map crearion algorithm. Use one from: Percent, Number.", new StringValue("Number"))); 189 220 Parameters.Add(new FixedValueParameter<BoolValue>(SetSeedRandomlyParameterName, "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true))); 190 Parameters.Add(new ValueParameter<IntValue>(PopulationSizeParameterName, "The size of the population of solutions.", new IntValue(100)));221 Parameters.Add(new ValueParameter<IntValue>(PopulationSizeParameterName, "The size of the population of Solutions.", new IntValue(100))); 191 222 Parameters.Add(new ConstrainedValueParameter<ISelector>(SelectorParameterName, "The operator used to sellect parents.")); 192 223 Parameters.Add(new ValueParameter<PercentValue>(CrossoverProbabilityParameterName, "The probability that the crossover operator is applied.", new PercentValue(0.9))); 193 224 Parameters.Add(new ValueParameter<IntValue>(GroupSizeParameterName, "The GoupSize that the Selector operator is applied.", new IntValue(3))); 194 Parameters.Add(new ConstrainedValueParameter<ICrossover>(CrossoverParameterName, "The operator used to cross solutions."));225 Parameters.Add(new ConstrainedValueParameter<ICrossover>(CrossoverParameterName, "The operator used to cross Solutions.")); 195 226 Parameters.Add(new ValueParameter<PercentValue>(MutationProbabilityParameterName, "The probability that the mutation operator is applied on a solution.", new PercentValue(0.25))); 196 Parameters.Add(new ConstrainedValueParameter<IManipulator>(MutatorParameterName, "The operator used to mutate solutions."));227 Parameters.Add(new ConstrainedValueParameter<IManipulator>(MutatorParameterName, "The operator used to mutate Solutions.")); 197 228 Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer())); 198 Parameters.Add(new ValueParameter<IntValue>(MaximumEvaluatedSolutionsParameterName, "The maximum number of evaluated solutions (approximately).", new IntValue(100_000)));229 Parameters.Add(new ValueParameter<IntValue>(MaximumEvaluatedSolutionsParameterName, "The maximum number of evaluated Solutions (approximately).", new IntValue(100_000))); 199 230 Parameters.Add(new ValueParameter<IRandom>(RandomParameterName, new MersenneTwister())); 200 Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));231 Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite Solutions which are kept in each generation.", new IntValue(1))); 201 232 Parameters.Add(new ValueParameter<IntValue>(ClusterNumbersParameterName, "The number of clusters for model Map.", new IntValue(100))); 202 233 foreach (ISelector selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector)).OrderBy(x => x.Name)) … … 218 249 219 250 protected EvolvmentModelsOfModelsAlgorithmBase(EvolvmentModelsOfModelsAlgorithmBase original, Cloner cloner) : base(original, cloner) { 220 evaluatedSolutions = original.evaluatedSolutions;251 EvaluatedSolutions = original.EvaluatedSolutions; 221 252 previousExecutionState = original.previousExecutionState; 222 253 223 if (original. solutions != null) {224 solutions = original.solutions.Select(cloner.Clone).ToArray();225 } 226 227 if (original. population != null) {228 population = original.population.Select(cloner.Clone).ToList();229 } 230 231 if (original.offspringPopulation != null) {232 offspringPopulation = original.offspringPopulation.Select(cloner.Clone).ToList();233 }234 235 if (original.jointPopulation != null) {236 jointPopulation = original.jointPopulation.Select(x => cloner.Clone(x)).ToList();237 }254 if (original.Solutions != null) { 255 Solutions = original.Solutions.Select(cloner.Clone).ToArray(); 256 } 257 258 if (original.Population != null) { 259 Population = original.Population.Select(cloner.Clone).ToList(); 260 } 261 262 //if (original.offspringPopulation != null) { 263 // offspringPopulation = original.offspringPopulation.Select(cloner.Clone).ToList(); 264 //} 265 266 //if (original.jointPopulation != null) { 267 // jointPopulation = original.jointPopulation.Select(x => cloner.Clone(x)).ToList(); 268 //} 238 269 239 270 if (original.executionContext != null) { … … 264 295 265 296 public IList<IEMMSolution> GetResult(IRandom random) { 266 return population;297 return Population; 267 298 } 268 299 … … 384 415 385 416 protected override void OnStopped() { 386 if ( solutions != null) {387 solutions.Clear();388 } 389 if ( population != null) {390 population.Clear();391 } 392 if (offspringPopulation != null) {393 offspringPopulation.Clear();394 }395 if (jointPopulation != null) {396 jointPopulation.Clear();397 }417 if (Solutions != null) { 418 Solutions.Clear(); 419 } 420 if (Population != null) { 421 Population.Clear(); 422 } 423 //if (offspringPopulation != null) { 424 // offspringPopulation.Clear(); 425 //} 426 //if (jointPopulation != null) { 427 // jointPopulation.Clear(); 428 //} 398 429 executionContext.Scope.SubScopes.Clear(); 399 430 base.OnStopped(); -
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMClustering.cs
r16722 r16760 36 36 } 37 37 public int Apply(IRandom random, double[,] distances, List<int> numberCluster) { 38 39 K = ApplyClusteringAlgorithm(random, distances, numberCluster, K); 40 return K; 41 } 42 public static void ApplyFullConectedMapCreationAlgorithm(IRandom random, double[,] distances, List<List<int>> map, int k, int neghboorNumber = 10) { 43 int mapSize = distances.GetLength(0); 44 List<double> currentList = new List<double>(); 45 for (int i = 0; i < mapSize; i++) { 46 map.Add(new List<int>()); 47 for (int j = 0; j < mapSize; j++) { 48 currentList.Add(distances[i, j]); 49 } 50 map[i].Add(ChooseMinElement(currentList)); 51 while (map[i].Count < neghboorNumber) { 52 map[i].Add(ChooseMinElement(currentList, i, map[i])); 53 } 54 currentList.Clear(); 55 } 56 } 57 private static bool CheckNumberIsInList(int number, List<int> priviousNumber) { 58 foreach (var pNum in priviousNumber) { 59 if (number == pNum) 60 return true; 61 } 62 return false; 63 } 64 public static int ApplyClusteringAlgorithm(IRandom random, double[,] distances, List<int> numberCluster, int k) { 38 65 int mapSize = distances.GetLength(0); 39 66 List<int> centroids = new List<int>(); // capacity is equal K 40 67 List<double> averageClusterDistance = new List<double>(); 41 68 List<List<int>> clusters = new List<List<int>>(); // capacity is equal K 42 CentroidsRandomSetUp(random, centroids, mapSize );69 CentroidsRandomSetUp(random, centroids, mapSize, k); 43 70 if (numberCluster.Count == 0) { 44 71 for (int i = 0; i < mapSize; i++) { … … 50 77 while (flag) { 51 78 clusters.Clear(); 52 for (int i = 0; i < K; i++) {79 for (int i = 0; i < k; i++) { 53 80 clusters.Add(new List<int>()); 54 81 55 82 } 56 83 for (int i = 0; i < mapSize; i++) { 57 numberCluster[i] = LookCloseCentroid(centroids, mapSize, distances, i );84 numberCluster[i] = LookCloseCentroid(centroids, mapSize, distances, i, k); 58 85 clusters[numberCluster[i]].Add(numberCluster[i]); 59 86 } 60 NullSizeClusterDelete(centroids, clusters, mapSize, numberCluster);87 k = NullSizeClusterDelete(centroids, clusters, mapSize, numberCluster, k); 61 88 flag = false; 62 for (int i = 0; i < K; i++) {89 for (int i = 0; i < k; i++) { 63 90 AverageClusterDistanceCalculation(averageClusterDistance, distances, numberCluster, mapSize, i); 64 91 var newCentroid = clusters[i][ChooseMinElement(averageClusterDistance)]; … … 70 97 } 71 98 } 72 return K;99 return k; 73 100 } 74 private void CentroidsRandomSetUp(IRandom random, List<int> centroids, int size) {75 for (int i = 0; i < K; i++) {101 private static void CentroidsRandomSetUp(IRandom random, List<int> centroids, int size, int k) { 102 for (int i = 0; i < k; i++) { 76 103 centroids.Add(random.Next(size)); 77 104 } 78 105 } 79 private int LookCloseCentroid(List<int> centroids, int MapSize, double[,] distances, int currentNumber) {106 private static int LookCloseCentroid(List<int> centroids, int MapSize, double[,] distances, int currentNumber, int k) { 80 107 double minDistanse = distances[currentNumber, centroids[0]]; 81 108 int clusterNum = 0; 82 for (int i = 1; i < K; i++) {109 for (int i = 1; i < k; i++) { 83 110 if (minDistanse > distances[currentNumber, centroids[i]]) { 84 111 minDistanse = distances[currentNumber, centroids[i]]; … … 88 115 return clusterNum; 89 116 } 90 private void NullSizeClusterDelete(List<int> centroids, List<List<int>> clusters, int mapSize, List<int> numberCluster) {117 private static int NullSizeClusterDelete(List<int> centroids, List<List<int>> clusters, int mapSize, List<int> numberCluster, int k) { 91 118 int iter = 0; 92 for (int i = 0; i < K; i++) {119 for (int i = 0; i < k; i++) { 93 120 if (clusters[i - iter].Count == 0) { 94 121 for (int j = 0; j < mapSize; j++) { … … 97 124 } 98 125 99 for (int j = 0; j < K- iter; j++) {126 for (int j = 0; j < k - iter; j++) { 100 127 if (j != i - iter) { 101 128 for (int m = 0; m < clusters[j].Count; m++) … … 109 136 } 110 137 } 111 K -= iter; 138 k -= iter; 139 return k; 112 140 } 113 private void AverageClusterDistanceCalculation(List<double> averageClusterDistance, double[,] distances, List<int> numberCluster, int MapSize, int currentClusterNumber) {141 private static void AverageClusterDistanceCalculation(List<double> averageClusterDistance, double[,] distances, List<int> numberCluster, int MapSize, int currentClusterNumber) { 114 142 int m = 0; 115 143 for (int i = 0; i < MapSize; i++) { … … 124 152 } 125 153 } 126 private int ChooseMinElement(List<double> averageClusterDistance) {154 private static int ChooseMinElement(List<double> averageClusterDistance) { 127 155 double minValue = averageClusterDistance[0]; 128 156 int minElementNumber = 0; … … 135 163 return minElementNumber; 136 164 } 165 private static int ChooseMinElement(List<double> distances, int currentElement, List<int> previousNumbers) { 166 double minValue = 100; 167 int minElementNumber = 0; 168 int temp = 0, i = 0; 169 while (temp == 0) { 170 if ((currentElement != i) && (!CheckNumberIsInList(i, previousNumbers))) { 171 minValue = distances[i]; 172 minElementNumber = i; 173 temp = i; 174 } 175 i++; 176 } 177 for (i = 0; i < distances.Count(); i++) { 178 if ((distances[i] < minValue) && (currentElement != i) && (!CheckNumberIsInList(i, previousNumbers))) { 179 minValue = distances[i]; 180 minElementNumber = i; 181 } 182 } 183 return minElementNumber; 184 } 137 185 } 138 186 } -
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMMapBase.cs
r16734 r16760 34 34 35 35 protected abstract void CalculateDistances(); 36 protected abstract void Create Map(IRandom random, int k);36 protected abstract void CreateIslandMap(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
r16734 r16760 58 58 K = original.K; 59 59 } 60 public EMMMapTreeModel(IRandom random, IEnumerable<ISymbolicExpressionTree> trees, int k ) : this(k) {60 public EMMMapTreeModel(IRandom random, IEnumerable<ISymbolicExpressionTree> trees, int k, int neghboorNumber) : this(k) { 61 61 ModelSet = trees.ToList(); 62 62 CalculateDistances(); 63 CreateMap(random, k); 63 if (k < ModelSet.Count) 64 CreateIslandMap(random, k); 65 else if (k == ModelSet.Count) { 66 CreateFullConnectedMap(random, k, neghboorNumber); 67 } else { 68 k -= ModelSet.Count; 69 CreateIslandMap(random, k); 70 } 64 71 } 65 72 public EMMMapTreeModel(IRandom random, IEnumerable<ISymbolicExpressionTree> trees) : this(1) { … … 91 98 } 92 99 } 93 override protected void CreateMap(IRandom random, int k) { 100 protected void CreateFullConnectedMap(IRandom random, int k, int neghboorNumber) { 101 EMModelsClusterizationAlgorithm.ApplyFullConectedMapCreationAlgorithm(random, Distances, Map, k, neghboorNumber); 94 102 K = k; 103 for (int i = 0; i < Map.Count; i++) { 104 ClusterNumber.Add(i); 105 } 106 } 107 override protected void CreateIslandMap(IRandom random, int k) { 95 108 //Clusterization 96 EMModelsClusterizationAlgorithm clusteringAlgorithm = new EMModelsClusterizationAlgorithm(K); 97 K = clusteringAlgorithm.Apply(random, Distances, ClusterNumber); 109 K = EMModelsClusterizationAlgorithm.ApplyClusteringAlgorithm(random, Distances, ClusterNumber, k); 98 110 // Cheking a Map size 99 111 if (Map != null) Map.Clear(); -
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/EMMMutators.cs
r16734 r16760 71 71 72 72 protected override void Manipulate(IRandom random, ISymbolicExpressionTree symbolicExpressionTree) { 73 //EMMMapTreeModel map= (EMMMapTreeModel)ExecutionContext.Scope.Variables["TreeModelMap"].Value;74 73 EMMMutatorsPart(random, symbolicExpressionTree, ModelSet, ClusterNumber, Map); 75 74 } … … 121 120 122 121 var newNode = newSymbol.CreateTreeNode(); 123 if (newNode.HasLocalParameters) 124 125 126 if (child is TreeModelTreeNode chNode) // in real life never bacame true. It need some cheking127 { p = chNode.ClusterNumer; }128 treeNode.TreeNumber = map[p].SampleRandom(random).Value;129 treeNode.Tree = (ISymbolicExpressionTree)modelSet[treeNode.TreeNumber].Clone();130 131 } else132 122 123 if (newNode is TreeModelTreeNode treeNode) { 124 int p = random.Next(map.Count); 125 if (child is TreeModelTreeNode chNode) { p = chNode.ClusterNumer; } 126 treeNode.TreeNumber = map[p].SampleRandom(random).Value; 127 treeNode.Tree = (ISymbolicExpressionTree)modelSet[treeNode.TreeNumber].Clone(); 128 treeNode.ClusterNumer = p; 129 treeNode.SetLocalParameters(random, 0.5); 130 } else if (newNode.HasLocalParameters) 131 newNode.ResetLocalParameters(random); 133 132 foreach (var subtree in child.Subtrees) 134 133 newNode.AddSubtree(subtree); -
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/HeuristicLab.Algorithms.EvolvmentModelsOfModels.csproj
r16722 r16760 109 109 </ItemGroup> 110 110 <ItemGroup> 111 <Compile Include="EMMMultyPointsMutator.cs" /> 111 112 <Compile Include="EMMAlgorithm.cs" /> 112 113 <Compile Include="EMMClustering.cs" /> 113 114 <Compile Include="EMMMapBase.cs" /> 114 115 <Compile Include="EMMMapTreeModel.cs" /> 116 <Compile Include="EMMMultyPointsMutatorNodeTypeSaving.cs" /> 115 117 <Compile Include="EMMMutators.cs" /> 116 118 <Compile Include="EMMSolution.cs" /> -
branches/2988_ModelsOfModels2/HeuristicLab.Algorithms.EMM/Plugin.cs
r16734 r16760 26 26 /// Plugin class for HeuristicLab.Algorithms.EMMAlgorithm plugin. 27 27 /// </summary> 28 [Plugin("HeuristicLab.Algorithms.EMMAlgorithm", "3.3.15.167 22")]28 [Plugin("HeuristicLab.Algorithms.EMMAlgorithm", "3.3.15.16734")] 29 29 [PluginFile("HeuristicLab.Algorithms.EMMAlgorithm-3.3.dll", PluginFileType.Assembly)] 30 30 [PluginDependency("HeuristicLab.Analysis", "3.3")] -
branches/2988_ModelsOfModels2/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj
r16722 r16760 182 182 <Compile Include="ArchitectureManipulators\SubroutineDuplicater.cs" /> 183 183 <Compile Include="ArchitectureManipulators\SymbolicExpressionTreeArchitectureManipulator.cs" /> 184 <Compile Include="Grammars\EMMTreeModelGrammar.cs" />185 184 <Compile Include="Grammars\GrammarUtils.cs" /> 186 185 <Compile Include="SymbolicExpressionTreeProblem.cs" /> -
branches/2988_ModelsOfModels2/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r16734 r16760 235 235 </Compile> 236 236 <Compile Include="Analyzers\SymbolicDataAnalysisVariableFrequencyAnalyzer.cs" /> 237 <Compile Include="Analyzers\TerminalNodesFrequencyAnalyzer.cs" /> 237 238 <Compile Include="Converters\LinearModelToTreeConverter.cs" /> 238 239 <Compile Include="Converters\TreeSimplifier.cs" />
Note: See TracChangeset
for help on using the changeset viewer.