Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Algorithms.GradientDescent/HeuristicLab.Algorithms.GradientDescent/3.3/LevenbergMarquardt.cs @ 7786

Last change on this file since 7786 was 5520, checked in by gkronber, 14 years ago

#1423 Fixed problem with progress reporting and stored quality values in a datatable.

File size: 5.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Operators;
27using HeuristicLab.Optimization;
28using HeuristicLab.Optimization.Operators;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31using HeuristicLab.Problems.TestFunctions;
32using HeuristicLab.Random;
33
34namespace HeuristicLab.Algorithms.GradientDescent {
35  /// <summary>
36  /// Linear regression data analysis algorithm.
37  /// </summary>
38  [Item("Levenberg Marquardt", "Levenberg Marquardt real vector optimization algorithm.")]
39  [Creatable("Algorithms")]
40  [StorableClass]
41  public sealed class LevenbergMarquardt : EngineAlgorithm, IStorableContent {
42    public string Filename { get; set; }
43
44    public override Type ProblemType {
45      get { return typeof(SingleObjectiveTestFunctionProblem); }
46    }
47    public new SingleObjectiveTestFunctionProblem Problem {
48      get { return (SingleObjectiveTestFunctionProblem)base.Problem; }
49      set { base.Problem = value; }
50    }
51
52    private ValueParameter<IntValue> SeedParameter {
53      get { return (ValueParameter<IntValue>)Parameters["Seed"]; }
54    }
55    private ValueParameter<BoolValue> SetSeedRandomlyParameter {
56      get { return (ValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
57    }
58
59    public IntValue Seed {
60      get { return SeedParameter.Value; }
61      set { SeedParameter.Value = value; }
62    }
63    public BoolValue SetSeedRandomly {
64      get { return SetSeedRandomlyParameter.Value; }
65      set { SetSeedRandomlyParameter.Value = value; }
66    }
67
68    private RandomCreator RandomCreator {
69      get { return (RandomCreator)OperatorGraph.InitialOperator; }
70    }
71    private SolutionsCreator SolutionsCreator {
72      get { return (SolutionsCreator)RandomCreator.Successor; }
73    }
74
75    #region storing and cloning
76    [StorableConstructor]
77    private LevenbergMarquardt(bool deserializing) : base(deserializing) { }
78    private LevenbergMarquardt(LevenbergMarquardt original, Cloner cloner)
79      : base(original, cloner) {
80      Initialize();
81    }
82    public override IDeepCloneable Clone(Cloner cloner) {
83      return new LevenbergMarquardt(this, cloner);
84    }
85    #endregion
86
87    public LevenbergMarquardt()
88      : base() {
89      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
90      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
91
92
93      RandomCreator randomCreator = new RandomCreator();
94      SolutionsCreator solutionsCreator = new SolutionsCreator();
95      UniformSubScopesProcessor subscopesProcessor = new UniformSubScopesProcessor();
96      LevenbergMarquardtMove moveCreator = new LevenbergMarquardtMove();
97      OperatorGraph.InitialOperator = randomCreator;
98
99      randomCreator.RandomParameter.ActualName = "Random";
100      randomCreator.SeedParameter.ActualName = SeedParameter.Name;
101      randomCreator.SeedParameter.Value = null;
102      randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
103      randomCreator.SetSeedRandomlyParameter.Value = null;
104      randomCreator.Successor = solutionsCreator;
105
106      solutionsCreator.NumberOfSolutionsParameter.Value = new IntValue(1);
107      solutionsCreator.Successor = subscopesProcessor;
108
109      subscopesProcessor.Operator = moveCreator;
110    }
111
112    public override void Prepare() {
113      if (Problem != null) base.Prepare();
114    }
115
116    protected override void Problem_Reset(object sender, EventArgs e) {
117      base.Problem_Reset(sender, e);
118    }
119
120    protected override void OnProblemChanged() {
121      Problem.Reset += new EventHandler(Problem_Reset);
122      base.OnProblemChanged();
123    }
124
125    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
126      SolutionsCreator.NumberOfSolutionsParameter.Value = new IntValue(1);
127      base.Problem_SolutionCreatorChanged(sender, e);
128    }
129
130
131    private void Initialize() {
132
133    }
134  }
135}
Note: See TracBrowser for help on using the repository browser.