- Timestamp:
- 04/04/17 12:37:52 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/Problems/InfillProblem.cs
r14768 r14818 27 27 using HeuristicLab.Optimization; 28 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 using HeuristicLab.Problems.DataAnalysis;30 29 31 30 namespace HeuristicLab.Algorithms.EGO { … … 34 33 public sealed class InfillProblem : SingleObjectiveBasicProblem<RealVectorEncoding> { 35 34 36 public override bool Maximization => true; 35 public override bool Maximization => true; //This is necessary because algorithms do not expect the maximization to change 37 36 38 37 #region Properties; … … 41 40 [Storable] 42 41 private SingleObjectiveBasicProblem<IEncoding> problem; 43 [Storable]44 private IRegressionSolution regressionSolution;45 46 42 47 43 public IInfillCriterion InfillCriterion … … 57 53 problem = value; 58 54 if (problem == null) return; 59 Encoding = problem.Encoding as RealVectorEncoding; 55 var enc = problem.Encoding as RealVectorEncoding; 56 if (enc == null) throw new ArgumentException("EGO can not be performed on non-RealVectorEncodings"); 57 Encoding = enc; 60 58 SolutionCreator = new UniformRandomRealVectorCreator();//ignore Problem specific Solution Creation 61 if (Encoding == null) throw new ArgumentException("EGO can not be performed on non-RealVectorEncodings"); 59 62 60 } 63 }64 public IRegressionSolution RegressionSolution65 {66 get { return regressionSolution; }67 set { regressionSolution = value; }68 61 } 69 62 #endregion … … 75 68 infillCriterion = cloner.Clone(original.InfillCriterion); 76 69 problem = cloner.Clone(original.Problem); 77 regressionSolution = cloner.Clone(original.regressionSolution);78 70 } 79 71 public InfillProblem() { } … … 82 74 83 75 public override double Evaluate(Individual individual, IRandom r) { 84 var q = InfillCriterion.Evaluate( RegressionSolution, individual.RealVector(), Problem.Maximization);85 return InfillCriterion.Maximization( Problem.Maximization) ? q : -q; //This is necessary because Maximization is not supposed to change on a normal problem76 var q = InfillCriterion.Evaluate(individual.RealVector()); 77 return InfillCriterion.Maximization() ? q : -q; 86 78 } 87 79 public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) { 88 80 base.Analyze(individuals, qualities, results, random); 89 81 var best = qualities.ArgMax(x => x); 90 var qnew = InfillCriterion.Maximization(Problem.Maximization) ? qualities[best] : -qualities[best]; 91 //var best = Maximization ? qualities.ArgMax(x => x) : qualities.ArgMin(x => x); 82 var qnew = InfillCriterion.Maximization() ? qualities[best] : -qualities[best]; 92 83 const string qname = EfficientGlobalOptimizationAlgorithm.BestInfillQualityResultName; 93 84 const string sname = EfficientGlobalOptimizationAlgorithm.BestInfillSolutionResultName; … … 99 90 var qold = results[qname].Value as DoubleValue; 100 91 if (qold == null) throw new ArgumentException("Old best quality is not a double value. Conflicting Analyzers?"); 101 if (qold.Value >= qnew == InfillCriterion.Maximization( Problem.Maximization)) return;92 if (qold.Value >= qnew == InfillCriterion.Maximization()) return; 102 93 results[sname].Value = (RealVector)individuals[best].RealVector().Clone(); 103 94 qold.Value = qnew; 104 105 95 } 106 96 }
Note: See TracChangeset
for help on using the changeset viewer.