Changeset 8416 for trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceLinear.cs
- Timestamp:
- 08/06/12 15:02:34 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceLinear.cs
r8401 r8416 29 29 [Item(Name = "CovarianceLinear", Description = "Linear covariance function with for Gaussian processes.")] 30 30 public class CovarianceLinear : Item, ICovarianceFunction { 31 private static readonly double[] emptyArray = new double[0]; 32 31 33 [Storable] 32 34 private double[,] x; 33 35 [Storable] 34 36 private double[,] xt; 35 36 37 37 38 private double[,] k; … … 45 46 protected CovarianceLinear(CovarianceLinear original, Cloner cloner) 46 47 : base(original, cloner) { 47 // note: using shallow copies here!48 this.x = original.x;49 this.xt = original.xt;48 if (original.x != null) { 49 this.x = new double[original.x.GetLength(0), original.x.GetLength(1)]; 50 Array.Copy(original.x, this.x, x.Length); 50 51 52 this.xt = new double[original.xt.GetLength(0), original.xt.GetLength(1)]; 53 Array.Copy(original.xt, this.xt, xt.Length); 54 55 this.k = new double[original.k.GetLength(0), original.k.GetLength(1)]; 56 Array.Copy(original.k, this.k, k.Length); 57 } 58 this.symmetric = original.symmetric; 51 59 } 52 60 public CovarianceLinear() … … 58 66 } 59 67 60 public void SetParameter(double[] hyp, double[,] x) { 61 if (hyp.Length > 0) throw new ArgumentException(); 62 SetParameter(hyp, x, x); 68 public void SetParameter(double[] hyp) { 69 if (hyp.Length > 0) throw new ArgumentException("No hyperparameters are allowed for the linear covariance function."); 70 k = null; 71 } 72 73 public void SetData(double[,] x) { 74 SetData(x, x); 63 75 this.symmetric = true; 64 76 } 65 77 66 public void Set Parameter(double[] hyp,double[,] x, double[,] xt) {78 public void SetData(double[,] x, double[,] xt) { 67 79 this.x = x; 68 80 this.xt = xt; … … 77 89 } 78 90 79 80 public double[] GetDiagonalCovariances() {81 if (x != xt) throw new InvalidOperationException();82 int rows = x.GetLength(0);83 int cols = x.GetLength(1);84 var k = new double[rows];85 for (int i = 0; i < rows; i++) {86 k[i] = 0;87 for (int j = 0; j < cols; j++) {88 k[i] += x[i, j] * x[i, j];89 }90 }91 return k;92 }93 94 91 public double[] GetGradient(int i, int j) { 95 throw new NotSupportedException();92 return emptyArray; 96 93 } 97 94
Note: See TracChangeset
for help on using the changeset viewer.