Changeset 9152


Ignore:
Timestamp:
01/14/13 13:14:22 (8 years ago)
Author:
mkommend
Message:

#2004: Add an update flag to the best solution symbolic data analysis analyzers (single- and multi objective).

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisMultiObjectiveTrainingBestSolutionAnalyzer.cs

    r7259 r9152  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    2627using HeuristicLab.Data;
    2728using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    28 using HeuristicLab.Operators;
    2929using HeuristicLab.Optimization;
    3030using HeuristicLab.Parameters;
    3131using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    32 using System;
    3332
    3433namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    4241    private const string TrainingBestSolutionsParameterName = "Best training solutions";
    4342    private const string TrainingBestSolutionQualitiesParameterName = "Best training solution qualities";
     43    private const string UpdateAlwaysParameterName = "Always update best solutions";
    4444
    4545    #region parameter properties
     
    4949    public ILookupParameter<ItemList<DoubleArray>> TrainingBestSolutionQualitiesParameter {
    5050      get { return (ILookupParameter<ItemList<DoubleArray>>)Parameters[TrainingBestSolutionQualitiesParameterName]; }
     51    }
     52    public IFixedValueParameter<BoolValue> UpdateAlwaysParameter {
     53      get { return (IFixedValueParameter<BoolValue>)Parameters[UpdateAlwaysParameterName]; }
    5154    }
    5255    #endregion
     
    6063      set { TrainingBestSolutionQualitiesParameter.ActualValue = value; }
    6164    }
     65    public BoolValue UpdateAlways {
     66      get { return UpdateAlwaysParameter.Value; }
     67    }
    6268    #endregion
    6369
     
    6975      Parameters.Add(new LookupParameter<ItemList<T>>(TrainingBestSolutionsParameterName, "The training best (Pareto-optimal) symbolic data analysis solutions."));
    7076      Parameters.Add(new LookupParameter<ItemList<DoubleArray>>(TrainingBestSolutionQualitiesParameterName, "The qualities of the training best (Pareto-optimal) solutions."));
     77      Parameters.Add(new FixedValueParameter<BoolValue>(UpdateAlwaysParameterName, "Determines if the best training solutions should always be updated regardless of its quality.", new BoolValue(false)));
     78      UpdateAlwaysParameter.Hidden = true;
     79    }
     80
     81    [StorableHook(HookType.AfterDeserialization)]
     82    private void AfterDeserialization() {
     83      if (!Parameters.ContainsKey(UpdateAlwaysParameterName)) {
     84        Parameters.Add(new FixedValueParameter<BoolValue>(UpdateAlwaysParameterName, "Determines if the best training solutions should always be updated regardless of its quality.", new BoolValue(false)));
     85        UpdateAlwaysParameter.Hidden = true;
     86      }
    7187    }
    7288
     
    8197      }
    8298
    83       IList<double[]> trainingBestQualities = TrainingBestSolutionQualities
    84         .Select(x => x.ToArray())
    85         .ToList();
     99      //if the pareto front of best solutions shall be updated regardless of the quality, the list initialized empty to discard old solutions
     100      IList<double[]> trainingBestQualities;
     101      if (UpdateAlways.Value) {
     102        trainingBestQualities = new List<double[]>();
     103      } else {
     104        trainingBestQualities = TrainingBestSolutionQualities.Select(x => x.ToArray()).ToList();
     105      }
    86106
    87107      #region find best trees
     
    131151      public bool Equals(double[] x, double[] y) {
    132152        if (y.Length != x.Length) throw new ArgumentException();
    133         for (int i = 0; i < x.Length;i++ ) {
     153        for (int i = 0; i < x.Length; i++) {
    134154          if (!x[i].IsAlmost(y[i])) return false;
    135155        }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisMultiObjectiveValidationBestSolutionAnalyzer.cs

    r7259 r9152  
    4444    private const string ValidationBestSolutionsParameterName = "Best validation solutions";
    4545    private const string ValidationBestSolutionQualitiesParameterName = "Best validation solution qualities";
     46    private const string UpdateAlwaysParameterName = "Always update best solutions";
    4647
    4748    #region parameter properties
     
    5152    public ILookupParameter<ItemList<DoubleArray>> ValidationBestSolutionQualitiesParameter {
    5253      get { return (ILookupParameter<ItemList<DoubleArray>>)Parameters[ValidationBestSolutionQualitiesParameterName]; }
     54    }
     55    public IFixedValueParameter<BoolValue> UpdateAlwaysParameter {
     56      get { return (IFixedValueParameter<BoolValue>)Parameters[UpdateAlwaysParameterName]; }
    5357    }
    5458    #endregion
     
    6266      set { ValidationBestSolutionQualitiesParameter.ActualValue = value; }
    6367    }
     68    public BoolValue UpdateAlways {
     69      get { return UpdateAlwaysParameter.Value; }
     70    }
    6471    #endregion
    6572
     
    7178      Parameters.Add(new LookupParameter<ItemList<S>>(ValidationBestSolutionsParameterName, "The validation best (Pareto-optimal) symbolic data analysis solutions."));
    7279      Parameters.Add(new LookupParameter<ItemList<DoubleArray>>(ValidationBestSolutionQualitiesParameterName, "The qualities of the validation best (Pareto-optimal) solutions."));
     80      Parameters.Add(new FixedValueParameter<BoolValue>(UpdateAlwaysParameterName, "Determines if the best validation solutions should always be updated regardless of its quality.", new BoolValue(false)));
     81      UpdateAlwaysParameter.Hidden = true;
     82    }
     83
     84    [StorableHook(HookType.AfterDeserialization)]
     85    private void AfterDeserialization() {
     86      if (!Parameters.ContainsKey(UpdateAlwaysParameterName)) {
     87        Parameters.Add(new FixedValueParameter<BoolValue>(UpdateAlwaysParameterName, "Determines if the best training solutions should always be updated regardless of its quality.", new BoolValue(false)));
     88        UpdateAlwaysParameter.Hidden = true;
     89      }
    7390    }
    7491
     
    86103      }
    87104
    88       IList<double[]> trainingBestQualities = ValidationBestSolutionQualities
    89         .Select(x => x.ToArray())
    90         .ToList();
     105      //if the pareto front of best solutions shall be updated regardless of the quality, the list initialized empty to discard old solutions
     106      IList<double[]> trainingBestQualities;
     107      if (UpdateAlways.Value) {
     108        trainingBestQualities = new List<double[]>();
     109      } else {
     110        trainingBestQualities = ValidationBestSolutionQualities.Select(x => x.ToArray()).ToList();
     111      }
    91112
    92113      #region find best trees
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveTrainingBestSolutionAnalyzer.cs

    r8798 r9152  
    2020#endregion
    2121
    22 using System.Collections.Generic;
    2322using System.Linq;
    2423using HeuristicLab.Common;
     
    2625using HeuristicLab.Data;
    2726using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    28 using HeuristicLab.Operators;
    2927using HeuristicLab.Optimization;
    3028using HeuristicLab.Parameters;
     
    4139    private const string TrainingBestSolutionParameterName = "Best training solution";
    4240    private const string TrainingBestSolutionQualityParameterName = "Best training solution quality";
     41    private const string UpdateAlwaysParameterName = "Always update best solution";
    4342
    4443    #region parameter properties
     
    4847    public ILookupParameter<DoubleValue> TrainingBestSolutionQualityParameter {
    4948      get { return (ILookupParameter<DoubleValue>)Parameters[TrainingBestSolutionQualityParameterName]; }
     49    }
     50    public IFixedValueParameter<BoolValue> UpdateAlwaysParameter {
     51      get { return (IFixedValueParameter<BoolValue>)Parameters[UpdateAlwaysParameterName]; }
    5052    }
    5153    #endregion
     
    5961      set { TrainingBestSolutionQualityParameter.ActualValue = value; }
    6062    }
     63    public BoolValue UpdateAlways {
     64      get { return UpdateAlwaysParameter.Value; }
     65    }
    6166    #endregion
    6267
     
    6873      Parameters.Add(new LookupParameter<T>(TrainingBestSolutionParameterName, "The training best symbolic data analyis solution."));
    6974      Parameters.Add(new LookupParameter<DoubleValue>(TrainingBestSolutionQualityParameterName, "The quality of the training best symbolic data analysis solution."));
     75      Parameters.Add(new FixedValueParameter<BoolValue>(UpdateAlwaysParameterName, "Determines if the best training solution should always be updated regardless of its quality.", new BoolValue(false)));
     76      UpdateAlwaysParameter.Hidden = true;
     77    }
     78
     79    [StorableHook(HookType.AfterDeserialization)]
     80    private void AfterDeserialization() {
     81      if (!Parameters.ContainsKey(UpdateAlwaysParameterName)) {
     82        Parameters.Add(new FixedValueParameter<BoolValue>(UpdateAlwaysParameterName, "Determines if the best training solution should always be updated regardless of its quality.", new BoolValue(false)));
     83        UpdateAlwaysParameter.Hidden = true;
     84      }
    7085    }
    7186
     
    85100
    86101      var results = ResultCollection;
    87       if (bestTree != null && (TrainingBestSolutionQuality == null ||
     102      if (bestTree != null && (UpdateAlways.Value || TrainingBestSolutionQuality == null ||
    88103        IsBetter(bestQuality, TrainingBestSolutionQuality.Value, Maximization.Value))) {
    89104        TrainingBestSolution = CreateSolution(bestTree, bestQuality);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveValidationBestSolutionAnalyzer.cs

    r7721 r9152  
    4343    private const string ValidationBestSolutionParameterName = "Best validation solution";
    4444    private const string ValidationBestSolutionQualityParameterName = "Best validation solution quality";
     45    private const string UpdateAlwaysParameterName = "Always update best solution";
    4546
    4647    #region parameter properties
     
    5051    public ILookupParameter<DoubleValue> ValidationBestSolutionQualityParameter {
    5152      get { return (ILookupParameter<DoubleValue>)Parameters[ValidationBestSolutionQualityParameterName]; }
     53    }
     54    public IFixedValueParameter<BoolValue> UpdateAlwaysParameter {
     55      get { return (IFixedValueParameter<BoolValue>)Parameters[UpdateAlwaysParameterName]; }
    5256    }
    5357    #endregion
     
    6165      set { ValidationBestSolutionQualityParameter.ActualValue = value; }
    6266    }
     67    public BoolValue UpdateAlways {
     68      get { return UpdateAlwaysParameter.Value; }
     69    }
    6370    #endregion
    6471
     
    7077      Parameters.Add(new LookupParameter<S>(ValidationBestSolutionParameterName, "The validation best symbolic data analyis solution."));
    7178      Parameters.Add(new LookupParameter<DoubleValue>(ValidationBestSolutionQualityParameterName, "The quality of the validation best symbolic data analysis solution."));
     79      Parameters.Add(new FixedValueParameter<BoolValue>(UpdateAlwaysParameterName, "Determines if the best validation solution should always be updated regardless of its quality.", new BoolValue(false)));
     80      UpdateAlwaysParameter.Hidden = true;
     81    }
     82
     83    [StorableHook(HookType.AfterDeserialization)]
     84    private void AfterDeserialization() {
     85      if (!Parameters.ContainsKey(UpdateAlwaysParameterName)) {
     86        Parameters.Add(new FixedValueParameter<BoolValue>(UpdateAlwaysParameterName, "Determines if the best training solution should always be updated regardless of its quality.", new BoolValue(false)));
     87        UpdateAlwaysParameter.Hidden = true;
     88      }
    7289    }
    7390
     
    117134
    118135      var results = ResultCollection;
    119       if (ValidationBestSolutionQuality == null ||
     136      if (UpdateAlways.Value || ValidationBestSolutionQuality == null ||
    120137        IsBetter(bestValidationQuality, ValidationBestSolutionQuality.Value, Maximization.Value)) {
    121138        ValidationBestSolution = CreateSolution(bestTree, bestValidationQuality);
Note: See TracChangeset for help on using the changeset viewer.