Changeset 9439
- Timestamp:
- 05/04/13 17:10:55 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.GradientDescent/3.3/Lbfgs.cs
r9409 r9439 22 22 23 23 using System; 24 using System.Linq; 25 using HeuristicLab.Analysis; 24 26 using HeuristicLab.Common; 25 27 using HeuristicLab.Core; … … 51 53 public string Filename { get; set; } 52 54 55 private const string AnalyzerParameterName = "Analyzer"; 53 56 private const string MaxIterationsParameterName = "MaxIterations"; 54 57 private const string ApproximateGradientsParameterName = "ApproximateGradients"; … … 58 61 59 62 #region parameter properties 63 public IValueParameter<IMultiAnalyzer> AnalyzerParameter { 64 get { return (IValueParameter<IMultiAnalyzer>)Parameters[AnalyzerParameterName]; } 65 } 60 66 public IValueParameter<IntValue> MaxIterationsParameter { 61 67 get { return (IValueParameter<IntValue>)Parameters[MaxIterationsParameterName]; } … … 72 78 #endregion 73 79 #region properties 80 public IMultiAnalyzer Analyzer { 81 get { return AnalyzerParameter.Value; } 82 set { AnalyzerParameter.Value = value; } 83 } 74 84 public int MaxIterations { 75 85 set { MaxIterationsParameter.Value.Value = value; } … … 88 98 [Storable] 89 99 private LbfgsAnalyzer analyzer; 90 [Storable]91 private LbfgsAnalyzer finalAnalyzer;92 100 [Storable] 93 101 private Placeholder solutionCreator; … … 103 111 updateResults = cloner.Clone(original.updateResults); 104 112 analyzer = cloner.Clone(original.analyzer); 105 finalAnalyzer = cloner.Clone(original.finalAnalyzer);106 113 solutionCreator = cloner.Clone(original.solutionCreator); 107 114 evaluator = cloner.Clone(original.evaluator); … … 110 117 public LbfgsAlgorithm() 111 118 : base() { 112 119 Parameters.Add(new ValueParameter<IMultiAnalyzer>(AnalyzerParameterName, "The analyzers that will be executed on the solution.", new MultiAnalyzer())); 113 120 Parameters.Add(new ValueParameter<IntValue>(MaxIterationsParameterName, "The maximal number of iterations for.", new IntValue(20))); 114 121 Parameters.Add(new ValueParameter<IntValue>(SeedParameterName, "The random seed used to initialize the new pseudo random number generator.", new IntValue(0))); … … 127 134 evaluator = new Placeholder(); 128 135 updateResults = new LbfgsUpdateResults(); 129 analyzer = new LbfgsAnalyzer();130 finalAnalyzer = new LbfgsAnalyzer();136 var analyzerPlaceholder = new Placeholder(); 137 var finalAnalyzerPlaceholder = new Placeholder(); 131 138 132 139 OperatorGraph.InitialOperator = randomCreator; … … 150 157 branch.ConditionParameter.ActualName = makeStep.TerminationCriterionParameter.Name; 151 158 branch.FalseBranch = evaluator; 152 branch.TrueBranch = finalAnalyzer ;159 branch.TrueBranch = finalAnalyzerPlaceholder; 153 160 154 161 evaluator.Name = "(Evaluator)"; … … 157 164 updateResults.StateParameter.ActualName = initializer.StateParameter.Name; 158 165 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(); 161 177 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;167 178 } 168 179 … … 190 201 solutionCreator.OperatorParameter.ActualName = Problem.SolutionCreatorParameter.Name; 191 202 evaluator.OperatorParameter.ActualName = Problem.EvaluatorParameter.Name; 203 UpdateAnalyzers(); 204 ParameterizeOperators(); 192 205 } 193 206 } … … 203 216 RegisterEvaluatorEvents(); 204 217 ParameterizeOperators(); 218 } 219 220 protected override void Problem_OperatorsChanged(object sender, EventArgs e) { 221 base.Problem_OperatorsChanged(sender, e); 222 UpdateAnalyzers(); 205 223 } 206 224 … … 228 246 public override void Prepare() { 229 247 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); 230 260 } 231 261 … … 238 268 makeStep.PointParameter.ActualName = realVectorParameterName; 239 269 analyzer.PointParameter.ActualName = realVectorParameterName; 240 finalAnalyzer.PointParameter.ActualName = realVectorParameterName;241 270 } 242 271 … … 244 273 updateResults.QualityParameter.ActualName = qualityParameterName; 245 274 analyzer.QualityParameter.ActualName = qualityParameterName; 246 finalAnalyzer.QualityParameter.ActualName = qualityParameterName;247 275 } 248 276 }
Note: See TracChangeset
for help on using the changeset viewer.