- Timestamp:
- 04/11/12 07:37:02 (13 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveValidationAnalyzer.cs
r7259 r7721 45 45 private const string ValidationPartitionParameterName = "ValidationPartition"; 46 46 private const string RelativeNumberOfEvaluatedSamplesParameterName = "RelativeNumberOfEvaluatedSamples"; 47 private const string PercentageOfBestSolutionsParameterName = "PercentageOfBestSolutions"; 47 48 48 49 #region parameter properties … … 65 66 get { return (IValueLookupParameter<PercentValue>)Parameters[RelativeNumberOfEvaluatedSamplesParameterName]; } 66 67 } 68 public IValueLookupParameter<PercentValue> PercentageOfBestSolutionsParameter { 69 get { return (IValueLookupParameter<PercentValue>)Parameters[PercentageOfBestSolutionsParameterName]; } 70 } 67 71 #endregion 68 72 … … 80 84 Parameters.Add(new ValueLookupParameter<IntRange>(ValidationPartitionParameterName, "Thes validation partition.")); 81 85 Parameters.Add(new ValueLookupParameter<PercentValue>(RelativeNumberOfEvaluatedSamplesParameterName, "The relative number of samples of the dataset partition, which should be randomly chosen for evaluation between the start and end index.")); 86 Parameters.Add(new ValueLookupParameter<PercentValue>(PercentageOfBestSolutionsParameterName, 87 "The percentage of the top solutions which should be analyzed.", new PercentValue(0.1))); 88 } 89 90 [StorableHook(HookType.AfterDeserialization)] 91 private void AfterDeserialization() { 92 if (!Parameters.ContainsKey(PercentageOfBestSolutionsParameterName)) 93 Parameters.Add(new ValueLookupParameter<PercentValue>(PercentageOfBestSolutionsParameterName, 94 "The percentage of the top solutions which should be analyzed.", new PercentValue(1))); 82 95 } 83 96 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveValidationBestSolutionAnalyzer.cs
r7259 r7721 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 72 73 73 74 public override IOperation Apply() { 74 #region find best tree75 double bestQuality = Maximization.Value ? double.NegativeInfinity : double.PositiveInfinity;76 ISymbolicExpressionTree bestTree = null;77 ISymbolicExpressionTree[] tree = SymbolicExpressionTree.ToArray();78 var evaluator = EvaluatorParameter.ActualValue;79 var problemData = ProblemDataParameter.ActualValue;80 75 IEnumerable<int> rows = GenerateRowsToEvaluate(); 81 76 if (!rows.Any()) return base.Apply(); 82 77 78 #region find best tree 79 var evaluator = EvaluatorParameter.ActualValue; 80 var problemData = ProblemDataParameter.ActualValue; 81 double bestValidationQuality = Maximization.Value ? double.NegativeInfinity : double.PositiveInfinity; 82 ISymbolicExpressionTree bestTree = null; 83 ISymbolicExpressionTree[] tree = SymbolicExpressionTree.ToArray(); 84 85 // sort is ascending and we take the first n% => order so that best solutions are smallest 86 // sort order is determined by maximization parameter 87 double[] trainingQuality; 88 if (Maximization.Value) { 89 // largest values must be sorted first 90 trainingQuality = Quality.Select(x => -x.Value).ToArray(); 91 } else { 92 // smallest values must be sorted first 93 trainingQuality = Quality.Select(x => x.Value).ToArray(); 94 } 95 96 // sort trees by training qualities 97 Array.Sort(trainingQuality, tree); 98 99 // number of best training solutions to validate (at least 1) 100 int topN = (int)Math.Max(tree.Length * PercentageOfBestSolutionsParameter.ActualValue.Value, 1); 101 83 102 IExecutionContext childContext = (IExecutionContext)ExecutionContext.CreateChildOperation(evaluator); 103 // evaluate best n training trees on validiation set 84 104 var quality = tree 105 .Take(topN) 85 106 .AsParallel() 86 107 .Select(t => evaluator.Evaluate(childContext, t, problemData, rows)) 87 108 .ToArray(); 88 109 89 for (int i = 0; i < tree.Length; i++) {90 if (IsBetter(quality[i], best Quality, Maximization.Value)) {91 best Quality = quality[i];110 for (int i = 0; i < quality.Length; i++) { 111 if (IsBetter(quality[i], bestValidationQuality, Maximization.Value)) { 112 bestValidationQuality = quality[i]; 92 113 bestTree = tree[i]; 93 114 } … … 97 118 var results = ResultCollection; 98 119 if (ValidationBestSolutionQuality == null || 99 IsBetter(best Quality, ValidationBestSolutionQuality.Value, Maximization.Value)) {100 ValidationBestSolution = CreateSolution(bestTree, best Quality);101 ValidationBestSolutionQuality = new DoubleValue(best Quality);120 IsBetter(bestValidationQuality, ValidationBestSolutionQuality.Value, Maximization.Value)) { 121 ValidationBestSolution = CreateSolution(bestTree, bestValidationQuality); 122 ValidationBestSolutionQuality = new DoubleValue(bestValidationQuality); 102 123 103 124 if (!results.ContainsKey(ValidationBestSolutionParameter.Name)) {
Note: See TracChangeset
for help on using the changeset viewer.