Changeset 9516 for trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions
- Timestamp:
- 05/23/13 08:33:12 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovariancePolynomial.cs
r9515 r9516 34 34 Description = "Polynomial covariance function for Gaussian processes.")] 35 35 public sealed class CovariancePolynomial : ParameterizedNamedItem, ICovarianceFunction { 36 public IValueParameter<DoubleValue> C Parameter {37 get { return (IValueParameter<DoubleValue>)Parameters["C "]; }36 public IValueParameter<DoubleValue> ConstParameter { 37 get { return (IValueParameter<DoubleValue>)Parameters["Const"]; } 38 38 } 39 39 … … 60 60 Description = ItemDescription; 61 61 62 Parameters.Add(new OptionalValueParameter<DoubleValue>("C ", "Parameter for the additive constant in the polymomial."));62 Parameters.Add(new OptionalValueParameter<DoubleValue>("Const", "Additive constant in the polymomial.")); 63 63 Parameters.Add(new OptionalValueParameter<DoubleValue>("Scale", "The scale parameter of the Polynomial covariance function.")); 64 64 Parameters.Add(new ValueParameter<IntValue>("Degree", "The degree of the polynomial (only non-zero positive values allowed).", new IntValue(2))); … … 71 71 public int GetNumberOfParameters(int numberOfVariables) { 72 72 return 73 (C Parameter.Value != null ? 0 : 1) +73 (ConstParameter.Value != null ? 0 : 1) + 74 74 (ScaleParameter.Value != null ? 0 : 1); 75 75 } 76 76 77 77 public void SetParameter(double[] p) { 78 double c, scale;79 GetParameterValues(p, out c, out scale);80 C Parameter.Value = new DoubleValue(c);78 double @const, scale; 79 GetParameterValues(p, out @const, out scale); 80 ConstParameter.Value = new DoubleValue(@const); 81 81 ScaleParameter.Value = new DoubleValue(scale); 82 82 } 83 83 84 private void GetParameterValues(double[] p, out double c, out double scale) {84 private void GetParameterValues(double[] p, out double @const, out double scale) { 85 85 // gather parameter values 86 86 int n = 0; 87 if (C Parameter.Value != null) {88 c = CParameter.Value.Value;87 if (ConstParameter.Value != null) { 88 @const = ConstParameter.Value.Value; 89 89 } else { 90 c= Math.Exp(p[n]);90 @const = Math.Exp(p[n]); 91 91 n++; 92 92 } … … 102 102 103 103 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices) { 104 double c, scale;105 int d = DegreeParameter.Value.Value;106 if (d <= 0) throw new ArgumentException("The degree parameter for CovariancePolynomial must be greater than zero.");107 GetParameterValues(p, out c, out scale);104 double @const, scale; 105 int degree = DegreeParameter.Value.Value; 106 if (degree <= 0) throw new ArgumentException("The degree parameter for CovariancePolynomial must be greater than zero."); 107 GetParameterValues(p, out @const, out scale); 108 108 // create functions 109 109 var cov = new ParameterizedCovarianceFunction(); 110 cov.Covariance = (x, i, j) => scale * Math.Pow( c + Util.ScalarProd(x, i, j, 1.0, columnIndices), d);111 cov.CrossCovariance = (x, xt, i, j) => scale * Math.Pow( c + Util.ScalarProd(x, i, xt, j, 1.0, columnIndices), d);112 cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, c, scale, d, columnIndices);110 cov.Covariance = (x, i, j) => scale * Math.Pow(@const + Util.ScalarProd(x, i, j, 1.0, columnIndices), degree); 111 cov.CrossCovariance = (x, xt, i, j) => scale * Math.Pow(@const + Util.ScalarProd(x, i, xt, j, 1.0, columnIndices), degree); 112 cov.CovarianceGradient = (x, i, j) => GetGradient(x, i, j, @const, scale, degree, columnIndices); 113 113 return cov; 114 114 }
Note: See TracChangeset
for help on using the changeset viewer.