- Timestamp:
- 05/06/13 12:30:18 (12 years ago)
- Location:
- branches/HivePerformance/sources
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HivePerformance/sources
- Property svn:mergeinfo changed
/trunk/sources (added) merged: 9376,9379,9388,9390,9396,9402-9410,9413,9417,9426-9429,9432-9433,9435-9439,9441-9443
- Property svn:mergeinfo changed
-
branches/HivePerformance/sources/HeuristicLab.Algorithms.GradientDescent/3.3/Lbfgs.cs
r9128 r9444 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"; 55 58 private const string SeedParameterName = "Seed"; 56 59 private const string SetSeedRandomlyParameterName = "SetSeedRandomly"; 60 private const string GradientCheckStepSizeParameterName = "GradientCheckStepSize"; 57 61 58 62 #region parameter properties 63 public IValueParameter<IMultiAnalyzer> AnalyzerParameter { 64 get { return (IValueParameter<IMultiAnalyzer>)Parameters[AnalyzerParameterName]; } 65 } 59 66 public IValueParameter<IntValue> MaxIterationsParameter { 60 67 get { return (IValueParameter<IntValue>)Parameters[MaxIterationsParameterName]; } … … 66 73 get { return (IValueParameter<BoolValue>)Parameters[SetSeedRandomlyParameterName]; } 67 74 } 75 public IValueParameter<DoubleValue> GradientStepSizeParameter { 76 get { return (IValueParameter<DoubleValue>)Parameters[GradientCheckStepSizeParameterName]; } 77 } 68 78 #endregion 69 79 #region properties 80 public IMultiAnalyzer Analyzer { 81 get { return AnalyzerParameter.Value; } 82 set { AnalyzerParameter.Value = value; } 83 } 70 84 public int MaxIterations { 71 85 set { MaxIterationsParameter.Value.Value = value; } … … 84 98 [Storable] 85 99 private LbfgsAnalyzer analyzer; 86 [Storable]87 private LbfgsAnalyzer finalAnalyzer;88 100 [Storable] 89 101 private Placeholder solutionCreator; … … 99 111 updateResults = cloner.Clone(original.updateResults); 100 112 analyzer = cloner.Clone(original.analyzer); 101 finalAnalyzer = cloner.Clone(original.finalAnalyzer);102 113 solutionCreator = cloner.Clone(original.solutionCreator); 103 114 evaluator = cloner.Clone(original.evaluator); … … 106 117 public LbfgsAlgorithm() 107 118 : 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())); 111 120 Parameters.Add(new ValueParameter<IntValue>(MaxIterationsParameterName, "The maximal number of iterations for.", new IntValue(20))); 112 121 Parameters.Add(new ValueParameter<IntValue>(SeedParameterName, "The random seed used to initialize the new pseudo random number generator.", new IntValue(0))); 113 122 Parameters.Add(new ValueParameter<BoolValue>(SetSeedRandomlyParameterName, "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true))); 114 123 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; 116 128 117 129 var randomCreator = new RandomCreator(); … … 122 134 evaluator = new Placeholder(); 123 135 updateResults = new LbfgsUpdateResults(); 124 analyzer = new LbfgsAnalyzer();125 finalAnalyzer = new LbfgsAnalyzer();136 var analyzerPlaceholder = new Placeholder(); 137 var finalAnalyzerPlaceholder = new Placeholder(); 126 138 127 139 OperatorGraph.InitialOperator = randomCreator; … … 133 145 randomCreator.Successor = solutionCreator; 134 146 135 solutionCreator.Name = " Solution Creator (placeholder)";147 solutionCreator.Name = "(Solution Creator)"; 136 148 solutionCreator.Successor = initializer; 137 149 … … 145 157 branch.ConditionParameter.ActualName = makeStep.TerminationCriterionParameter.Name; 146 158 branch.FalseBranch = evaluator; 147 branch.TrueBranch = finalAnalyzer ;148 149 evaluator.Name = " Evaluator (placeholder)";159 branch.TrueBranch = finalAnalyzerPlaceholder; 160 161 evaluator.Name = "(Evaluator)"; 150 162 evaluator.Successor = updateResults; 151 163 152 164 updateResults.StateParameter.ActualName = initializer.StateParameter.Name; 153 165 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(); 156 177 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;162 178 } 163 179 … … 185 201 solutionCreator.OperatorParameter.ActualName = Problem.SolutionCreatorParameter.Name; 186 202 evaluator.OperatorParameter.ActualName = Problem.EvaluatorParameter.Name; 203 UpdateAnalyzers(); 204 ParameterizeOperators(); 187 205 } 188 206 } … … 200 218 } 201 219 220 protected override void Problem_OperatorsChanged(object sender, EventArgs e) { 221 base.Problem_OperatorsChanged(sender, e); 222 UpdateAnalyzers(); 223 } 224 202 225 private void RegisterSolutionCreatorEvents() { 203 var realVectorCreator = Problem.SolutionCreator as RealVectorCreator;226 var realVectorCreator = Problem.SolutionCreator as IRealVectorCreator; 204 227 // ignore if we have a different kind of problem 205 228 if (realVectorCreator != null) { … … 214 237 215 238 protected override void OnStarted() { 216 var realVectorCreator = Problem.SolutionCreator as RealVectorCreator;239 var realVectorCreator = Problem.SolutionCreator as IRealVectorCreator; 217 240 // must catch the case that user loaded an unsupported problem 218 241 if (realVectorCreator == null) … … 225 248 } 226 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); 260 } 261 227 262 private void ParameterizeOperators() { 228 var realVectorCreator = Problem.SolutionCreator as RealVectorCreator;263 var realVectorCreator = Problem.SolutionCreator as IRealVectorCreator; 229 264 // ignore if we have a different kind of problem 230 265 if (realVectorCreator != null) { … … 233 268 makeStep.PointParameter.ActualName = realVectorParameterName; 234 269 analyzer.PointParameter.ActualName = realVectorParameterName; 235 finalAnalyzer.PointParameter.ActualName = realVectorParameterName;236 270 } 237 271 … … 239 273 updateResults.QualityParameter.ActualName = qualityParameterName; 240 274 analyzer.QualityParameter.ActualName = qualityParameterName; 241 finalAnalyzer.QualityParameter.ActualName = qualityParameterName;242 275 } 243 276 } -
branches/HivePerformance/sources/HeuristicLab.Algorithms.GradientDescent/3.3/LbfgsInitializer.cs
r9211 r9444 38 38 private const string IterationsParameterName = "Iterations"; 39 39 private const string ApproximateGradientsParameterName = "ApproximateGradients"; 40 private const string GradientCheckStepSizeParameterName = "GradientCheckStepSize"; 40 41 41 42 #region Parameter Properties … … 53 54 public ILookupParameter<BoolValue> ApproximateGradientsParameter { 54 55 get { return (ILookupParameter<BoolValue>)Parameters[ApproximateGradientsParameterName]; } 56 } 57 public ILookupParameter<DoubleValue> GradientStepSizeParameter { 58 get { return (ILookupParameter<DoubleValue>)Parameters[GradientCheckStepSizeParameterName]; } 55 59 } 56 60 … … 74 78 Parameters.Add(new LookupParameter<BoolValue>(ApproximateGradientsParameterName, 75 79 "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).")); 76 81 // out 77 82 Parameters.Add(new LookupParameter<LbfgsState>(StateParameterName, "The state of the LM-BFGS algorithm.")); … … 93 98 alglib.minlbfgs.minlbfgssetcond(state, 0.0, 0, 0, Iterations.Value); 94 99 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); 96 102 97 103 PointParameter.ActualValue = new RealVector(initialPoint); -
branches/HivePerformance/sources/HeuristicLab.Algorithms.GradientDescent/3.3/LbfgsMakeStep.cs
r8401 r9444 79 79 alglib.minlbfgs.minlbfgsreport rep = new alglib.minlbfgs.minlbfgsreport(); 80 80 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 } 81 89 PointParameter.ActualValue = new RealVector(x); 82 90 }
Note: See TracChangeset
for help on using the changeset viewer.