Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/13/19 09:29:11 (5 years ago)
Author:
gkronber
Message:

#2994: added parameter for gradient checks and experimented with preconditioning

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2994-AutoDiffForIntervals/HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Extensions/ConstrainedNLS.cs

    r17197 r17204  
    3838      get { return (IFixedValueParameter<DoubleValue>)Parameters["MaxTime"]; }
    3939    }
     40    public IFixedValueParameter<BoolValue> CheckGradientParameter {
     41      get { return (IFixedValueParameter<BoolValue>)Parameters["CheckGradient"]; }
     42    }
    4043    public int Iterations { get { return IterationsParameter.Value.Value; } set { IterationsParameter.Value.Value = value; } }
    4144
     
    4851      get { return ModelStructureParameter.Value.Value; }
    4952      set { ModelStructureParameter.Value.Value = value; }
     53    }
     54    public bool CheckGradient {
     55      get { return CheckGradientParameter.Value.Value; }
     56      set { CheckGradientParameter.Value.Value = value; }
    5057    }
    5158
     
    6471      Parameters.Add(new FixedValueParameter<DoubleValue>("FuncToleranceAbs", new DoubleValue(0)));
    6572      Parameters.Add(new FixedValueParameter<DoubleValue>("MaxTime", new DoubleValue(10)));
     73      Parameters.Add(new FixedValueParameter<BoolValue>("CheckGradient", "Flag to indicate whether the gradient should be checked using numeric approximation", new BoolValue(false)));
     74
     75      CheckGradientParameter.Hidden = true;
    6676    }
    6777
    6878    public ConstrainedNLS(ConstrainedNLS original, Cloner cloner) : base(original, cloner) {
     79    }
     80
     81    [StorableHook(HookType.AfterDeserialization)]
     82    public void AfterDeserializationHook() {
     83      if (!Parameters.ContainsKey("CheckGradient")) {
     84        Parameters.Add(new FixedValueParameter<BoolValue>("CheckGradient", "Flag to indicate whether the gradient should be checked using numeric approximation", new BoolValue(false)));
     85
     86        CheckGradientParameter.Hidden = true;
     87      }
    6988    }
    7089
     
    89108      Results.AddOrUpdateResult("Evaluations", functionEvaluations);
    90109      var bestError = new DoubleValue(double.MaxValue);
     110      var curError = new DoubleValue(double.MaxValue);
    91111      Results.AddOrUpdateResult("Best error", bestError);
     112      Results.AddOrUpdateResult("Current error", curError);
    92113      Results.AddOrUpdateResult("Tree", tree);
    93114      var qualitiesTable = new DataTable("Qualities");
     
    112133
    113134      var state = new ConstrainedNLSInternal(Solver.Value, tree, Iterations, problem.ProblemData, FuncToleranceRel, FuncToleranceAbs, MaxTime);
     135      if (CheckGradient) state.CheckGradient = true;
     136      int idx = 0;
     137      foreach(var constraintTree in state.constraintTrees) {
     138        Results.AddOrUpdateResult($"Constraint {idx++}", constraintTree);
     139      }
    114140
    115141      // we use a listener model here to get state from the solver     
     
    123149      bestQualityRow.Values.Add(bestError.Value);
    124150
    125 
    126       Results.AddOrUpdateResult("Best solution", CreateSolution(state.BestTree, problem.ProblemData));
     151      Results.AddOrUpdateResult("Best solution", CreateSolution((ISymbolicExpressionTree)state.BestTree.Clone(), problem.ProblemData));
     152      Results.AddOrUpdateResult("Best solution constraint values", new DoubleArray(state.BestConstraintValues));
    127153
    128154
     
    132158        functionEvaluations.Value++;
    133159        bestError.Value = state.BestError;
     160        curError.Value = state.CurError;
    134161        curQualityRow.Values.Add(state.CurError);
    135162        bestQualityRow.Values.Add(bestError.Value);
Note: See TracChangeset for help on using the changeset viewer.