Changeset 8664 for trunk/sources/HeuristicLab.Problems.DataAnalysis
- Timestamp:
- 09/17/12 11:18:40 (12 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj
r8600 r8664 151 151 <Compile Include="Interfaces\Regression\IRegressionEnsembleSolution.cs" /> 152 152 <Compile Include="Implementation\Regression\RegressionSolutionBase.cs" /> 153 <Compile Include="OnlineCalculators\OnlineBoundedMeanSquaredErrorCalculator.cs" /> 153 154 <Compile Include="OnlineCalculators\HoeffdingsDependenceCalculator.cs" /> 154 155 <Compile Include="OnlineCalculators\OnlineMaxAbsoluteErrorCalculator.cs" /> … … 280 281 --> 281 282 <PropertyGroup> 282 <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir)283 <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir) 283 284 set ProjectDir=$(ProjectDir) 284 285 set SolutionDir=$(SolutionDir) … … 287 288 call PreBuildEvent.cmd 288 289 </PreBuildEvent> 289 <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">290 <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' "> 290 291 export ProjectDir=$(ProjectDir) 291 292 export SolutionDir=$(SolutionDir) -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineBoundedMeanSquaredErrorCalculator.cs
r8650 r8664 24 24 25 25 namespace HeuristicLab.Problems.DataAnalysis { 26 public class Online MeanSquaredErrorCalculator : IOnlineCalculator {26 public class OnlineBoundedMeanSquaredErrorCalculator : IOnlineCalculator { 27 27 28 private double sse;28 private double errorSum; 29 29 private int n; 30 public double MeanSquaredError {30 public double BoundedMeanSquaredError { 31 31 get { 32 return n > 0 ? sse/ n : 0.0;32 return n > 0 ? errorSum / n : 0.0; 33 33 } 34 34 } 35 35 36 public OnlineMeanSquaredErrorCalculator() { 36 public double LowerBound { get; private set; } 37 public double UpperBound { get; private set; } 38 39 40 public OnlineBoundedMeanSquaredErrorCalculator(double lowerBound, double upperbound) { 41 LowerBound = lowerBound; 42 UpperBound = upperbound; 37 43 Reset(); 38 44 } … … 44 50 } 45 51 public double Value { 46 get { return MeanSquaredError; }52 get { return BoundedMeanSquaredError; } 47 53 } 48 54 public void Reset() { 49 55 n = 0; 50 sse= 0.0;56 errorSum = 0.0; 51 57 errorState = OnlineCalculatorError.InsufficientElementsAdded; 52 58 } … … 58 64 } else { 59 65 double error = estimated - original; 60 sse += error * error; 66 if (estimated < LowerBound || estimated > UpperBound) 67 errorSum += Math.Abs(error); 68 else 69 errorSum += error * error; 61 70 n++; 62 71 errorState = errorState & (~OnlineCalculatorError.InsufficientElementsAdded); // n >= 1 … … 65 74 #endregion 66 75 67 public static double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) {76 public static double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, double lowerBound, double upperBound, out OnlineCalculatorError errorState) { 68 77 IEnumerator<double> originalEnumerator = originalValues.GetEnumerator(); 69 78 IEnumerator<double> estimatedEnumerator = estimatedValues.GetEnumerator(); 70 Online MeanSquaredErrorCalculator mseCalculator = new OnlineMeanSquaredErrorCalculator();79 OnlineBoundedMeanSquaredErrorCalculator boundedMseCalculator = new OnlineBoundedMeanSquaredErrorCalculator(lowerBound, upperBound); 71 80 72 81 // always move forward both enumerators (do not use short-circuit evaluation!) … … 74 83 double original = originalEnumerator.Current; 75 84 double estimated = estimatedEnumerator.Current; 76 mseCalculator.Add(original, estimated);77 if ( mseCalculator.ErrorState != OnlineCalculatorError.None) break;85 boundedMseCalculator.Add(original, estimated); 86 if (boundedMseCalculator.ErrorState != OnlineCalculatorError.None) break; 78 87 } 79 88 80 89 // check if both enumerators are at the end to make sure both enumerations have the same length 81 if ( mseCalculator.ErrorState == OnlineCalculatorError.None &&90 if (boundedMseCalculator.ErrorState == OnlineCalculatorError.None && 82 91 (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext())) { 83 92 throw new ArgumentException("Number of elements in originalValues and estimatedValues enumerations doesn't match."); 84 93 } else { 85 errorState = mseCalculator.ErrorState;86 return mseCalculator.MeanSquaredError;94 errorState = boundedMseCalculator.ErrorState; 95 return boundedMseCalculator.BoundedMeanSquaredError; 87 96 } 88 97 }
Note: See TracChangeset
for help on using the changeset viewer.