Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15483


Ignore:
Timestamp:
11/21/17 17:10:05 (6 years ago)
Author:
mkommend
Message:

#2852: Added option for reporting function and gradient evaluation in the constants optimization evaluator.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionConstantOptimizationEvaluator.cs

    r15481 r15483  
    4444    private const string FunctionEvaluationsResultParameterName = "Constants Optimization Function Evaluations";
    4545    private const string GradientEvaluationsResultParameterName = "Constants Optimization Gradient Evaluations";
     46    private const string CountEvaluationsParameterName = "Count Function and Gradient Evaluations";
    4647
    4748    public IFixedValueParameter<IntValue> ConstantOptimizationIterationsParameter {
     
    6970    public IResultParameter<IntValue> GradientEvaluationsResultParameter {
    7071      get { return (IResultParameter<IntValue>)Parameters[GradientEvaluationsResultParameterName]; }
     72    }
     73    public IFixedValueParameter<BoolValue> CountEvaluationsParameter {
     74      get { return (IFixedValueParameter<BoolValue>)Parameters[CountEvaluationsParameterName]; }
    7175    }
    7276
     
    9296      get { return UpdateVariableWeightsParameter.Value.Value; }
    9397      set { UpdateVariableWeightsParameter.Value.Value = value; }
     98    }
     99
     100    public bool CountEvaluations {
     101      get { return CountEvaluationsParameter.Value.Value; }
     102      set { CountEvaluationsParameter.Value.Value = value; }
    94103    }
    95104
     
    112121      Parameters.Add(new FixedValueParameter<BoolValue>(UpdateVariableWeightsParameterName, "Determines if the variable weights in the tree should be  optimized.", new BoolValue(true)) { Hidden = true });
    113122
     123      Parameters.Add(new FixedValueParameter<BoolValue>(CountEvaluationsParameterName, "Determines if function and gradient evaluation should be counted.", new BoolValue(false)));
    114124      Parameters.Add(new ResultParameter<IntValue>(FunctionEvaluationsResultParameterName, "The number of function evaluations performed by the constants optimization evaluator", "Results", new IntValue()));
    115125      Parameters.Add(new ResultParameter<IntValue>(GradientEvaluationsResultParameterName, "The number of gradient evaluations performed by the constants optimization evaluator", "Results", new IntValue()));
     
    126136      if (!Parameters.ContainsKey(UpdateVariableWeightsParameterName))
    127137        Parameters.Add(new FixedValueParameter<BoolValue>(UpdateVariableWeightsParameterName, "Determines if the variable weights in the tree should be  optimized.", new BoolValue(true)));
     138
     139      if (!Parameters.ContainsKey(CountEvaluationsParameterName))
     140        Parameters.Add(new FixedValueParameter<BoolValue>(CountEvaluationsParameterName, "Determines if function and gradient evaluation should be counted.", new BoolValue(false)));
     141      if (Parameters.ContainsKey(FunctionEvaluationsResultParameterName) && Parameters.ContainsKey(GradientEvaluationsResultParameterName))
     142        CountEvaluations = true;
    128143
    129144      if (!Parameters.ContainsKey(FunctionEvaluationsResultParameterName))
     
    148163        }
    149164
    150         lock (locker) {
    151           FunctionEvaluationsResultParameter.ActualValue.Value += counter.FunctionEvaluations;
    152           GradientEvaluationsResultParameter.ActualValue.Value += counter.GradientEvaluations;
     165        if (CountEvaluations) {
     166          lock (locker) {
     167            FunctionEvaluationsResultParameter.ActualValue.Value += counter.FunctionEvaluations;
     168            GradientEvaluationsResultParameter.ActualValue.Value += counter.GradientEvaluations;
     169          }
    153170        }
    154171
Note: See TracChangeset for help on using the changeset viewer.