Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/14/12 13:25:17 (12 years ago)
Author:
gkronber
Message:

#1902 changed interface for covariance functions to improve readability, fixed several bugs in the covariance functions and in the line chart for Gaussian process models.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceSum.cs

    r8463 r8484  
    7777
    7878    public void SetParameter(double[] hyp) {
     79      if (terms.Count == 0) throw new ArgumentException("At least one term is needed for sum covariance function.");
    7980      int offset = 0;
    8081      foreach (var t in terms) {
     
    8485      }
    8586    }
    86     public void SetData(double[,] x) {
    87       SetData(x, x);
    88     }
    8987
    90     public void SetData(double[,] x, double[,] xt) {
    91       foreach (var t in terms) {
    92         t.SetData(x, xt);
    93       }
    94     }
    95 
    96     public double GetCovariance(int i, int j) {
    97       return terms.Select(t => t.GetCovariance(i, j)).Sum();
     88    public double GetCovariance(double[,] x, int i, int j) {
     89      return terms.Select(t => t.GetCovariance(x, i, j)).Sum();
    9890    }
    9991
    10092    private Dictionary<int, Tuple<int, int>> cachedParameterMap;
    101     public double GetGradient(int i, int j, int k) {
    102       if (cachedParameterMap == null) {
    103         CalculateParameterMap();
    104       }
    105       int ti = cachedParameterMap[k].Item1;
    106       k = cachedParameterMap[k].Item2;
    107       return terms[ti].GetGradient(i, j, k);
     93    public IEnumerable<double> GetGradient(double[,] x, int i, int j) {
     94      //if (cachedParameterMap == null) {
     95      //  CalculateParameterMap();
     96      //}
     97      //int ti = cachedParameterMap[k].Item1;
     98      //k = cachedParameterMap[k].Item2;
     99      //return terms[ti].GetGradient(x, i, j, k);
     100      return terms.Select(t => t.GetGradient(x, i, j)).Aggregate(Enumerable.Concat);
    108101    }
     102
     103    public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j) {
     104      return terms.Select(t => t.GetCrossCovariance(x, xt, i, j)).Sum();
     105    }
     106
    109107    private void ClearCache() {
    110108      cachedParameterMap = null;
    111109    }
    112110
    113     private void CalculateParameterMap() {
    114       cachedParameterMap = new Dictionary<int, Tuple<int, int>>();
    115       int k = 0;
    116       for (int ti = 0; ti < terms.Count; ti++) {
    117         for (int ti_k = 0; ti_k < terms[ti].GetNumberOfParameters(numberOfVariables); ti_k++) {
    118           cachedParameterMap[k++] = Tuple.Create(ti, ti_k);
    119         }
    120       }
    121     }
     111    //private void CalculateParameterMap() {
     112    //  cachedParameterMap = new Dictionary<int, Tuple<int, int>>();
     113    //  int k = 0;
     114    //  for (int ti = 0; ti < terms.Count; ti++) {
     115    //    for (int ti_k = 0; ti_k < terms[ti].GetNumberOfParameters(numberOfVariables); ti_k++) {
     116    //      cachedParameterMap[k++] = Tuple.Create(ti, ti_k);
     117    //    }
     118    //  }
     119    //}
    122120  }
    123121}
Note: See TracChangeset for help on using the changeset viewer.