Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9439


Ignore:
Timestamp:
05/04/13 17:10:55 (12 years ago)
Author:
abeham
Message:

#1423: Changed the way analyzers work for LM-BFGS

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.GradientDescent/3.3/Lbfgs.cs

    r9409 r9439  
    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";
     
    5861
    5962    #region parameter properties
     63    public IValueParameter<IMultiAnalyzer> AnalyzerParameter {
     64      get { return (IValueParameter<IMultiAnalyzer>)Parameters[AnalyzerParameterName]; }
     65    }
    6066    public IValueParameter<IntValue> MaxIterationsParameter {
    6167      get { return (IValueParameter<IntValue>)Parameters[MaxIterationsParameterName]; }
     
    7278    #endregion
    7379    #region properties
     80    public IMultiAnalyzer Analyzer {
     81      get { return AnalyzerParameter.Value; }
     82      set { AnalyzerParameter.Value = value; }
     83    }
    7484    public int MaxIterations {
    7585      set { MaxIterationsParameter.Value.Value = value; }
     
    8898    [Storable]
    8999    private LbfgsAnalyzer analyzer;
    90     [Storable]
    91     private LbfgsAnalyzer finalAnalyzer;
    92100    [Storable]
    93101    private Placeholder solutionCreator;
     
    103111      updateResults = cloner.Clone(original.updateResults);
    104112      analyzer = cloner.Clone(original.analyzer);
    105       finalAnalyzer = cloner.Clone(original.finalAnalyzer);
    106113      solutionCreator = cloner.Clone(original.solutionCreator);
    107114      evaluator = cloner.Clone(original.evaluator);
     
    110117    public LbfgsAlgorithm()
    111118      : base() {
    112 
     119      Parameters.Add(new ValueParameter<IMultiAnalyzer>(AnalyzerParameterName, "The analyzers that will be executed on the solution.", new MultiAnalyzer()));
    113120      Parameters.Add(new ValueParameter<IntValue>(MaxIterationsParameterName, "The maximal number of iterations for.", new IntValue(20)));
    114121      Parameters.Add(new ValueParameter<IntValue>(SeedParameterName, "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
     
    127134      evaluator = new Placeholder();
    128135      updateResults = new LbfgsUpdateResults();
    129       analyzer = new LbfgsAnalyzer();
    130       finalAnalyzer = new LbfgsAnalyzer();
     136      var analyzerPlaceholder = new Placeholder();
     137      var finalAnalyzerPlaceholder = new Placeholder();
    131138
    132139      OperatorGraph.InitialOperator = randomCreator;
     
    150157      branch.ConditionParameter.ActualName = makeStep.TerminationCriterionParameter.Name;
    151158      branch.FalseBranch = evaluator;
    152       branch.TrueBranch = finalAnalyzer;
     159      branch.TrueBranch = finalAnalyzerPlaceholder;
    153160
    154161      evaluator.Name = "(Evaluator)";
     
    157164      updateResults.StateParameter.ActualName = initializer.StateParameter.Name;
    158165      updateResults.ApproximateGradientsParameter.ActualName = ApproximateGradientsParameterName;
    159       updateResults.Successor = analyzer;
    160 
     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();
    161177      analyzer.StateParameter.ActualName = initializer.StateParameter.Name;
    162       analyzer.Successor = makeStep;
    163 
    164       finalAnalyzer.PointsTableParameter.ActualName = analyzer.PointsTableParameter.ActualName;
    165       finalAnalyzer.QualityGradientsTableParameter.ActualName = analyzer.QualityGradientsTableParameter.ActualName;
    166       finalAnalyzer.QualitiesTableParameter.ActualName = analyzer.QualitiesTableParameter.ActualName;
    167178    }
    168179
     
    190201        solutionCreator.OperatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
    191202        evaluator.OperatorParameter.ActualName = Problem.EvaluatorParameter.Name;
     203        UpdateAnalyzers();
     204        ParameterizeOperators();
    192205      }
    193206    }
     
    203216      RegisterEvaluatorEvents();
    204217      ParameterizeOperators();
     218    }
     219
     220    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
     221      base.Problem_OperatorsChanged(sender, e);
     222      UpdateAnalyzers();
    205223    }
    206224
     
    228246    public override void Prepare() {
    229247      if (Problem != null) base.Prepare();
     248    }
     249
     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);
    230260    }
    231261
     
    238268        makeStep.PointParameter.ActualName = realVectorParameterName;
    239269        analyzer.PointParameter.ActualName = realVectorParameterName;
    240         finalAnalyzer.PointParameter.ActualName = realVectorParameterName;
    241270      }
    242271
     
    244273      updateResults.QualityParameter.ActualName = qualityParameterName;
    245274      analyzer.QualityParameter.ActualName = qualityParameterName;
    246       finalAnalyzer.QualityParameter.ActualName = qualityParameterName;
    247275    }
    248276  }
Note: See TracChangeset for help on using the changeset viewer.