Changeset 4224
- Timestamp:
- 08/16/10 10:02:12 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Operators/DynOpEqComparator.cs
r4193 r4224 68 68 public ILookupParameter<ItemList<IntValue>> TotalCountsParameter { 69 69 get { return (ILookupParameter<ItemList<IntValue>>)Parameters["TotalCounts"]; } 70 } 71 public IValueLookupParameter<BoolValue> AntiOverfitParameter { 72 get { return (IValueLookupParameter<BoolValue>)Parameters["AntiOverfit"]; } 73 } 74 public ILookupParameter<DoubleValue> CurrentBestValidationQualityParameter { 75 get { return (ILookupParameter<DoubleValue>)Parameters["Current best validation quality"]; } 76 } 77 public ILookupParameter<DoubleValue> BestValidationQualityParameter { 78 get { return (ILookupParameter<DoubleValue>)Parameters["Best solution quality (validation)"]; } 70 79 } 71 80 … … 83 92 Parameters.Add(new LookupParameter<ItemList<IntValue>>("AcceptedCounts")); 84 93 Parameters.Add(new LookupParameter<ItemList<IntValue>>("TotalCounts")); 94 Parameters.Add(new ValueLookupParameter<BoolValue>("AntiOverfit", new BoolValue(false))); 95 Parameters.Add(new LookupParameter<DoubleValue>("Current best validation quality")); 96 Parameters.Add(new LookupParameter<DoubleValue>("Best solution quality (validation)")); 85 97 } 86 98 … … 91 103 int bin = GetBinIndexForSize(size); 92 104 if (LeftSideParameter.ActualValue == null) { 105 // not yet evaluated 106 #region debugging 93 107 ItemList<IntValue> totalCounts = TotalCountsParameter.ActualValue; 94 108 while (bin >= totalCounts.Count) totalCounts.Add(new IntValue(0)); 95 109 totalCounts[bin].Value = totalCounts[bin].Value + 1; 96 97 if (!Exists(bin)) ResultParameter.ActualValue = new BoolValue(true); 98 else ResultParameter.ActualValue = new BoolValue(IsNotFull(bin)); 110 #endregion 111 if (!Exists(bin)) { 112 113 if (AntiOverfitParameter.ActualValue.Value) { 114 // reject more complex solutions if the current validation quality is worse than the best so far 115 ResultParameter.ActualValue = new BoolValue(!IsOverfitting()); 116 } else { 117 // new bin -> evaluate and check later 118 ResultParameter.ActualValue = new BoolValue(true); 119 } 120 } else { 121 // bin exists: 122 // if bin is full -> reject 123 // otherwise -> evaluate and check success criterion 124 ResultParameter.ActualValue = new BoolValue(IsNotFull(bin)); 125 } 99 126 } else { 100 127 double leftQuality = LeftSideParameter.ActualValue.Value; 101 102 103 128 ResultParameter.ActualValue = new BoolValue(Accept(size, bin, leftQuality)); 104 129 } … … 107 132 } 108 133 134 private bool IsOverfitting() { 135 bool maximization = MaximizationParameter.ActualValue.Value; 136 if (CurrentBestValidationQualityParameter.ActualValue != null && BestValidationQualityParameter.ActualValue != null) { 137 double currentValidationQuality = CurrentBestValidationQualityParameter.ActualValue.Value; 138 double bestValidationQuality = BestValidationQualityParameter.ActualValue.Value; 139 return maximization ? currentValidationQuality < bestValidationQuality : currentValidationQuality > bestValidationQuality; 140 } else 141 return false; 142 } 143 109 144 private int GetBinIndexForSize(int size) { 110 145 return (int)Math.Floor((size - 3.0) / BinSizeParameter.ActualValue.Value); … … 114 149 bool accept = false; 115 150 if (Exists(binIndex)) { 116 if (IsNotFull(binIndex)||117 NewBestOfBin(solutionQuality, binIndex)) {118 151 //if (IsNotFull(binIndex) /*|| 152 //NewBestOfBin(solutionQuality, binIndex)*/) { 153 AddToBin(solutionQuality, binIndex); 119 154 accept = true; 120 }155 //} 121 156 } else if (NewBestOfRun(solutionQuality)) { 122 157 CreateNewBin(binIndex); … … 130 165 ItemList<DoubleValue> acceptedBinQualities = AcceptedBinQualitiesParameter.ActualValue[binIndex]; 131 166 ItemList<IntValue> acceptedCounts = AcceptedCountsParameter.ActualValue; 132 if (acceptedBinQualities.Count == 0) { 133 acceptedBinQualities.Add(new DoubleValue(solutionQuality)); 134 acceptedCounts[binIndex].Value = acceptedCounts[binIndex].Value + 1; 135 } else { 136 // insert at beginning if it is a new best or add at end 137 bool maximization = MaximizationParameter.ActualValue.Value; 138 if ((maximization && solutionQuality > acceptedBinQualities[0].Value) || 139 (!maximization && solutionQuality < acceptedBinQualities[0].Value)) { 140 acceptedBinQualities.Insert(0, new DoubleValue(solutionQuality)); 141 } else { 142 acceptedBinQualities.Add(new DoubleValue(solutionQuality)); 143 } 144 acceptedCounts[binIndex].Value = acceptedCounts[binIndex].Value + 1; 145 } 167 acceptedBinQualities.Add(new DoubleValue(solutionQuality)); 168 acceptedCounts[binIndex].Value = acceptedCounts[binIndex].Value + 1; 146 169 } 147 170 … … 165 188 } 166 189 167 private bool NewBestOfBin(double solutionQuality, int binIndex) {168 ItemList<ItemList<DoubleValue>> acceptedQualities = AcceptedBinQualitiesParameter.ActualValue;169 if (acceptedQualities[binIndex].Count == 0) return true;170 bool maximization = MaximizationParameter.ActualValue.Value;171 IEnumerable<double> binQualities = acceptedQualities[binIndex].Select(x => x.Value);172 // binQualities are always sorted so that the best is in bin 0173 return maximization ? solutionQuality > binQualities.First() :174 solutionQuality < binQualities.First();175 }190 //private bool NewBestOfBin(double solutionQuality, int binIndex) { 191 // ItemList<ItemList<DoubleValue>> acceptedQualities = AcceptedBinQualitiesParameter.ActualValue; 192 // if (acceptedQualities[binIndex].Count == 0) return true; 193 // bool maximization = MaximizationParameter.ActualValue.Value; 194 // IEnumerable<double> binQualities = acceptedQualities[binIndex].Select(x => x.Value); 195 // // binQualities are always sorted so that the best is in bin 0 196 // return maximization ? solutionQuality > binQualities.First() : 197 // solutionQuality < binQualities.First(); 198 //} 176 199 177 200 private bool IsNotFull(int binIndex) {
Note: See TracChangeset
for help on using the changeset viewer.