Changeset 1742 for trunk/sources/HeuristicLab.Selection.Uncertainty
- Timestamp:
- 05/05/09 23:29:50 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Selection.Uncertainty/v3.2/UncertainTournamentSelector.cs
r1740 r1742 43 43 AddVariable(new Variable("GroupSize", new IntData(2))); 44 44 GetVariable("CopySelected").GetValue<BoolData>().Data = true; 45 AddVariableInfo(new VariableInfo("SignificanceLevel", "The significance level for the mann whitney wilcoxon rank sum test", typeof(DoubleData), VariableKind.In)); 46 GetVariableInfo("SignificanceLevel").Local = true; 47 AddVariable(new Variable("SignificanceLevel", new DoubleData(0.05))); 45 48 } 46 49 … … 49 52 bool maximization = GetVariableValue<BoolData>("Maximization", source, true).Data; 50 53 int groupSize = GetVariableValue<IntData>("GroupSize", source, true).Data; 54 double alpha = GetVariableValue<DoubleData>("SignificanceLevel", source, true).Data; 55 51 56 for (int i = 0; i < selected; i++) { 52 57 if (source.SubScopes.Count < 1) throw new InvalidOperationException("No source scopes available to select."); 53 58 54 IScope selectedScope = source.SubScopes[random.Next(source.SubScopes.Count)]; 55 double best = selectedScope.GetVariableValue<DoubleData>(qualityInfo.FormalName, false).Data; 56 for (int j = 1; j < groupSize; j++) { 57 IScope scope = source.SubScopes[random.Next(source.SubScopes.Count)]; 58 double quality = scope.GetVariableValue<DoubleData>(qualityInfo.FormalName, false).Data; 59 if (((maximization) && (quality > best)) || 60 ((!maximization) && (quality < best))) { 61 best = quality; 62 selectedScope = scope; 59 double[][] tournamentGroup = new double[groupSize][]; 60 int[] tournamentGroupIndices = new int[groupSize]; 61 double[] tournamentGroupAverages = new double[groupSize]; 62 for (int j = 0; j < groupSize; j++) { 63 tournamentGroupIndices[j] = random.Next(source.SubScopes.Count); 64 tournamentGroup[j] = source.SubScopes[tournamentGroupIndices[j]].GetVariableValue<DoubleArrayData>(qualityInfo.FormalName, false).Data; 65 double sum = 0.0; 66 for (int k = 0; k < tournamentGroup[j].Length; k++) { 67 sum += tournamentGroup[j][k]; 68 } 69 tournamentGroupAverages[j] = sum / (double)tournamentGroup[j].Length; 70 } 71 72 int[] rankList = new int[groupSize]; 73 int highestRank = 0; 74 IList<int> equalRankList = new List<int>(groupSize); 75 for (int j = 0; j < groupSize - 1; j++) { 76 for (int k = j + 1; k < groupSize; k++) { 77 if (MannWhitneyWilcoxonTest.TwoTailedTest(tournamentGroup[j], tournamentGroup[k], alpha)) { // if a 2-tailed test is successful it means that two solutions are likely different 78 if (maximization && tournamentGroupAverages[j] > tournamentGroupAverages[k] 79 || !maximization && tournamentGroupAverages[j] < tournamentGroupAverages[k]) { 80 rankList[j]++; 81 if (rankList[j] > highestRank) { 82 highestRank = rankList[j]; 83 equalRankList.Clear(); 84 equalRankList.Add(j); 85 } else if (rankList[j] == highestRank) { 86 equalRankList.Add(j); 87 } 88 } else if (maximization && tournamentGroupAverages[j] < tournamentGroupAverages[k] 89 || !maximization && tournamentGroupAverages[j] > tournamentGroupAverages[k]) { 90 rankList[k]++; 91 if (rankList[k] > highestRank) { 92 highestRank = rankList[k]; 93 equalRankList.Clear(); 94 equalRankList.Add(k); 95 } else if (rankList[k] == highestRank) { 96 equalRankList.Add(k); 97 } 98 } 99 // else there's a statistical significant difference, but equal average qualities... can that happen? 100 } 63 101 } 64 102 } 103 int selectedScopeIndex = 0; 104 if (equalRankList.Count == 0) 105 selectedScopeIndex = tournamentGroupIndices[random.Next(groupSize)]; // no significance in all the solutions, select one randomly 106 else 107 selectedScopeIndex = tournamentGroupIndices[equalRankList[random.Next(equalRankList.Count)]]; // select among those with the highest rank randomly 108 109 IScope selectedScope = source.SubScopes[selectedScopeIndex]; 65 110 66 111 if (copySelected)
Note: See TracChangeset
for help on using the changeset viewer.