Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5246


Ignore:
Timestamp:
01/08/11 13:04:00 (13 years ago)
Author:
gkronber
Message:

Added calculation of length and height of best solution to FixedValidationBestScaledSymbolicRegressionSolutionAnalyzer. #1368

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Analyzers/RegressionSolutionAnalyzer.cs

    r5199 r5246  
    123123    }
    124124
    125     public static void UpdateBestSolutionResults(DataAnalysisSolution bestSolution, DataAnalysisProblemData problemData, ResultCollection results, IntValue CurrentGeneration) {
    126       var solution = bestSolution;
     125    public static void UpdateBestSolutionResults(DataAnalysisSolution solution, DataAnalysisProblemData problemData, ResultCollection results, IntValue generation) {
    127126      #region update R2,MSE, Rel Error
    128127      IEnumerable<double> trainingValues = problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable.Value, problemData.TrainingIndizes);
     
    170169        results[BestSolutionTrainingRelativeError].Value = new DoubleValue(trainingRelError);
    171170        results[BestSolutionTestRelativeError].Value = new DoubleValue(testRelError);
    172         if (CurrentGeneration != null) // this check is needed because linear regression solutions do not have a generations parameter
    173           results[BestSolutionGeneration].Value = new IntValue(CurrentGeneration.Value);
     171        if (generation != null) // this check is needed because linear regression solutions do not have a generations parameter
     172          results[BestSolutionGeneration].Value = new IntValue(generation.Value);
    174173      } else {
    175174        results.Add(new Result(BestSolutionResultName, solution));
     
    180179        results.Add(new Result(BestSolutionTrainingRelativeError, new DoubleValue(trainingRelError)));
    181180        results.Add(new Result(BestSolutionTestRelativeError, new DoubleValue(testRelError)));
    182         if (CurrentGeneration != null)
    183           results.Add(new Result(BestSolutionGeneration, new IntValue(CurrentGeneration.Value)));
     181        if (generation != null)
     182          results.Add(new Result(BestSolutionGeneration, new IntValue(generation.Value)));
    184183      }
    185184      #endregion
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/BestSymbolicRegressionSolutionAnalyzer.cs

    r4722 r5246  
    110110    }
    111111
    112     public static void UpdateBestSolutionResults(SymbolicRegressionSolution bestSolution, DataAnalysisProblemData problemData, ResultCollection results, IntValue currentGeneration, DataTable variableFrequencies) {
    113       RegressionSolutionAnalyzer.UpdateBestSolutionResults(bestSolution, problemData, results, currentGeneration);
    114       UpdateSymbolicRegressionBestSolutionResults(bestSolution, problemData, results, variableFrequencies);
     112    public static void UpdateBestSolutionResults(SymbolicRegressionSolution solution, DataAnalysisProblemData problemData, ResultCollection results, IntValue currentGeneration, DataTable variableFrequencies) {
     113      RegressionSolutionAnalyzer.UpdateBestSolutionResults(solution, problemData, results, currentGeneration);
     114      UpdateSymbolicRegressionBestSolutionResults(solution, problemData, results, variableFrequencies);
    115115    }
    116116
    117     private static void UpdateSymbolicRegressionBestSolutionResults(SymbolicRegressionSolution bestSolution, DataAnalysisProblemData problemData, ResultCollection results, DataTable variableFrequencies) {
     117    private static void UpdateSymbolicRegressionBestSolutionResults(SymbolicRegressionSolution solution, DataAnalysisProblemData problemData, ResultCollection results, DataTable variableFrequencies) {
    118118      if (results.ContainsKey(BestSolutionInputvariableCountResultName)) {
    119         results[BestSolutionInputvariableCountResultName].Value = new IntValue(bestSolution.Model.InputVariables.Count());
     119        results[BestSolutionInputvariableCountResultName].Value = new IntValue(solution.Model.InputVariables.Count());
    120120        results[VariableImpactsResultName].Value = CalculateVariableImpacts(variableFrequencies);
    121121      } else {
    122         results.Add(new Result(BestSolutionInputvariableCountResultName, new IntValue(bestSolution.Model.InputVariables.Count())));
     122        results.Add(new Result(BestSolutionInputvariableCountResultName, new IntValue(solution.Model.InputVariables.Count())));
    123123        results.Add(new Result(VariableImpactsResultName, CalculateVariableImpacts(variableFrequencies)));
    124124      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/FixedValidationBestScaledSymbolicRegressionSolutionAnalyzer.cs

    r5198 r5246  
    4141  public sealed class FixedValidationBestScaledSymbolicRegressionSolutionAnalyzer : SymbolicRegressionValidationAnalyzer, ISymbolicRegressionAnalyzer {
    4242    private const string MaximizationParameterName = "Maximization";
     43    private const string CalculateSolutionComplexityParameterName = "CalculateSolutionComplexity";
    4344    private const string BestSolutionParameterName = "Best solution (validation)";
    4445    private const string BestSolutionQualityParameterName = "Best solution quality (validation)";
     46    private const string BestSolutionLengthParameterName = "Best solution length (validation)";
     47    private const string BestSolutionHeightParameterName = "Best solution height (validiation)";
    4548    private const string CurrentBestValidationQualityParameterName = "Current best validation quality";
    4649    private const string BestSolutionQualityValuesParameterName = "Validation Quality";
     
    5457      get { return (ILookupParameter<BoolValue>)Parameters[MaximizationParameterName]; }
    5558    }
     59    public IValueParameter<BoolValue> CalculateSolutionComplexityParameter {
     60      get { return (IValueParameter<BoolValue>)Parameters[CalculateSolutionComplexityParameterName]; }
     61    }
    5662    public ILookupParameter<SymbolicRegressionSolution> BestSolutionParameter {
    5763      get { return (ILookupParameter<SymbolicRegressionSolution>)Parameters[BestSolutionParameterName]; }
     
    6268    public ILookupParameter<DoubleValue> BestSolutionQualityParameter {
    6369      get { return (ILookupParameter<DoubleValue>)Parameters[BestSolutionQualityParameterName]; }
     70    }
     71    public ILookupParameter<IntValue> BestSolutionLengthParameter {
     72      get { return (ILookupParameter<IntValue>)Parameters[BestSolutionLengthParameterName]; }
     73    }
     74    public ILookupParameter<IntValue> BestSolutionHeightParameter {
     75      get { return (ILookupParameter<IntValue>)Parameters[BestSolutionHeightParameterName]; }
    6476    }
    6577    public ILookupParameter<ResultCollection> ResultsParameter {
     
    7890      get { return MaximizationParameter.ActualValue; }
    7991    }
     92    public BoolValue CalculateSolutionComplexity {
     93      get { return CalculateSolutionComplexityParameter.Value; }
     94      set { CalculateSolutionComplexityParameter.Value = value; }
     95    }
    8096    public ResultCollection Results {
    8197      get { return ResultsParameter.ActualValue; }
     
    89105    public DoubleValue BestSolutionQuality {
    90106      get { return BestSolutionQualityParameter.ActualValue; }
     107    }
     108    public IntValue BestSolutionLength {
     109      get { return BestSolutionLengthParameter.ActualValue; }
     110      set { BestSolutionLengthParameter.ActualValue = value; }
     111    }
     112    public IntValue BestSolutionHeight {
     113      get { return BestSolutionHeightParameter.ActualValue; }
     114      set { BestSolutionHeightParameter.ActualValue = value; }
    91115    }
    92116
     
    99123      : base() {
    100124      Parameters.Add(new LookupParameter<BoolValue>(MaximizationParameterName, "The direction of optimization."));
     125      Parameters.Add(new ValueParameter<BoolValue>(CalculateSolutionComplexityParameterName, "Determines if the length and height of the validation best solution should be calculated.", new BoolValue(false)));
    101126      Parameters.Add(new LookupParameter<SymbolicRegressionSolution>(BestSolutionParameterName, "The best symbolic regression solution."));
    102127      Parameters.Add(new LookupParameter<IntValue>(GenerationsParameterName, "The number of generations calculated so far."));
    103128      Parameters.Add(new LookupParameter<DoubleValue>(BestSolutionQualityParameterName, "The quality of the best symbolic regression solution."));
     129      Parameters.Add(new LookupParameter<IntValue>(BestSolutionLengthParameterName, "The length of the best symbolic regression solution."));
     130      Parameters.Add(new LookupParameter<IntValue>(BestSolutionHeightParameterName, "The height of the best symbolic regression solution."));
    104131      Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The result collection where the best symbolic regression solution should be stored."));
    105132      Parameters.Add(new LookupParameter<DoubleValue>(BestKnownQualityParameterName, "The best known (validation) quality achieved on the data set."));
     
    120147        Parameters.Add(new LookupParameter<BoolValue>(MaximizationParameterName, "The direction of optimization."));
    121148      }
     149      if (!Parameters.ContainsKey(CalculateSolutionComplexityParameterName)) {
     150        Parameters.Add(new ValueParameter<BoolValue>(CalculateSolutionComplexityParameterName, "Determines if the length and height of the validation best solution should be calculated.", new BoolValue(false)));
     151      }
     152      if (!Parameters.ContainsKey(BestSolutionLengthParameterName)) {
     153        Parameters.Add(new LookupParameter<IntValue>(BestSolutionLengthParameterName, "The length of the best symbolic regression solution."));
     154      }
     155      if (!Parameters.ContainsKey(BestSolutionHeightParameterName)) {
     156        Parameters.Add(new LookupParameter<IntValue>(BestSolutionHeightParameterName, "The height of the best symbolic regression solution."));
     157      }
    122158      #endregion
    123159    }
    124    
     160
    125161    protected override void Analyze(SymbolicExpressionTree[] trees, double[] validationQuality) {
    126162      double bestQuality = Maximization.Value ? double.NegativeInfinity : double.PositiveInfinity;
    127163      SymbolicExpressionTree bestTree = null;
    128164
    129       for(int i=0;i<trees.Length;i++) {
     165      for (int i = 0; i < trees.Length; i++) {
    130166        double quality = validationQuality[i];
    131167        if ((Maximization.Value && quality > bestQuality) ||
     
    164200        BestSolutionQualityParameter.ActualValue = new DoubleValue(bestQuality);
    165201
     202        if (CalculateSolutionComplexity.Value) {
     203          BestSolutionLength = new IntValue(solution.Model.SymbolicExpressionTree.Size);
     204          BestSolutionHeight = new IntValue(solution.Model.SymbolicExpressionTree.Height);
     205          if (!Results.ContainsKey(BestSolutionLengthParameterName)) {
     206            Results.Add(new Result(BestSolutionLengthParameterName, "Length of the best solution on the validation set", new IntValue()));
     207            Results.Add(new Result(BestSolutionHeightParameterName, "Height of the best solution on the validation set", new IntValue()));
     208          }
     209          Results[BestSolutionLengthParameterName].Value = BestSolutionLength;
     210          Results[BestSolutionHeightParameterName].Value = BestSolutionHeight;
     211        }
     212
    166213        BestSymbolicRegressionSolutionAnalyzer.UpdateBestSolutionResults(solution, ProblemData, Results, Generations, VariableFrequencies);
    167214      }
    168 
    169215
    170216      if (!Results.ContainsKey(BestSolutionQualityValuesParameterName)) {
Note: See TracChangeset for help on using the changeset viewer.