- Timestamp:
- 11/26/10 22:00:21 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis.PopulationDiversityAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/FineGrainedStructuralPopulationDiversityAnalyzer.cs
r4948 r4949 161 161 162 162 protected override double[,] CalculateSimilarities(SymbolicExpressionTree[] solutions) { 163 // collect information stored int the problem's parameters 163 164 double variableWeightSigma = 0; 164 165 double constantMinimumValue = 0; … … 187 188 } 188 189 variableNames.Add(ProblemData.TargetVariable.Value); 190 // collect genetic information item lists and store them also in dictionaries 189 191 IList<GeneticInformationItem>[] geneticInformationItemsLists = new List<GeneticInformationItem>[n]; 192 IDictionary<string, IList<GeneticInformationItem>>[] geneticInformationItemsListsDictionaries = new IDictionary<string, IList<GeneticInformationItem>>[n]; 190 193 for (int i = 0; i < n; i++) { 191 194 geneticInformationItemsLists[i] = GeneticInformationItem.getGeneticInformationItems(solutions[i].Root, variableNames, MinimumLevelDelta, MaximumLevelDelta); 192 } 193 double[,] result = new double[n, n]; 195 geneticInformationItemsListsDictionaries[i] = GeneticInformationItem.GetDictionary(geneticInformationItemsLists[i]); 196 } 197 // calculate solution similarities 198 double[,] similarities = new double[n, n]; 194 199 for (int i = 0; i < n; i++) { 195 200 for (int j = 0; j < n; j++) { 196 201 if (i == j) 197 result[i, j] = 1;202 similarities[i, j] = 1; 198 203 else { 199 IList<GeneticInformationItem> solution1GeneticItems = GeneticInformationItem.CopyList(geneticInformationItemsLists[i]);200 I List<GeneticInformationItem> solution2GeneticItems = GeneticInformationItem.CopyList(geneticInformationItemsLists[j]);204 IList<GeneticInformationItem> solution1GeneticItems = geneticInformationItemsLists[i]; 205 IDictionary<string, IList<GeneticInformationItem>> solution2GeneticItemsDictionary = GeneticInformationItem.CopyDictionary(geneticInformationItemsListsDictionaries[j]); 201 206 double similarity = 0; 202 207 for (int k = 0; k < solution1GeneticItems.Count; k++) { 203 double bestPendantSimilarity; 204 GeneticInformationItem bestPendant = GeneticInformationItem.FindBestPendant(solution1GeneticItems[k], solution2GeneticItems, 205 constantMinimumValue, constantMaximumValue, variableWeightSigma, 206 MaximumExpressionDepth, minimumTimeOffset, maximumTimeOffset, 207 LevelDifferenceCoefficient, AncestorIndexCoefficient, ConstantValueCoefficient, VariableWeightCoefficient, 208 TimeOffsetCoefficientCoefficient, VariableIndexCoefficient, AdditiveSimilarityCalculation, 209 out bestPendantSimilarity); 208 double bestPendantSimilarity = 0; 209 GeneticInformationItem item = solution1GeneticItems[k]; 210 GeneticInformationItem bestPendant = null; 211 IList<GeneticInformationItem> geneticInformationItemsList = null; 212 string key = GeneticInformationItem.GetKey(item); 213 if (solution2GeneticItemsDictionary.ContainsKey(key)) { 214 geneticInformationItemsList = solution2GeneticItemsDictionary[GeneticInformationItem.GetKey(item)]; 215 bestPendant = GeneticInformationItem.FindBestPendant(item, geneticInformationItemsList, 216 constantMinimumValue, constantMaximumValue, variableWeightSigma, 217 MaximumExpressionDepth, minimumTimeOffset, maximumTimeOffset, 218 LevelDifferenceCoefficient, AncestorIndexCoefficient, ConstantValueCoefficient, VariableWeightCoefficient, 219 TimeOffsetCoefficientCoefficient, VariableIndexCoefficient, AdditiveSimilarityCalculation, 220 out bestPendantSimilarity); 221 } 210 222 if (bestPendant != null) { 211 223 similarity += bestPendantSimilarity; 212 224 if (PreventMultipleComparisonContribution) 213 solution2GeneticItems.Remove(bestPendant);225 geneticInformationItemsList.Remove(bestPendant); 214 226 } 215 227 } 216 result[i, j] = similarity / solution1GeneticItems.Count;228 similarities[i, j] = similarity / solution1GeneticItems.Count; 217 229 } 218 230 } 219 231 } 220 return result;232 return similarities; 221 233 } 222 234 … … 278 290 list.AddRange(GeneticInformationItemsList); 279 291 return list; 292 } 293 294 public static string GetKey(GeneticInformationItem item) { 295 return item.AncestorDefinition.Name.ToString() + "," + item.DescendantDefinition.Name.ToString(); 296 } 297 298 public static IDictionary<string, IList<GeneticInformationItem>> GetDictionary(IList<GeneticInformationItem> GeneticInformationItemsList) { 299 IDictionary<string, IList<GeneticInformationItem>> dictionary = new Dictionary<string, IList<GeneticInformationItem>>(); 300 foreach (GeneticInformationItem item in GeneticInformationItemsList) { 301 string key = GetKey(item); 302 if (!dictionary.ContainsKey(key)) 303 dictionary.Add(key, new List<GeneticInformationItem>()); 304 dictionary[key].Add(item); 305 } 306 return dictionary; 307 } 308 309 public static IDictionary<string, IList<GeneticInformationItem>> CopyDictionary(IDictionary<string, IList<GeneticInformationItem>> Dictionary) { 310 IDictionary<string, IList<GeneticInformationItem>> copy = new Dictionary<string, IList<GeneticInformationItem>>(); 311 foreach (KeyValuePair<string, IList<GeneticInformationItem>> pair in Dictionary) { 312 copy.Add(pair.Key, CopyList(pair.Value)); 313 } 314 return copy; 280 315 } 281 316
Note: See TracChangeset
for help on using the changeset viewer.