Changeset 4194
- Timestamp:
- 08/11/10 13:00:53 (14 years ago)
- Location:
- branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression
- Files:
-
- 8 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression/3.3/HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression-3.3.csproj
r4065 r4194 114 114 <SubType>Code</SubType> 115 115 </Compile> 116 <Compile Include="Symbolic\Evaluators\MultiObjectiveSymbolicVectorRegressionEvaluator.cs" /> 117 <Compile Include="Symbolic\Evaluators\SingleObjectiveSymbolicVectorRegressionEvaluator.cs" /> 118 <Compile Include="Symbolic\Evaluators\PartialDerivativeEvaluator.cs" /> 119 <Compile Include="Symbolic\Evaluators\PartialSymbolicDifferential.cs" /> 116 120 <Compile Include="Symbolic\Evaluators\SymbolicRegressionNormalizedMeanSquaredErrorEvaluator.cs"> 117 121 <SubType>Code</SubType> -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression/3.3/Symbolic/Analyzer/ValidationBestScaledSymbolicVectorRegressionSolutionAnalyzer.cs
r4112 r4194 32 32 using HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression.Symbolic.Evaluators; 33 33 using HeuristicLab.Problems.DataAnalysis.Symbolic; 34 using HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression.Symbolic.Interfaces; 34 35 35 36 namespace HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression.Symbolic.Analyzers { … … 44 45 private const string SymbolicExpressionTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter"; 45 46 private const string ProblemDataParameterName = "ProblemData"; 46 private const string TrainingSamplesStartParameterName = "TrainingSamplesStart";47 private const string TrainingSamplesEndParameterName = "TrainingSamplesEnd";48 47 private const string ValidationSamplesStartParameterName = "ValidationSamplesStart"; 49 48 private const string ValidationSamplesEndParameterName = "ValidationSamplesEnd"; 50 private const string TestSamplesStartParameterName = "TestSamplesStart"; 51 private const string TestSamplesEndParameterName = "TestSamplesEnd"; 52 private const string QualityParameterName = "Quality"; 53 private const string ScaledQualityParameterName = "ScaledQuality"; 49 private const string EvaluatorParameterName = "Evaluator"; 50 private const string MaximizationParameterName = "Maximization"; 54 51 private const string UpperEstimationLimitParameterName = "UpperEstimationLimit"; 55 52 private const string LowerEstimationLimitParameterName = "LowerEstimationLimit"; … … 85 82 get { return (IValueLookupParameter<IntValue>)Parameters[ValidationSamplesEndParameterName]; } 86 83 } 84 public IValueLookupParameter<ISingleObjectiveSymbolicVectorRegressionEvaluator> EvaluatorParameter { 85 get { return (IValueLookupParameter<ISingleObjectiveSymbolicVectorRegressionEvaluator>)Parameters[EvaluatorParameterName]; } 86 } 87 public IValueLookupParameter<BoolValue> MaximizationParameter { 88 get { return (IValueLookupParameter<BoolValue>)Parameters[MaximizationParameterName]; } 89 } 87 90 public IValueLookupParameter<DoubleArray> UpperEstimationLimitParameter { 88 91 get { return (IValueLookupParameter<DoubleArray>)Parameters[UpperEstimationLimitParameterName]; } … … 119 122 public DoubleArray UpperEstimationLimit { 120 123 get { return UpperEstimationLimitParameter.ActualValue; } 124 } 125 public ISingleObjectiveSymbolicVectorRegressionEvaluator Evaluator { 126 get { return EvaluatorParameter.ActualValue; } 127 } 128 public BoolValue Maximization { 129 get { return MaximizationParameter.ActualValue; } 130 } 131 public DoubleValue BestSolutionQuality { 132 get { return BestSolutionQualityParameter.ActualValue; } 121 133 } 122 134 #endregion … … 131 143 Parameters.Add(new ValueLookupParameter<IntValue>(ValidationSamplesStartParameterName, "The first index of the validation partition of the data set.")); 132 144 Parameters.Add(new ValueLookupParameter<IntValue>(ValidationSamplesEndParameterName, "The last index of the validation partition of the data set.")); 145 Parameters.Add(new ValueLookupParameter<ISingleObjectiveSymbolicVectorRegressionEvaluator>(EvaluatorParameterName, "The evaluator which should be used to evaluate the solution on the validation set.")); 146 Parameters.Add(new ValueLookupParameter<BoolValue>(MaximizationParameterName, "The direction of optimization.")); 133 147 Parameters.Add(new ValueLookupParameter<DoubleArray>(UpperEstimationLimitParameterName, "The upper estimation limit that was set for the evaluation of the symbolic expression trees.")); 134 148 Parameters.Add(new ValueLookupParameter<DoubleArray>(LowerEstimationLimitParameterName, "The lower estimation limit that was set for the evaluation of the symbolic expression trees.")); … … 156 170 IEnumerable<int> rows = Enumerable.Range(validationStart, validationEnd - validationStart); 157 171 SymbolicExpressionTree bestTree = null; 158 double best ValidationError =double.PositiveInfinity;172 double bestQuality = Maximization.Value ? double.NegativeInfinity : double.PositiveInfinity; 159 173 foreach (var tree in scaledTrees) { 160 // calculate error on validation set 161 double validationMse = SymbolicVectorRegressionNormalizedMseEvaluator.Calculate(tree, interpreter, ProblemData, selectedTargetVariables, rows, LowerEstimationLimit, UpperEstimationLimit); 162 if (bestValidationError > validationMse) { 163 bestValidationError = validationMse; 174 // calculate quality on validation set 175 double quality = Evaluator.Evaluate(tree, interpreter, ProblemData, selectedTargetVariables, rows, LowerEstimationLimit, UpperEstimationLimit); 176 if ((Maximization.Value && quality > bestQuality) || 177 (!Maximization.Value && quality < bestQuality)) { 178 bestQuality = quality; 164 179 bestTree = tree; 165 180 } 166 181 } 167 if (BestSolutionQualityParameter.ActualValue == null || BestSolutionQualityParameter.ActualValue.Value > bestValidationError) { 182 bool newBest = 183 BestSolutionQualityParameter.ActualValue == null || 184 (Maximization.Value && bestQuality > BestSolutionQuality.Value) || 185 (!Maximization.Value && bestQuality < BestSolutionQuality.Value); 186 if (newBest) { 168 187 var bestSolution = bestTree; 169 188 … … 172 191 173 192 BestSolutionParameter.ActualValue = bestSolution; 174 BestSolutionQualityParameter.ActualValue = new DoubleValue(best ValidationError);193 BestSolutionQualityParameter.ActualValue = new DoubleValue(bestQuality); 175 194 } 176 195 … … 185 204 results[BestSolutionParameterName].Value = BestSolutionParameter.ActualValue; 186 205 results[BestSolutionQualityParameterName].Value = new DoubleValue(BestSolutionQualityParameter.ActualValue.Value); 187 results[CurrentBestValidationQualityParameterName].Value = new DoubleValue(best ValidationError);206 results[CurrentBestValidationQualityParameterName].Value = new DoubleValue(bestQuality); 188 207 189 208 DataTable validationValues = (DataTable)results[BestSolutionQualityValuesParameterName].Value; 190 209 AddValue(validationValues, BestSolutionQualityParameter.ActualValue.Value, BestSolutionQualityParameterName, BestSolutionQualityParameterName); 191 AddValue(validationValues, best ValidationError, CurrentBestValidationQualityParameterName, CurrentBestValidationQualityParameterName);210 AddValue(validationValues, bestQuality, CurrentBestValidationQualityParameterName, CurrentBestValidationQualityParameterName); 192 211 193 212 return base.Apply(); -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression/3.3/Symbolic/Evaluators/SymbolicVectorRegressionEvaluator.cs
r4068 r4194 105 105 #endregion 106 106 107 public SymbolicVectorRegressionEvaluator(bool deserializing) : base(deserializing) { } 107 108 public SymbolicVectorRegressionEvaluator() 108 109 : base() { … … 118 119 } 119 120 120 public override IOperation Apply() { 121 var interpreter = SymbolicExpressionTreeInterpreter; 122 var tree = SymbolicExpressionTree; 123 var problemData = MultiVariateDataAnalysisProblemData; 124 125 IEnumerable<string> selectedTargetVariables = 126 problemData.TargetVariables.CheckedItems 127 .Select(x => x.Value.Value); 128 129 // check if there is a vector component for each target variable 130 if (selectedTargetVariables.Count() != tree.Root.SubTrees[0].SubTrees.Count) 131 throw new ArgumentException("The dimension of the output-vector of the tree doesn't match the number of selected target variables."); 132 int start = SamplesStart.Value; 133 int end = SamplesEnd.Value; 134 135 IEnumerable<int> rows = GenerateRowsToEvaluate((uint)Random.Next(), RelativeNumberOfEvaluatedSamples.Value, start, end); 136 137 Evaluate(tree, interpreter, problemData, selectedTargetVariables, rows, LowerEstimationLimit, UpperEstimationLimit); 138 139 return base.Apply(); 140 } 141 142 public abstract void Evaluate(SymbolicExpressionTree tree, ISymbolicExpressionTreeInterpreter interpreter, MultiVariateDataAnalysisProblemData problemData, IEnumerable<string> targetVariables, IEnumerable<int> rows, DoubleArray lowerEstimationBound, DoubleArray upperEstimationBound); 143 144 private static IEnumerable<int> GenerateRowsToEvaluate(uint seed, double relativeAmount, int start, int end) { 121 public static IEnumerable<int> GenerateRowsToEvaluate(uint seed, double relativeAmount, int start, int end) { 145 122 if (end < start) throw new ArgumentException("Start value is larger than end value."); 146 123 int count = (int)((end - start) * relativeAmount); -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression/3.3/Symbolic/Evaluators/SymbolicVectorRegressionNormalizedMseEvaluator.cs
r4112 r4194 34 34 [Item("SymbolicVectorRegressionNormalizedMseEvaluator", "Represents an operator that calculates the sum of the normalized mean squared error over all components.")] 35 35 [StorableClass] 36 public class SymbolicVectorRegressionNormalizedMseEvaluator : SymbolicVectorRegressionEvaluator, ISingleObjectiveSymbolicVectorRegressionEvaluator { 37 private const string QualityParameterName = "ScaledNormalizedMeanSquaredError"; 36 public class SymbolicVectorRegressionNormalizedMseEvaluator : SingleObjectiveSymbolicVectorRegressionEvaluator { 38 37 39 #region parameter properties 40 public ILookupParameter<DoubleValue> QualityParameter { 41 get { return (ILookupParameter<DoubleValue>)Parameters[QualityParameterName]; } 38 39 public SymbolicVectorRegressionNormalizedMseEvaluator(bool deserializing) : base(deserializing) { } 40 public SymbolicVectorRegressionNormalizedMseEvaluator() 41 : base() { 42 42 } 43 43 44 #endregion 45 46 public SymbolicVectorRegressionNormalizedMseEvaluator() 47 : base() { 48 Parameters.Add(new LookupParameter<DoubleValue>(QualityParameterName, "The sum of the normalized mean squared error over all components of the symbolic vector regression solution encoded as a symbolic expression tree.")); 49 } 50 51 public override void Evaluate(SymbolicExpressionTree tree, ISymbolicExpressionTreeInterpreter interpreter, MultiVariateDataAnalysisProblemData problemData, IEnumerable<string> targetVariables, IEnumerable<int> rows, DoubleArray lowerEstimationBound, DoubleArray upperEstimationBound) { 52 double nmse = Calculate(tree, interpreter, problemData, targetVariables, rows, lowerEstimationBound, upperEstimationBound); 53 QualityParameter.ActualValue = new DoubleValue(nmse); 44 public override double Evaluate(SymbolicExpressionTree tree, ISymbolicExpressionTreeInterpreter interpreter, MultiVariateDataAnalysisProblemData problemData, IEnumerable<string> targetVariables, IEnumerable<int> rows, DoubleArray lowerEstimationBound, DoubleArray upperEstimationBound) { 45 return Calculate(tree, interpreter, problemData, targetVariables, rows, lowerEstimationBound, upperEstimationBound); 54 46 } 55 47 -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression/3.3/Symbolic/Evaluators/SymbolicVectorRegressionScaledMseEvaluator.cs
r4112 r4194 34 34 [Item("SymbolicVectorRegressionScaledMseEvaluator", "Represents an operator that calculates the scaled mean squared error for all components independently.")] 35 35 [StorableClass] 36 public class SymbolicVectorRegressionScaledMseEvaluator : SymbolicVectorRegressionEvaluator, IMultiObjectiveSymbolicVectorRegressionEvaluator { 37 private const string QualitiesParameterName = "ScaledMeanSquaredErrors"; 36 public class SymbolicVectorRegressionScaledMseEvaluator : MultiObjectiveSymbolicVectorRegressionEvaluator { 38 37 private const string AlphaParameterName = "Alpha"; 39 38 private const string BetaParameterName = "Beta"; 40 39 41 40 #region parameter properties 42 public ILookupParameter<DoubleArray> QualitiesParameter {43 get { return (ILookupParameter<DoubleArray>)Parameters[QualitiesParameterName]; }44 }45 41 public ILookupParameter<DoubleArray> AlphaParameter { 46 42 get { return (ILookupParameter<DoubleArray>)Parameters[AlphaParameterName]; } … … 54 50 public SymbolicVectorRegressionScaledMseEvaluator() 55 51 : base() { 56 Parameters.Add(new LookupParameter<DoubleArray>(QualitiesParameterName, "The mean squared errors for each component of the symbolic vector regression solution encoded as a symbolic expression tree."));57 52 Parameters.Add(new LookupParameter<DoubleArray>(AlphaParameterName, "The alpha parameter for linear scaling.")); 58 53 Parameters.Add(new LookupParameter<DoubleArray>(BetaParameterName, "The beta parameter for linear scaling.")); 59 54 } 60 55 61 public override voidEvaluate(SymbolicExpressionTree tree, ISymbolicExpressionTreeInterpreter interpreter, MultiVariateDataAnalysisProblemData problemData, IEnumerable<string> targetVariables, IEnumerable<int> rows, DoubleArray lowerEstimationBound, DoubleArray upperEstimationBound) {56 public override double[] Evaluate(SymbolicExpressionTree tree, ISymbolicExpressionTreeInterpreter interpreter, MultiVariateDataAnalysisProblemData problemData, IEnumerable<string> targetVariables, IEnumerable<int> rows, DoubleArray lowerEstimationBound, DoubleArray upperEstimationBound) { 62 57 List<string> targetVariablesList = targetVariables.ToList(); 63 DoubleArray qualities = new DoubleArray(targetVariables.Count());58 double[] qualities = new double[targetVariables.Count()]; 64 59 DoubleArray alpha = new DoubleArray(qualities.Length); 65 60 DoubleArray beta = new DoubleArray(qualities.Length); … … 87 82 } 88 83 89 QualitiesParameter.ActualValue = qualities;90 84 AlphaParameter.ActualValue = alpha; 91 85 BetaParameter.ActualValue = beta; 86 return qualities; 92 87 } 93 88 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression/3.3/Symbolic/Evaluators/SymbolicVectorRegressionScaledNormalizedMseEvaluator.cs
r4112 r4194 34 34 [Item("SymbolicVectorRegressionScaledNormalizedMseEvaluator", "Represents an operator that calculates the sum of the normalized mean squared error over all components.")] 35 35 [StorableClass] 36 public class SymbolicVectorRegressionScaledNormalizedMseEvaluator : SymbolicVectorRegressionEvaluator, ISingleObjectiveSymbolicVectorRegressionEvaluator { 37 private const string QualityParameterName = "ScaledNormalizedMeanSquaredError"; 36 public class SymbolicVectorRegressionScaledNormalizedMseEvaluator : SingleObjectiveSymbolicVectorRegressionEvaluator { 38 37 private const string AlphaParameterName = "Alpha"; 39 38 private const string BetaParameterName = "Beta"; 40 39 41 40 #region parameter properties 42 public ILookupParameter<DoubleValue> QualityParameter {43 get { return (ILookupParameter<DoubleValue>)Parameters[QualityParameterName]; }44 }45 41 public ILookupParameter<DoubleArray> AlphaParameter { 46 42 get { return (ILookupParameter<DoubleArray>)Parameters[AlphaParameterName]; } … … 54 50 public SymbolicVectorRegressionScaledNormalizedMseEvaluator() 55 51 : base() { 56 Parameters.Add(new LookupParameter<DoubleValue>(QualityParameterName, "The sum of the normalized mean squared error over all components of the symbolic vector regression solution encoded as a symbolic expression tree."));57 52 Parameters.Add(new LookupParameter<DoubleArray>(AlphaParameterName, "The alpha parameter for linear scaling.")); 58 53 Parameters.Add(new LookupParameter<DoubleArray>(BetaParameterName, "The beta parameter for linear scaling.")); 59 54 } 60 55 61 public override voidEvaluate(SymbolicExpressionTree tree, ISymbolicExpressionTreeInterpreter interpreter, MultiVariateDataAnalysisProblemData problemData, IEnumerable<string> targetVariables, IEnumerable<int> rows, DoubleArray lowerEstimationBound, DoubleArray upperEstimationBound) {56 public override double Evaluate(SymbolicExpressionTree tree, ISymbolicExpressionTreeInterpreter interpreter, MultiVariateDataAnalysisProblemData problemData, IEnumerable<string> targetVariables, IEnumerable<int> rows, DoubleArray lowerEstimationBound, DoubleArray upperEstimationBound) { 62 57 List<string> targetVariablesList = targetVariables.ToList(); 63 58 double nmseSum = 0.0; … … 87 82 AlphaParameter.ActualValue = alpha; 88 83 BetaParameter.ActualValue = beta; 89 QualityParameter.ActualValue = new DoubleValue(nmseSum);84 return nmseSum; 90 85 } 91 86 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression/3.3/Symbolic/Interfaces/IMultiObjectiveSymbolicVectorRegressionEvaluator.cs
r4068 r4194 25 25 using HeuristicLab.Optimization; 26 26 using HeuristicLab.Problems.DataAnalysis.Symbolic; 27 using System.Collections.Generic; 27 28 28 29 namespace HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression.Symbolic.Interfaces { … … 32 33 ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter { get; } 33 34 ILookupParameter<ISymbolicExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter { get; } 35 36 double[] Evaluate(SymbolicExpressionTree tree, ISymbolicExpressionTreeInterpreter interpreter, MultiVariateDataAnalysisProblemData problemData, IEnumerable<string> targetVariables, IEnumerable<int> rows, DoubleArray lowerEstimationBound, DoubleArray upperEstimationBound); 37 34 38 } 35 39 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression/3.3/Symbolic/Interfaces/ISingleObjectiveSymbolicVectorRegressionEvaluator.cs
r4068 r4194 25 25 using HeuristicLab.Optimization; 26 26 using HeuristicLab.Problems.DataAnalysis.Symbolic; 27 using System.Collections.Generic; 27 28 28 29 namespace HeuristicLab.Problems.DataAnalysis.MultiVariate.Regression.Symbolic.Interfaces { … … 32 33 ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter { get; } 33 34 ILookupParameter<ISymbolicExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter { get; } 35 36 double Evaluate(SymbolicExpressionTree tree, ISymbolicExpressionTreeInterpreter interpreter, MultiVariateDataAnalysisProblemData problemData, IEnumerable<string> targetVariables, IEnumerable<int> rows, DoubleArray lowerEstimationBound, DoubleArray upperEstimationBound); 34 37 } 35 38 }
Note: See TracChangeset
for help on using the changeset viewer.