Changeset 8396 for trunk/sources
- Timestamp:
- 08/02/12 17:27:46 (12 years ago)
- Location:
- trunk/sources
- Files:
-
- 1 added
- 7 edited
- 6 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessHyperparameterInitializer.cs
r8375 r8396 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Data; 26 using HeuristicLab.Encodings.RealVectorEncoding; 26 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 28 using HeuristicLab.Operators; … … 32 33 namespace HeuristicLab.Algorithms.DataAnalysis { 33 34 [StorableClass] 34 [Item(Name = "GaussianProcess SetHyperparameterLength",35 Description = " Determines the length ofthe hyperparameter vector based on the mean function, covariance function, and number of allowed input variables.")]36 public sealed class GaussianProcess SetHyperparameterLength: SingleSuccessorOperator {35 [Item(Name = "GaussianProcessHyperparameterInitializer", 36 Description = "Initializers the hyperparameter vector based on the mean function, covariance function, and number of allowed input variables.")] 37 public sealed class GaussianProcessHyperparameterInitializer : SingleSuccessorOperator { 37 38 private const string MeanFunctionParameterName = "MeanFunction"; 38 39 private const string CovarianceFunctionParameterName = "CovarianceFunction"; 39 40 private const string ProblemDataParameterName = "ProblemData"; 40 private const string NumberOfHyperparameterParameterName = "NumberOfHyperparameter";41 private const string HyperparameterParameterName = "Hyperparameter"; 41 42 42 43 #region Parameter Properties … … 52 53 } 53 54 // out 54 public ILookupParameter< IntValue> NumberOfHyperparameterParameter {55 get { return (ILookupParameter< IntValue>)Parameters[NumberOfHyperparameterParameterName]; }55 public ILookupParameter<RealVector> HyperparameterParameter { 56 get { return (ILookupParameter<RealVector>)Parameters[HyperparameterParameterName]; } 56 57 } 57 58 #endregion … … 64 65 65 66 [StorableConstructor] 66 private GaussianProcess SetHyperparameterLength(bool deserializing) : base(deserializing) { }67 private GaussianProcess SetHyperparameterLength(GaussianProcessSetHyperparameterLengthoriginal, Cloner cloner) : base(original, cloner) { }68 public GaussianProcess SetHyperparameterLength()67 private GaussianProcessHyperparameterInitializer(bool deserializing) : base(deserializing) { } 68 private GaussianProcessHyperparameterInitializer(GaussianProcessHyperparameterInitializer original, Cloner cloner) : base(original, cloner) { } 69 public GaussianProcessHyperparameterInitializer() 69 70 : base() { 70 71 // in … … 73 74 Parameters.Add(new LookupParameter<IDataAnalysisProblemData>(ProblemDataParameterName, "The input data for the Gaussian process.")); 74 75 // out 75 Parameters.Add(new LookupParameter< IntValue>(NumberOfHyperparameterParameterName, "The length of thehyperparameter vector for the Gaussian process model."));76 Parameters.Add(new LookupParameter<RealVector>(HyperparameterParameterName, "The initial hyperparameter vector for the Gaussian process model.")); 76 77 } 77 78 78 79 public override IDeepCloneable Clone(Cloner cloner) { 79 return new GaussianProcess SetHyperparameterLength(this, cloner);80 return new GaussianProcessHyperparameterInitializer(this, cloner); 80 81 } 81 82 82 public override IOperation Apply() 83 { 83 public override IOperation Apply() { 84 84 var inputVariablesCount = ProblemData.AllowedInputVariables.Count(); 85 85 int l = 1 + MeanFunction.GetNumberOfParameters(inputVariablesCount) + 86 86 CovarianceFunction.GetNumberOfParameters(inputVariablesCount); 87 NumberOfHyperparameterParameter.ActualValue = new IntValue(l);87 HyperparameterParameter.ActualValue = new RealVector(l); 88 88 return base.Apply(); 89 89 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessModel.cs
r8371 r8396 35 35 [Item("GaussianProcessModel", "Represents a Gaussian process posterior.")] 36 36 public sealed class GaussianProcessModel : NamedItem, IGaussianProcessModel { 37 38 37 [Storable] 39 38 private double negativeLogLikelihood; -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessModelCreator.cs
r8375 r8396 23 23 using HeuristicLab.Core; 24 24 using HeuristicLab.Data; 25 using HeuristicLab.Encodings.RealVectorEncoding; 25 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 27 using HeuristicLab.Operators; … … 42 43 #region Parameter Properties 43 44 // in 44 public ILookupParameter< DoubleArray> HyperparameterParameter {45 get { return (ILookupParameter< DoubleArray>)Parameters[HyperparameterParameterName]; }45 public ILookupParameter<RealVector> HyperparameterParameter { 46 get { return (ILookupParameter<RealVector>)Parameters[HyperparameterParameterName]; } 46 47 } 47 48 public ILookupParameter<IMeanFunction> MeanFunctionParameter { … … 55 56 get { return (ILookupParameter<IGaussianProcessModel>)Parameters[ModelParameterName]; } 56 57 } 57 public ILookupParameter< DoubleArray> HyperparameterGradientsParameter {58 get { return (ILookupParameter< DoubleArray>)Parameters[HyperparameterGradientsParameterName]; }58 public ILookupParameter<RealVector> HyperparameterGradientsParameter { 59 get { return (ILookupParameter<RealVector>)Parameters[HyperparameterGradientsParameterName]; } 59 60 } 60 61 public ILookupParameter<DoubleValue> NegativeLogLikelihoodParameter { … … 65 66 66 67 #region Properties 67 protected DoubleArrayHyperparameter { get { return HyperparameterParameter.ActualValue; } }68 protected RealVector Hyperparameter { get { return HyperparameterParameter.ActualValue; } } 68 69 protected IMeanFunction MeanFunction { get { return MeanFunctionParameter.ActualValue; } } 69 70 protected ICovarianceFunction CovarianceFunction { get { return CovarianceFunctionParameter.ActualValue; } } … … 76 77 : base() { 77 78 // in 78 Parameters.Add(new LookupParameter< DoubleArray>(HyperparameterParameterName, "The hyperparameters for the Gaussian process model."));79 Parameters.Add(new LookupParameter<RealVector>(HyperparameterParameterName, "The hyperparameters for the Gaussian process model.")); 79 80 Parameters.Add(new LookupParameter<IMeanFunction>(MeanFunctionParameterName, "The mean function for the Gaussian process model.")); 80 81 Parameters.Add(new LookupParameter<ICovarianceFunction>(CovarianceFunctionParameterName, "The covariance function for the Gaussian process model.")); 81 82 // out 82 83 Parameters.Add(new LookupParameter<IGaussianProcessModel>(ModelParameterName, "The resulting Gaussian process model")); 83 Parameters.Add(new LookupParameter< DoubleArray>(HyperparameterGradientsParameterName, "The gradients of the hyperparameters for the produced Gaussian process model (necessary for hyperparameter optimization)"));84 Parameters.Add(new LookupParameter<RealVector>(HyperparameterGradientsParameterName, "The gradients of the hyperparameters for the produced Gaussian process model (necessary for hyperparameter optimization)")); 84 85 Parameters.Add(new LookupParameter<DoubleValue>(NegativeLogLikelihoodParameterName, "The negative log-likelihood of the produced Gaussian process model given the data.")); 85 86 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessRegression.cs
r8375 r8396 28 28 using HeuristicLab.Core; 29 29 using HeuristicLab.Data; 30 using HeuristicLab.Encodings.RealVectorEncoding; 30 31 using HeuristicLab.Operators; 31 32 using HeuristicLab.Optimization; … … 55 56 private const string CovarianceFunctionParameterName = "CovarianceFunction"; 56 57 private const string MinimizationIterationsParameterName = "Iterations"; 58 private const string ApproximateGradientsParameterName = "ApproximateGradients"; 57 59 58 60 #region parameter properties … … 88 90 public GaussianProcessRegression() 89 91 : base() { 92 this.name = ItemName; 93 this.description = ItemDescription; 94 90 95 Problem = new RegressionProblem(); 91 96 … … 97 102 Parameters.Add(new ConstrainedValueParameter<ICovarianceFunction>(CovarianceFunctionParameterName, "The covariance function to use.", 98 103 new ItemSet<ICovarianceFunction>(covFunctions), covFunctions.First())); 99 Parameters.Add(new ValueParameter<IntValue>(MinimizationIterationsParameterName, "The number of iterations for likelihood optimization with BFGS.", new IntValue(20))); 104 Parameters.Add(new ValueParameter<IntValue>(MinimizationIterationsParameterName, "The number of iterations for likelihood optimization with LM-BFGS.", new IntValue(20))); 105 Parameters.Add(new ValueParameter<BoolValue>(ApproximateGradientsParameterName, "Indicates that gradients should not be approximated (necessary for LM-BFGS).", new BoolValue(false))); 106 Parameters[ApproximateGradientsParameterName].Hidden = true; // should not be changed 100 107 101 var setParameterLength = new GaussianProcessSetHyperparameterLength();102 var initializer = new BFGSInitializer();103 var makeStep = new BFGSMakeStep();108 var gpInitializer = new GaussianProcessHyperparameterInitializer(); 109 var bfgsInitializer = new LbfgsInitializer(); 110 var makeStep = new LbfgsMakeStep(); 104 111 var branch = new ConditionalBranch(); 105 112 var modelCreator = new GaussianProcessRegressionModelCreator(); 106 var updateResults = new BFGSUpdateResults();107 var analyzer = new BFGSAnalyzer();113 var updateResults = new LbfgsUpdateResults(); 114 var analyzer = new LbfgsAnalyzer(); 108 115 var finalModelCreator = new GaussianProcessRegressionModelCreator(); 109 var finalAnalyzer = new BFGSAnalyzer();116 var finalAnalyzer = new LbfgsAnalyzer(); 110 117 var solutionCreator = new GaussianProcessRegressionSolutionCreator(); 111 118 112 OperatorGraph.InitialOperator = setParameterLength;119 OperatorGraph.InitialOperator = gpInitializer; 113 120 114 setParameterLength.CovarianceFunctionParameter.ActualName = CovarianceFunctionParameterName; 115 setParameterLength.MeanFunctionParameter.ActualName = MeanFunctionParameterName; 116 setParameterLength.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name; 117 setParameterLength.Successor = initializer; 121 gpInitializer.CovarianceFunctionParameter.ActualName = CovarianceFunctionParameterName; 122 gpInitializer.MeanFunctionParameter.ActualName = MeanFunctionParameterName; 123 gpInitializer.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name; 124 gpInitializer.HyperparameterParameter.ActualName = modelCreator.HyperparameterParameter.Name; 125 gpInitializer.Successor = bfgsInitializer; 118 126 119 initializer.IterationsParameter.ActualName = MinimizationIterationsParameterName;120 initializer.DimensionParameter.ActualName = setParameterLength.NumberOfHyperparameterParameter.Name;121 initializer.PointParameter.ActualName = modelCreator.HyperparameterParameter.Name;122 initializer.Successor = makeStep;127 bfgsInitializer.IterationsParameter.ActualName = MinimizationIterationsParameterName; 128 bfgsInitializer.PointParameter.ActualName = modelCreator.HyperparameterParameter.Name; 129 bfgsInitializer.ApproximateGradientsParameter.ActualName = ApproximateGradientsParameterName; 130 bfgsInitializer.Successor = makeStep; 123 131 124 makeStep. BFGSStateParameter.ActualName = initializer.BFGSStateParameter.Name;132 makeStep.StateParameter.ActualName = bfgsInitializer.StateParameter.Name; 125 133 makeStep.PointParameter.ActualName = modelCreator.HyperparameterParameter.Name; 126 134 makeStep.Successor = branch; … … 135 143 modelCreator.Successor = updateResults; 136 144 137 updateResults. BFGSStateParameter.ActualName = initializer.BFGSStateParameter.Name;145 updateResults.StateParameter.ActualName = bfgsInitializer.StateParameter.Name; 138 146 updateResults.QualityParameter.ActualName = modelCreator.NegativeLogLikelihoodParameter.Name; 139 147 updateResults.QualityGradientsParameter.ActualName = modelCreator.HyperparameterGradientsParameter.Name; 148 updateResults.ApproximateGradientsParameter.ActualName = ApproximateGradientsParameterName; 140 149 updateResults.Successor = analyzer; 141 150 … … 143 152 analyzer.PointParameter.ActualName = modelCreator.HyperparameterParameter.Name; 144 153 analyzer.QualityGradientsParameter.ActualName = modelCreator.HyperparameterGradientsParameter.Name; 145 analyzer. BFGSStateParameter.ActualName = initializer.BFGSStateParameter.Name;154 analyzer.StateParameter.ActualName = bfgsInitializer.StateParameter.Name; 146 155 analyzer.PointsTableParameter.ActualName = "Hyperparameter table"; 147 156 analyzer.QualityGradientsTableParameter.ActualName = "Gradients table"; … … 152 161 finalModelCreator.MeanFunctionParameter.ActualName = MeanFunctionParameterName; 153 162 finalModelCreator.CovarianceFunctionParameter.ActualName = CovarianceFunctionParameterName; 154 finalModelCreator.HyperparameterParameter.ActualName = initializer.PointParameter.ActualName;163 finalModelCreator.HyperparameterParameter.ActualName = bfgsInitializer.PointParameter.ActualName; 155 164 finalModelCreator.Successor = finalAnalyzer; 156 165 -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessRegressionModelCreator.cs
r8375 r8396 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Encodings.RealVectorEncoding; 27 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 28 29 using HeuristicLab.Operators; … … 65 66 ModelParameter.ActualValue = model; 66 67 NegativeLogLikelihoodParameter.ActualValue = new DoubleValue(model.NegativeLogLikelihood); 67 HyperparameterGradientsParameter.ActualValue = new DoubleArray(model.GetHyperparameterGradients());68 HyperparameterGradientsParameter.ActualValue = new RealVector(model.GetHyperparameterGradients()); 68 69 return base.Apply(); 69 70 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/LbfgsAnalyzer.cs
r8375 r8396 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Encodings.RealVectorEncoding; 27 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 28 29 using HeuristicLab.Operators; … … 34 35 namespace HeuristicLab.Algorithms.DataAnalysis { 35 36 [StorableClass] 36 [Item(Name = " BFGSAnalyzer", Description = "Analyzer to collect results for theBFGS algorithm.")]37 public sealed class BFGSAnalyzer : SingleSuccessorOperator, IAnalyzer {37 [Item(Name = "LBFGS Analyzer", Description = "Analyzer to collect results for the LM-BFGS algorithm.")] 38 public sealed class LbfgsAnalyzer : SingleSuccessorOperator, IAnalyzer { 38 39 private const string PointParameterName = "Point"; 39 40 private const string QualityGradientsParameterName = "QualityGradients"; … … 43 44 private const string PointsTableParameterName = "PointTable"; 44 45 private const string QualityGradientsTableParameterName = "QualityGradientsTable"; 45 private const string BFGSStateParameterName = "BFGSState"; 46 private const string StateParameterName = "State"; 47 private const string ApproximateGradientsParameterName = "ApproximateGradients"; 46 48 47 49 #region Parameter Properties 48 public ILookupParameter< DoubleArray> QualityGradientsParameter {49 get { return (ILookupParameter< DoubleArray>)Parameters[QualityGradientsParameterName]; }50 public ILookupParameter<RealVector> QualityGradientsParameter { 51 get { return (ILookupParameter<RealVector>)Parameters[QualityGradientsParameterName]; } 50 52 } 51 public ILookupParameter< DoubleArray> PointParameter {52 get { return (ILookupParameter< DoubleArray>)Parameters[PointParameterName]; }53 public ILookupParameter<RealVector> PointParameter { 54 get { return (ILookupParameter<RealVector>)Parameters[PointParameterName]; } 53 55 } 54 56 public ILookupParameter<DoubleValue> QualityParameter { … … 67 69 get { return (ILookupParameter<DataTable>)Parameters[QualityGradientsTableParameterName]; } 68 70 } 69 public ILookupParameter<BFGSState> BFGSStateParameter { 70 get { return (ILookupParameter<BFGSState>)Parameters[BFGSStateParameterName]; } 71 public ILookupParameter<LbfgsState> StateParameter { 72 get { return (ILookupParameter<LbfgsState>)Parameters[StateParameterName]; } 73 } 74 public ILookupParameter<BoolValue> ApproximateGradientsParameter { 75 get { return (ILookupParameter<BoolValue>)Parameters[ApproximateGradientsParameterName]; } 71 76 } 72 77 #endregion 73 78 74 79 #region Properties 75 private DoubleArrayQualityGradients { get { return QualityGradientsParameter.ActualValue; } }76 private DoubleArrayPoint { get { return PointParameter.ActualValue; } }80 private RealVector QualityGradients { get { return QualityGradientsParameter.ActualValue; } } 81 private RealVector Point { get { return PointParameter.ActualValue; } } 77 82 private DoubleValue Quality { get { return QualityParameter.ActualValue; } } 78 83 private ResultCollection ResultCollection { get { return ResultCollectionParameter.ActualValue; } } 84 private BoolValue ApproximateGradients { get { return ApproximateGradientsParameter.ActualValue; } } 79 85 80 86 public bool EnabledByDefault { … … 85 91 86 92 [StorableConstructor] 87 private BFGSAnalyzer(bool deserializing) : base(deserializing) { }88 private BFGSAnalyzer(BFGSAnalyzer original, Cloner cloner) : base(original, cloner) { }89 public BFGSAnalyzer()93 private LbfgsAnalyzer(bool deserializing) : base(deserializing) { } 94 private LbfgsAnalyzer(LbfgsAnalyzer original, Cloner cloner) : base(original, cloner) { } 95 public LbfgsAnalyzer() 90 96 : base() { 91 97 // in 92 Parameters.Add(new LookupParameter< DoubleArray>(PointParameterName, "The current point of the function to optimize."));93 Parameters.Add(new LookupParameter< DoubleArray>(QualityGradientsParameterName, "The current gradients of the function to optimize."));98 Parameters.Add(new LookupParameter<RealVector>(PointParameterName, "The current point of the function to optimize.")); 99 Parameters.Add(new LookupParameter<RealVector>(QualityGradientsParameterName, "The current gradients of the function to optimize.")); 94 100 Parameters.Add(new LookupParameter<DoubleValue>(QualityParameterName, "The current value of the function to optimize.")); 95 101 Parameters.Add(new LookupParameter<DataTable>(QualitiesTableParameterName, "The table of all visited quality values.")); 96 102 Parameters.Add(new LookupParameter<DataTable>(PointsTableParameterName, "The table of all visited points.")); 97 103 Parameters.Add(new LookupParameter<DataTable>(QualityGradientsTableParameterName, "The table of all visited gradient values.")); 98 Parameters.Add(new LookupParameter<BFGSState>(BFGSStateParameterName, "The state of the BFGS optimization algorithm.")); 104 Parameters.Add(new LookupParameter<LbfgsState>(StateParameterName, "The state of the LM-BFGS optimization algorithm.")); 105 Parameters.Add(new LookupParameter<BoolValue>(ApproximateGradientsParameterName, 106 "Flag that indicates if gradients should be approximated.")); 107 99 108 // in & out 100 109 Parameters.Add(new LookupParameter<ResultCollection>(ResultCollectionParameterName, "The result collection of the algorithm.")); … … 102 111 103 112 public override IDeepCloneable Clone(Cloner cloner) { 104 return new BFGSAnalyzer(this, cloner);113 return new LbfgsAnalyzer(this, cloner); 105 114 } 106 115 107 116 public override IOperation Apply() { 108 if ( BFGSStateParameter.ActualValue.State.xupdated) {117 if (StateParameter.ActualValue.State.xupdated) { 109 118 var f = Quality.Value; 110 var g = QualityGradients.ToArray(); 119 double[] g; 120 if (ApproximateGradients.Value) { 121 g = StateParameter.ActualValue.State.g; 122 } else { 123 g = QualityGradients.ToArray(); 124 } 111 125 var x = Point.ToArray(); 112 126 var resultCollection = ResultCollection; -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/LbfgsInitializer.cs
r8375 r8396 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Encodings.RealVectorEncoding; 27 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 28 29 using HeuristicLab.Operators; … … 33 34 namespace HeuristicLab.Algorithms.DataAnalysis { 34 35 [StorableClass] 35 [Item(Name = "BFGSInitializer", Description = "Initializes the necessary data structures for the BFGS algorithm.")] 36 public sealed class BFGSInitializer : SingleSuccessorOperator { 37 private const string DimensionParameterName = "Dimension"; 36 [Item(Name = "LBFGS Initializer", Description = "Initializes the necessary data structures for the LM-BFGS algorithm.")] 37 public sealed class LbfgsInitializer : SingleSuccessorOperator { 38 38 private const string PointParameterName = "Point"; 39 private const string BFGSStateParameterName = "BFGSState";39 private const string StateParameterName = "State"; 40 40 private const string IterationsParameterName = "Iterations"; 41 private const string ApproximateGradientsParameterName = "ApproximateGradients"; 41 42 42 43 #region Parameter Properties 43 44 // in 44 public ILookupParameter<IntValue> DimensionParameter {45 get { return (ILookupParameter<IntValue>)Parameters[DimensionParameterName]; }46 }47 45 public ILookupParameter<IntValue> IterationsParameter { 48 46 get { return (ILookupParameter<IntValue>)Parameters[IterationsParameterName]; } 49 47 } 48 public ILookupParameter<RealVector> PointParameter { 49 get { return (ILookupParameter<RealVector>)Parameters[PointParameterName]; } 50 } 50 51 // out 51 public ILookupParameter< DoubleArray> PointParameter {52 get { return (ILookupParameter< DoubleArray>)Parameters[PointParameterName]; }52 public ILookupParameter<LbfgsState> StateParameter { 53 get { return (ILookupParameter<LbfgsState>)Parameters[StateParameterName]; } 53 54 } 54 public ILookupParameter<B FGSState> BFGSStateParameter {55 get { return (ILookupParameter<B FGSState>)Parameters[BFGSStateParameterName]; }55 public ILookupParameter<BoolValue> ApproximateGradientsParameter { 56 get { return (ILookupParameter<BoolValue>)Parameters[ApproximateGradientsParameterName]; } 56 57 } 57 58 … … 60 61 61 62 #region Properties 62 private IntValue Dimension { get { return DimensionParameter.ActualValue; } }63 private RealVector Point { get { return PointParameter.ActualValue; } } 63 64 private IntValue Iterations { get { return IterationsParameter.ActualValue; } } 65 private BoolValue ApproximateGradients { get { return ApproximateGradientsParameter.ActualValue; } } 64 66 #endregion 65 67 66 68 [StorableConstructor] 67 private BFGSInitializer(bool deserializing) : base(deserializing) { }68 private BFGSInitializer(BFGSInitializer original, Cloner cloner) : base(original, cloner) { }69 public BFGSInitializer()69 private LbfgsInitializer(bool deserializing) : base(deserializing) { } 70 private LbfgsInitializer(LbfgsInitializer original, Cloner cloner) : base(original, cloner) { } 71 public LbfgsInitializer() 70 72 : base() { 71 73 // in 72 Parameters.Add(new LookupParameter<IntValue>(DimensionParameterName, "The length of the vector to optimize.")); 73 Parameters.Add(new LookupParameter<IntValue>(IterationsParameterName, "The maximal number of iterations for the BFGS algorithm.")); 74 Parameters.Add(new LookupParameter<RealVector>(PointParameterName, "The initial point for the LM-BFGS algorithm.")); 75 Parameters.Add(new LookupParameter<IntValue>(IterationsParameterName, "The maximal number of iterations for the LM-BFGS algorithm.")); 76 Parameters.Add(new LookupParameter<BoolValue>(ApproximateGradientsParameterName, 77 "Flag that indicates if gradients should be approximated.")); 74 78 // out 75 Parameters.Add(new LookupParameter<DoubleArray>(PointParameterName, "The initial point for the BFGS algorithm.")); 76 Parameters.Add(new LookupParameter<BFGSState>(BFGSStateParameterName, "The state of the BFGS algorithm.")); 79 Parameters.Add(new LookupParameter<LbfgsState>(StateParameterName, "The state of the LM-BFGS algorithm.")); 77 80 } 78 81 79 82 public override IDeepCloneable Clone(Cloner cloner) { 80 return new BFGSInitializer(this, cloner);83 return new LbfgsInitializer(this, cloner); 81 84 } 82 85 83 86 public override IOperation Apply() { 84 int n = Dimension.Value;85 double[] initialPoint = Enumerable.Repeat(0.0, n).ToArray();87 double[] initialPoint = Point.ToArray(); 88 int n = initialPoint.Length; 86 89 alglib.minlbfgs.minlbfgsstate state = new alglib.minlbfgs.minlbfgsstate(); 87 alglib.minlbfgs.minlbfgscreate(n, Math.Min(n, 7), initialPoint, state); 90 if (ApproximateGradients.Value) { 91 alglib.minlbfgs.minlbfgscreatef(n, Math.Min(n, 7), initialPoint, 1E-5, state); 92 } else { 93 alglib.minlbfgs.minlbfgscreate(n, Math.Min(n, 7), initialPoint, state); 94 } 88 95 alglib.minlbfgs.minlbfgssetcond(state, 0, 0, 0, Iterations.Value); 89 96 alglib.minlbfgs.minlbfgssetxrep(state, true); 90 97 91 PointParameter.ActualValue = new DoubleArray(initialPoint);92 BFGSStateParameter.ActualValue = new BFGSState(state);98 PointParameter.ActualValue = new RealVector(initialPoint); 99 StateParameter.ActualValue = new LbfgsState(state); 93 100 return base.Apply(); 94 101 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/LbfgsMakeStep.cs
r8375 r8396 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Data; 26 using HeuristicLab.Encodings.RealVectorEncoding; 26 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 28 using HeuristicLab.Operators; … … 32 33 namespace HeuristicLab.Algorithms.DataAnalysis { 33 34 [StorableClass] 34 [Item(Name = " BFGSMakeStep", Description = "Makes a step in theBFGS optimization algorithm.")]35 public sealed class BFGSMakeStep : SingleSuccessorOperator {35 [Item(Name = "LBFGS MakeStep", Description = "Makes a step in the LM-BFGS optimization algorithm.")] 36 public sealed class LbfgsMakeStep : SingleSuccessorOperator { 36 37 private const string TerminationCriterionParameterName = "TerminationCriterion"; 37 38 private const string PointParameterName = "Point"; 38 private const string BFGSStateParameterName = "BFGSState";39 private const string StateParameterName = "State"; 39 40 40 41 #region Parameter Properties 41 public ILookupParameter< BFGSState> BFGSStateParameter {42 get { return (ILookupParameter< BFGSState>)Parameters[BFGSStateParameterName]; }42 public ILookupParameter<LbfgsState> StateParameter { 43 get { return (ILookupParameter<LbfgsState>)Parameters[StateParameterName]; } 43 44 } 44 45 public ILookupParameter<BoolValue> TerminationCriterionParameter { 45 46 get { return (ILookupParameter<BoolValue>)Parameters[TerminationCriterionParameterName]; } 46 47 } 47 public ILookupParameter< DoubleArray> PointParameter {48 get { return (ILookupParameter< DoubleArray>)Parameters[PointParameterName]; }48 public ILookupParameter<RealVector> PointParameter { 49 get { return (ILookupParameter<RealVector>)Parameters[PointParameterName]; } 49 50 } 50 51 #endregion … … 52 53 53 54 #region Properties 54 private BFGSState BFGSState { get { return BFGSStateParameter.ActualValue; } }55 private LbfgsState State { get { return StateParameter.ActualValue; } } 55 56 #endregion 56 57 57 58 [StorableConstructor] 58 private BFGSMakeStep(bool deserializing) : base(deserializing) { }59 private BFGSMakeStep(BFGSMakeStep original, Cloner cloner) : base(original, cloner) { }60 public BFGSMakeStep()59 private LbfgsMakeStep(bool deserializing) : base(deserializing) { } 60 private LbfgsMakeStep(LbfgsMakeStep original, Cloner cloner) : base(original, cloner) { } 61 public LbfgsMakeStep() 61 62 : base() { 62 63 // in & out 63 Parameters.Add(new LookupParameter< BFGSState>(BFGSStateParameterName, "The state of theBFGS algorithm."));64 Parameters.Add(new LookupParameter<LbfgsState>(StateParameterName, "The state of the LM-BFGS algorithm.")); 64 65 // out 65 Parameters.Add(new LookupParameter<BoolValue>(TerminationCriterionParameterName, "The termination criterion indicating that the BFGS optimization algorithm should stop."));66 Parameters.Add(new LookupParameter< DoubleArray>(PointParameterName, "The next point that should be evaluated in theBFGS algorithm."));66 Parameters.Add(new LookupParameter<BoolValue>(TerminationCriterionParameterName, "The termination criterion indicating that the LM-BFGS optimization algorithm should stop.")); 67 Parameters.Add(new LookupParameter<RealVector>(PointParameterName, "The next point that should be evaluated in the LM-BFGS algorithm.")); 67 68 } 68 69 69 70 public override IDeepCloneable Clone(Cloner cloner) { 70 return new BFGSMakeStep(this, cloner);71 return new LbfgsMakeStep(this, cloner); 71 72 } 72 73 73 74 public override IOperation Apply() { 74 var state = BFGSState;75 var state = State; 75 76 bool @continue = alglib.minlbfgs.minlbfgsiteration(state.State); 76 77 TerminationCriterionParameter.ActualValue = new BoolValue(!@continue); 77 78 if (@continue) { 78 PointParameter.ActualValue = new DoubleArray(state.State.x);79 PointParameter.ActualValue = new RealVector(state.State.x); 79 80 } else { 80 81 double[] x = new double[state.State.x.Length]; 81 82 alglib.minlbfgs.minlbfgsreport rep = new alglib.minlbfgs.minlbfgsreport(); 82 83 alglib.minlbfgs.minlbfgsresults(state.State, ref x, rep); 83 PointParameter.ActualValue = new DoubleArray(x);84 PointParameter.ActualValue = new RealVector(x); 84 85 } 85 86 return base.Apply(); -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/LbfgsState.cs
r8372 r8396 34 34 namespace HeuristicLab.Algorithms.DataAnalysis { 35 35 [StorableClass] 36 [Item(" BFGSState", "Internal state for theBFGS optimization algorithm.")]37 public sealed class BFGSState : Item {36 [Item("LbfgsState", "Internal state for the limited-memory BFGS optimization algorithm.")] 37 public sealed class LbfgsState : Item { 38 38 private alglib.minlbfgs.minlbfgsstate state; 39 39 public alglib.minlbfgs.minlbfgsstate State { get { return state; } } 40 40 41 41 [StorableConstructor] 42 private BFGSState(bool deserializing)42 private LbfgsState(bool deserializing) 43 43 : base(deserializing) { 44 44 state = new alglib.minlbfgs.minlbfgsstate(); 45 45 } 46 private BFGSState(BFGSState original, Cloner cloner)46 private LbfgsState(LbfgsState original, Cloner cloner) 47 47 : base(original, cloner) { 48 48 this.state = new alglib.minlbfgs.minlbfgsstate(); … … 125 125 } 126 126 127 public BFGSState(alglib.minlbfgs.minlbfgsstate state)127 public LbfgsState(alglib.minlbfgs.minlbfgsstate state) 128 128 : base() { 129 129 this.state = state; … … 131 131 132 132 public override IDeepCloneable Clone(Cloner cloner) { 133 return new BFGSState(this, cloner);133 return new LbfgsState(this, cloner); 134 134 } 135 135 -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/LbfgsUpdateResults.cs
r8375 r8396 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Data; 26 using HeuristicLab.Encodings.RealVectorEncoding; 26 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 28 using HeuristicLab.Operators; … … 32 33 namespace HeuristicLab.Algorithms.DataAnalysis { 33 34 [StorableClass] 34 [Item(Name = " BFGSUpdateResults", Description = "Sets the results (function value and gradients) for the next optimization step in theBFGS algorithm.")]35 public sealed class BFGSUpdateResults : SingleSuccessorOperator {35 [Item(Name = "LBFGS UpdateResults", Description = "Sets the results (function value and gradients) for the next optimization step in the LM-BFGS algorithm.")] 36 public sealed class LbfgsUpdateResults : SingleSuccessorOperator { 36 37 private const string QualityGradientsParameterName = "QualityGradients"; 37 38 private const string QualityParameterName = "Quality"; 38 private const string BFGSStateParameterName = "BFGSState"; 39 private const string StateParameterName = "State"; 40 private const string ApproximateGradientsParameterName = "ApproximateGradients"; 39 41 40 42 #region Parameter Properties 41 public ILookupParameter<DoubleArray> QualityGradientsParameter { 42 get { return (ILookupParameter<DoubleArray>)Parameters[QualityGradientsParameterName]; } 43 public ILookupParameter<BoolValue> ApproximateGradientsParameter { 44 get { return (ILookupParameter<BoolValue>)Parameters[ApproximateGradientsParameterName]; } 45 } 46 public ILookupParameter<RealVector> QualityGradientsParameter { 47 get { return (ILookupParameter<RealVector>)Parameters[QualityGradientsParameterName]; } 43 48 } 44 49 public ILookupParameter<DoubleValue> QualityParameter { 45 50 get { return (ILookupParameter<DoubleValue>)Parameters[QualityParameterName]; } 46 51 } 47 public ILookupParameter< BFGSState> BFGSStateParameter {48 get { return (ILookupParameter< BFGSState>)Parameters[BFGSStateParameterName]; }52 public ILookupParameter<LbfgsState> StateParameter { 53 get { return (ILookupParameter<LbfgsState>)Parameters[StateParameterName]; } 49 54 } 50 55 #endregion 51 56 52 57 #region Properties 53 private DoubleArray QualityGradients { get { return QualityGradientsParameter.ActualValue; } } 58 private BoolValue ApproximateGradients { get { return ApproximateGradientsParameter.ActualValue; } } 59 private RealVector QualityGradients { get { return QualityGradientsParameter.ActualValue; } } 54 60 private DoubleValue Quality { get { return QualityParameter.ActualValue; } } 55 private BFGSState BFGSState { get { return BFGSStateParameter.ActualValue; } }61 private LbfgsState State { get { return StateParameter.ActualValue; } } 56 62 #endregion 57 63 58 64 [StorableConstructor] 59 private BFGSUpdateResults(bool deserializing) : base(deserializing) { }60 private BFGSUpdateResults(BFGSUpdateResults original, Cloner cloner) : base(original, cloner) { }61 public BFGSUpdateResults()65 private LbfgsUpdateResults(bool deserializing) : base(deserializing) { } 66 private LbfgsUpdateResults(LbfgsUpdateResults original, Cloner cloner) : base(original, cloner) { } 67 public LbfgsUpdateResults() 62 68 : base() { 63 69 // in 64 Parameters.Add(new LookupParameter< DoubleArray>(QualityGradientsParameterName, "The gradients at the evaluated point of the function to optimize."));70 Parameters.Add(new LookupParameter<RealVector>(QualityGradientsParameterName, "The gradients at the evaluated point of the function to optimize.")); 65 71 Parameters.Add(new LookupParameter<DoubleValue>(QualityParameterName, "The value at the evaluated point of the function to optimize.")); 72 Parameters.Add(new LookupParameter<BoolValue>(ApproximateGradientsParameterName, 73 "Flag that indicates if gradients should be approximated.")); 66 74 // in & out 67 Parameters.Add(new LookupParameter< BFGSState>(BFGSStateParameterName, "The state of theBFGS algorithm."));75 Parameters.Add(new LookupParameter<LbfgsState>(StateParameterName, "The state of the LM-BFGS algorithm.")); 68 76 } 69 77 70 78 public override IDeepCloneable Clone(Cloner cloner) { 71 return new BFGSUpdateResults(this, cloner);79 return new LbfgsUpdateResults(this, cloner); 72 80 } 73 81 74 82 public override IOperation Apply() { 75 var state = BFGSState;83 var state = State; 76 84 var f = Quality.Value; 77 var g = QualityGradients.ToArray();78 85 state.State.f = f; 79 state.State.g = g; 86 if (!ApproximateGradients.Value) { 87 var g = QualityGradients.ToArray(); 88 state.State.g = g; 89 } 80 90 return base.Apply(); 81 91 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/HeuristicLab.Algorithms.DataAnalysis-3.4.csproj
r8375 r8396 122 122 </Compile> 123 123 <Compile Include="FixedDataAnalysisAlgorithm.cs" /> 124 <Compile Include="GaussianProcess\BFGSInitializer.cs" /> 125 <Compile Include="GaussianProcess\BFGSState.cs" /> 126 <Compile Include="GaussianProcess\BFGSUpdateResults.cs" /> 127 <Compile Include="GaussianProcess\BFGSMakeStep.cs" /> 128 <Compile Include="GaussianProcess\BFGSAnalyzer.cs" /> 124 <Compile Include="GaussianProcess\Lbfgs.cs" /> 125 <Compile Include="GaussianProcess\LbfgsInitializer.cs" /> 126 <Compile Include="GaussianProcess\LbfgsState.cs" /> 127 <Compile Include="GaussianProcess\LbfgsUpdateResults.cs" /> 128 <Compile Include="GaussianProcess\LbfgsMakeStep.cs" /> 129 <Compile Include="GaussianProcess\LbfgsAnalyzer.cs" /> 130 <Compile Include="GaussianProcess\GaussianProcessHyperparameterInitializer.cs" /> 129 131 <Compile Include="GaussianProcess\GaussianProcessRegressionSolutionCreator.cs" /> 130 <Compile Include="GaussianProcess\GaussianProcessSetHyperparameterLength.cs" />131 132 <Compile Include="GaussianProcess\GaussianProcessRegressionModelCreator.cs" /> 132 133 <Compile Include="GaussianProcess\CovarianceLinear.cs" /> … … 243 244 <Private>False</Private> 244 245 </ProjectReference> 246 <ProjectReference Include="..\..\HeuristicLab.Encodings.RealVectorEncoding\3.3\HeuristicLab.Encodings.RealVectorEncoding-3.3.csproj"> 247 <Project>{BB6D334A-4BB6-4674-9883-31A6EBB32CAB}</Project> 248 <Name>HeuristicLab.Encodings.RealVectorEncoding-3.3</Name> 249 </ProjectReference> 245 250 <ProjectReference Include="..\..\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding\3.4\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj"> 246 251 <Project>{06D4A186-9319-48A0-BADE-A2058D462EEA}</Project> … … 300 305 <Name>HeuristicLab.Problems.Instances-3.3</Name> 301 306 <Private>False</Private> 307 </ProjectReference> 308 <ProjectReference Include="..\..\HeuristicLab.Problems.TestFunctions\3.3\HeuristicLab.Problems.TestFunctions-3.3.csproj"> 309 <Project>{88B9B0E3-344E-4196-82A3-0F9732506FE8}</Project> 310 <Name>HeuristicLab.Problems.TestFunctions-3.3</Name> 302 311 </ProjectReference> 303 312 <ProjectReference Include="..\..\HeuristicLab.Random\3.3\HeuristicLab.Random-3.3.csproj"> -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Plugin.cs.frame
r8375 r8396 37 37 [PluginDependency("HeuristicLab.Data", "3.3")] 38 38 [PluginDependency("HeuristicLab.Encodings.SymbolicExpressionTreeEncoding", "3.4")] 39 [PluginDependency("HeuristicLab.Encodings.RealVectorEncoding", "3.3")] 39 40 [PluginDependency("HeuristicLab.Operators", "3.3")] 40 41 [PluginDependency("HeuristicLab.Optimization", "3.3")] -
trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/Plugin.cs.frame
r8246 r8396 40 40 [PluginDependency("HeuristicLab.Random", "3.3")] 41 41 [PluginDependency("HeuristicLab.Selection", "3.3")] 42 [PluginDependency("HeuristicLab.Problems.TestFunctions", "3.3")] 42 43 public class HeuristicLabAlgorithmsGeneticAlgorithmPlugin : PluginBase { 43 44 }
Note: See TracChangeset
for help on using the changeset viewer.