Changeset 9360 for trunk/sources/HeuristicLab.Algorithms.DataAnalysis
- Timestamp:
- 04/15/13 15:07:16 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunctions/CovarianceNeuralNetwork.cs
r9359 r9360 40 40 } 41 41 42 public IValueParameter<DoubleValue> InverseLengthParameter {43 get { return (IValueParameter<DoubleValue>)Parameters[" InverseLength"]; }42 public IValueParameter<DoubleValue> LengthParameter { 43 get { return (IValueParameter<DoubleValue>)Parameters["Length"]; } 44 44 } 45 45 … … 59 59 60 60 Parameters.Add(new OptionalValueParameter<DoubleValue>("Scale", "The scale parameter.")); 61 Parameters.Add(new OptionalValueParameter<DoubleValue>(" InverseLength", "The inverse length parameter."));61 Parameters.Add(new OptionalValueParameter<DoubleValue>("Length", "The length parameter.")); 62 62 } 63 63 … … 69 69 return 70 70 (ScaleParameter.Value != null ? 0 : 1) + 71 ( InverseLengthParameter.Value != null ? 0 : 1);71 (LengthParameter.Value != null ? 0 : 1); 72 72 } 73 73 74 74 public void SetParameter(double[] p) { 75 double scale, inverseLength;76 GetParameterValues(p, out scale, out inverseLength);75 double scale, length; 76 GetParameterValues(p, out scale, out length); 77 77 ScaleParameter.Value = new DoubleValue(scale); 78 InverseLengthParameter.Value = new DoubleValue(inverseLength);78 LengthParameter.Value = new DoubleValue(length); 79 79 } 80 80 81 81 82 private void GetParameterValues(double[] p, out double scale, out double inverseLength) {82 private void GetParameterValues(double[] p, out double scale, out double length) { 83 83 // gather parameter values 84 84 int c = 0; 85 if ( InverseLengthParameter.Value != null) {86 inverseLength = InverseLengthParameter.Value.Value;85 if (LengthParameter.Value != null) { 86 length = LengthParameter.Value.Value; 87 87 } else { 88 inverseLength = 1.0 / Math.Exp(p[c]);88 length = Math.Exp(2 * p[c]); 89 89 c++; 90 90 } … … 105 105 private static Func<Term, UnaryFunc> sqrt = UnaryFunc.Factory( 106 106 x => Math.Sqrt(x), 107 x => 1 / 2 * Math.Sqrt(x));107 x => 1 / (2 * Math.Sqrt(x))); 108 108 109 109 public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices) { 110 double inverseLength, scale;111 GetParameterValues(p, out scale, out inverseLength);110 double length, scale; 111 GetParameterValues(p, out scale, out length); 112 112 // create functions 113 113 AutoDiff.Variable p0 = new AutoDiff.Variable(); 114 114 AutoDiff.Variable p1 = new AutoDiff.Variable(); 115 var invL = 1.0 / TermBuilder.Exp(p0);116 var s = TermBuilder.Exp(2 * p1);115 var l = TermBuilder.Exp(2.0 * p0); 116 var s = TermBuilder.Exp(2.0 * p1); 117 117 AutoDiff.Variable[] x1 = new AutoDiff.Variable[columnIndices.Count()]; 118 118 AutoDiff.Variable[] x2 = new AutoDiff.Variable[columnIndices.Count()]; 119 AutoDiff.Term sx = invL;120 AutoDiff.Term s1 = invL;121 AutoDiff.Term s2 = invL;119 AutoDiff.Term sx = 1; 120 AutoDiff.Term s1 = 1; 121 AutoDiff.Term s2 = 1; 122 122 foreach (var k in columnIndices) { 123 123 x1[k] = new AutoDiff.Variable(); 124 124 x2[k] = new AutoDiff.Variable(); 125 sx += x1[k] * invL *x2[k];126 s1 += x1[k] * invL *x1[k];127 s2 += x2[k] * invL *x2[k];125 sx += x1[k] * x2[k]; 126 s1 += x1[k] * x1[k]; 127 s2 += x2[k] * x2[k]; 128 128 } 129 129 130 130 var parameter = x1.Concat(x2).Concat(new AutoDiff.Variable[] { p0, p1 }).ToArray(); 131 131 var values = new double[x1.Length + x2.Length + 2]; 132 var c = (s * asin( 2 * sx / (sqrt((1 + 2 * s1) * (1 + 2 *s2))))).Compile(parameter);132 var c = (s * asin(sx / (sqrt((l + s1) * (l + s2))))).Compile(parameter); 133 133 134 134 var cov = new ParameterizedCovarianceFunction(); … … 143 143 k++; 144 144 } 145 values[k] = Math.Log( 1.0 / inverseLength);146 values[k + 1] = Math.Log( scale) / 2.0;145 values[k] = Math.Log(Math.Sqrt(length)); 146 values[k + 1] = Math.Log(Math.Sqrt(scale)); 147 147 return c.Evaluate(values); 148 148 }; … … 157 157 k++; 158 158 } 159 values[k] = Math.Log( 1.0 / inverseLength);160 values[k + 1] = Math.Log( scale) / 2.0;159 values[k] = Math.Log(Math.Sqrt(length)); 160 values[k + 1] = Math.Log(Math.Sqrt(scale)); 161 161 return c.Evaluate(values); 162 162 }; … … 171 171 k++; 172 172 } 173 values[k] = Math.Log( 1.0 / inverseLength);174 values[k + 1] = Math.Log( scale) / 2.0;173 values[k] = Math.Log(Math.Sqrt(length)); 174 values[k + 1] = Math.Log(Math.Sqrt(scale)); 175 175 return c.Differentiate(values).Item1.Skip(columnIndices.Count() * 2); 176 176 };
Note: See TracChangeset
for help on using the changeset viewer.