Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/06/13 12:30:18 (11 years ago)
Author:
pfleck
Message:

#2030
Switched Text encoding to Mtom encoding for better performance for binary data.
Merged trunk into branch.

Location:
branches/HivePerformance/sources
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/HivePerformance/sources

  • branches/HivePerformance/sources/HeuristicLab.Algorithms.GradientDescent/3.3/Lbfgs.cs

    r9128 r9444  
    2222
    2323using System;
     24using System.Linq;
     25using HeuristicLab.Analysis;
    2426using HeuristicLab.Common;
    2527using HeuristicLab.Core;
     
    5153    public string Filename { get; set; }
    5254
     55    private const string AnalyzerParameterName = "Analyzer";
    5356    private const string MaxIterationsParameterName = "MaxIterations";
    5457    private const string ApproximateGradientsParameterName = "ApproximateGradients";
    5558    private const string SeedParameterName = "Seed";
    5659    private const string SetSeedRandomlyParameterName = "SetSeedRandomly";
     60    private const string GradientCheckStepSizeParameterName = "GradientCheckStepSize";
    5761
    5862    #region parameter properties
     63    public IValueParameter<IMultiAnalyzer> AnalyzerParameter {
     64      get { return (IValueParameter<IMultiAnalyzer>)Parameters[AnalyzerParameterName]; }
     65    }
    5966    public IValueParameter<IntValue> MaxIterationsParameter {
    6067      get { return (IValueParameter<IntValue>)Parameters[MaxIterationsParameterName]; }
     
    6673      get { return (IValueParameter<BoolValue>)Parameters[SetSeedRandomlyParameterName]; }
    6774    }
     75    public IValueParameter<DoubleValue> GradientStepSizeParameter {
     76      get { return (IValueParameter<DoubleValue>)Parameters[GradientCheckStepSizeParameterName]; }
     77    }
    6878    #endregion
    6979    #region properties
     80    public IMultiAnalyzer Analyzer {
     81      get { return AnalyzerParameter.Value; }
     82      set { AnalyzerParameter.Value = value; }
     83    }
    7084    public int MaxIterations {
    7185      set { MaxIterationsParameter.Value.Value = value; }
     
    8498    [Storable]
    8599    private LbfgsAnalyzer analyzer;
    86     [Storable]
    87     private LbfgsAnalyzer finalAnalyzer;
    88100    [Storable]
    89101    private Placeholder solutionCreator;
     
    99111      updateResults = cloner.Clone(original.updateResults);
    100112      analyzer = cloner.Clone(original.analyzer);
    101       finalAnalyzer = cloner.Clone(original.finalAnalyzer);
    102113      solutionCreator = cloner.Clone(original.solutionCreator);
    103114      evaluator = cloner.Clone(original.evaluator);
     
    106117    public LbfgsAlgorithm()
    107118      : base() {
    108       this.name = ItemName;
    109       this.description = ItemDescription;
    110 
     119      Parameters.Add(new ValueParameter<IMultiAnalyzer>(AnalyzerParameterName, "The analyzers that will be executed on the solution.", new MultiAnalyzer()));
    111120      Parameters.Add(new ValueParameter<IntValue>(MaxIterationsParameterName, "The maximal number of iterations for.", new IntValue(20)));
    112121      Parameters.Add(new ValueParameter<IntValue>(SeedParameterName, "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
    113122      Parameters.Add(new ValueParameter<BoolValue>(SetSeedRandomlyParameterName, "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
    114123      Parameters.Add(new ValueParameter<BoolValue>(ApproximateGradientsParameterName, "Indicates that gradients should be approximated.", new BoolValue(true)));
    115       Parameters[ApproximateGradientsParameterName].Hidden = true; // should not be changed
     124      Parameters.Add(new OptionalValueParameter<DoubleValue>(GradientCheckStepSizeParameterName, "Step size for the gradient check (should be used for debugging the gradient calculation only)."));
     125      // these parameter should not be changed usually
     126      Parameters[ApproximateGradientsParameterName].Hidden = true;
     127      Parameters[GradientCheckStepSizeParameterName].Hidden = true;
    116128
    117129      var randomCreator = new RandomCreator();
     
    122134      evaluator = new Placeholder();
    123135      updateResults = new LbfgsUpdateResults();
    124       analyzer = new LbfgsAnalyzer();
    125       finalAnalyzer = new LbfgsAnalyzer();
     136      var analyzerPlaceholder = new Placeholder();
     137      var finalAnalyzerPlaceholder = new Placeholder();
    126138
    127139      OperatorGraph.InitialOperator = randomCreator;
     
    133145      randomCreator.Successor = solutionCreator;
    134146
    135       solutionCreator.Name = "Solution Creator (placeholder)";
     147      solutionCreator.Name = "(Solution Creator)";
    136148      solutionCreator.Successor = initializer;
    137149
     
    145157      branch.ConditionParameter.ActualName = makeStep.TerminationCriterionParameter.Name;
    146158      branch.FalseBranch = evaluator;
    147       branch.TrueBranch = finalAnalyzer;
    148 
    149       evaluator.Name = "Evaluator (placeholder)";
     159      branch.TrueBranch = finalAnalyzerPlaceholder;
     160
     161      evaluator.Name = "(Evaluator)";
    150162      evaluator.Successor = updateResults;
    151163
    152164      updateResults.StateParameter.ActualName = initializer.StateParameter.Name;
    153165      updateResults.ApproximateGradientsParameter.ActualName = ApproximateGradientsParameterName;
    154       updateResults.Successor = analyzer;
    155 
     166      updateResults.Successor = analyzerPlaceholder;
     167
     168      analyzerPlaceholder.Name = "(Analyzer)";
     169      analyzerPlaceholder.OperatorParameter.ActualName = AnalyzerParameterName;
     170      analyzerPlaceholder.Successor = makeStep;
     171
     172      finalAnalyzerPlaceholder.Name = "(Analyzer)";
     173      finalAnalyzerPlaceholder.OperatorParameter.ActualName = AnalyzerParameterName;
     174      finalAnalyzerPlaceholder.Successor = null;
     175
     176      analyzer = new LbfgsAnalyzer();
    156177      analyzer.StateParameter.ActualName = initializer.StateParameter.Name;
    157       analyzer.Successor = makeStep;
    158 
    159       finalAnalyzer.PointsTableParameter.ActualName = analyzer.PointsTableParameter.ActualName;
    160       finalAnalyzer.QualityGradientsTableParameter.ActualName = analyzer.QualityGradientsTableParameter.ActualName;
    161       finalAnalyzer.QualitiesTableParameter.ActualName = analyzer.QualitiesTableParameter.ActualName;
    162178    }
    163179
     
    185201        solutionCreator.OperatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
    186202        evaluator.OperatorParameter.ActualName = Problem.EvaluatorParameter.Name;
     203        UpdateAnalyzers();
     204        ParameterizeOperators();
    187205      }
    188206    }
     
    200218    }
    201219
     220    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
     221      base.Problem_OperatorsChanged(sender, e);
     222      UpdateAnalyzers();
     223    }
     224
    202225    private void RegisterSolutionCreatorEvents() {
    203       var realVectorCreator = Problem.SolutionCreator as RealVectorCreator;
     226      var realVectorCreator = Problem.SolutionCreator as IRealVectorCreator;
    204227      // ignore if we have a different kind of problem
    205228      if (realVectorCreator != null) {
     
    214237
    215238    protected override void OnStarted() {
    216       var realVectorCreator = Problem.SolutionCreator as RealVectorCreator;
     239      var realVectorCreator = Problem.SolutionCreator as IRealVectorCreator;
    217240      // must catch the case that user loaded an unsupported problem
    218241      if (realVectorCreator == null)
     
    225248    }
    226249
     250    private void UpdateAnalyzers() {
     251      Analyzer.Operators.Clear();
     252      if (Problem != null) {
     253        foreach (var a in Problem.Operators.OfType<IAnalyzer>()) {
     254          foreach (var param in a.Parameters.OfType<IScopeTreeLookupParameter>())
     255            param.Depth = 0;
     256          Analyzer.Operators.Add(a, a.EnabledByDefault);
     257        }
     258      }
     259      Analyzer.Operators.Add(analyzer, analyzer.EnabledByDefault);
     260    }
     261
    227262    private void ParameterizeOperators() {
    228       var realVectorCreator = Problem.SolutionCreator as RealVectorCreator;
     263      var realVectorCreator = Problem.SolutionCreator as IRealVectorCreator;
    229264      // ignore if we have a different kind of problem
    230265      if (realVectorCreator != null) {
     
    233268        makeStep.PointParameter.ActualName = realVectorParameterName;
    234269        analyzer.PointParameter.ActualName = realVectorParameterName;
    235         finalAnalyzer.PointParameter.ActualName = realVectorParameterName;
    236270      }
    237271
     
    239273      updateResults.QualityParameter.ActualName = qualityParameterName;
    240274      analyzer.QualityParameter.ActualName = qualityParameterName;
    241       finalAnalyzer.QualityParameter.ActualName = qualityParameterName;
    242275    }
    243276  }
  • branches/HivePerformance/sources/HeuristicLab.Algorithms.GradientDescent/3.3/LbfgsInitializer.cs

    r9211 r9444  
    3838    private const string IterationsParameterName = "Iterations";
    3939    private const string ApproximateGradientsParameterName = "ApproximateGradients";
     40    private const string GradientCheckStepSizeParameterName = "GradientCheckStepSize";
    4041
    4142    #region Parameter Properties
     
    5354    public ILookupParameter<BoolValue> ApproximateGradientsParameter {
    5455      get { return (ILookupParameter<BoolValue>)Parameters[ApproximateGradientsParameterName]; }
     56    }
     57    public ILookupParameter<DoubleValue> GradientStepSizeParameter {
     58      get { return (ILookupParameter<DoubleValue>)Parameters[GradientCheckStepSizeParameterName]; }
    5559    }
    5660
     
    7478      Parameters.Add(new LookupParameter<BoolValue>(ApproximateGradientsParameterName,
    7579                                                    "Flag that indicates if gradients should be approximated."));
     80      Parameters.Add(new LookupParameter<DoubleValue>(GradientCheckStepSizeParameterName, "Step size for the gradient check (should be used for debugging the gradient calculation only)."));
    7681      // out
    7782      Parameters.Add(new LookupParameter<LbfgsState>(StateParameterName, "The state of the LM-BFGS algorithm."));
     
    9398      alglib.minlbfgs.minlbfgssetcond(state, 0.0, 0, 0, Iterations.Value);
    9499      alglib.minlbfgs.minlbfgssetxrep(state, true);
    95       // alglib.minlbfgs.minlbfgssetgradientcheck(state, 0.000001);
     100      if (GradientStepSizeParameter.ActualValue != null && GradientStepSizeParameter.ActualValue.Value > 0)
     101        alglib.minlbfgs.minlbfgssetgradientcheck(state, GradientStepSizeParameter.ActualValue.Value);
    96102
    97103      PointParameter.ActualValue = new RealVector(initialPoint);
  • branches/HivePerformance/sources/HeuristicLab.Algorithms.GradientDescent/3.3/LbfgsMakeStep.cs

    r8401 r9444  
    7979        alglib.minlbfgs.minlbfgsreport rep = new alglib.minlbfgs.minlbfgsreport();
    8080        alglib.minlbfgs.minlbfgsresults(state.State, ref x, rep);
     81        if (rep.terminationtype < 0) {
     82          if (rep.terminationtype == -1)
     83            throw new OperatorExecutionException(this, "Incorrect parameters were specified.");
     84          else if (rep.terminationtype == -2)
     85            throw new OperatorExecutionException(this, "Rounding errors prevent further improvement.");
     86          else if (rep.terminationtype == -7)
     87            throw new OperatorExecutionException(this, "Gradient verification failed.");
     88        }
    8189        PointParameter.ActualValue = new RealVector(x);
    8290      }
Note: See TracChangeset for help on using the changeset viewer.