Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8489


Ignore:
Timestamp:
08/14/12 15:24:30 (12 years ago)
Author:
gkronber
Message:

#1902 removed caches in product and sum covariance functions and fixed bug in SE-ARD covariance function

Location:
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess
Files:
3 edited

Legend:

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

    r8484 r8489  
    5050      this.factors = cloner.Clone(original.factors);
    5151      this.numberOfVariables = original.numberOfVariables;
    52       AttachEventHandlers();
    5352    }
    5453
     
    5655      : base() {
    5756      this.factors = new ItemList<ICovarianceFunction>();
    58       AttachEventHandlers();
    59     }
    60 
    61     private void AttachEventHandlers() {
    62       this.factors.CollectionReset += (sender, args) => ClearCache();
    63       this.factors.ItemsAdded += (sender, args) => ClearCache();
    64       this.factors.ItemsRemoved += (sender, args) => ClearCache();
    65       this.factors.ItemsReplaced += (sender, args) => ClearCache();
    66       this.factors.ItemsMoved += (sender, args) => ClearCache();
    6757    }
    6858
     
    9181
    9282    public IEnumerable<double> GetGradient(double[,] x, int i, int j) {
    93       //if (cachedParameterMap == null) {
    94       //  CalculateParameterMap();
    95       //}
    96       //int ti = cachedParameterMap[k].Item1;
    97       //k = cachedParameterMap[k].Item2;
    98       //double gradient = 1.0;
    99       //for (int ii = 0; ii < factors.Count; ii++) {
    100       //  var f = factors[ii];
    101       //  if (ii == ti) {
    102       //    gradient *= f.GetGradient(x, i, j, k);
    103       //  } else {
    104       //    gradient *= f.GetCovariance(x, i, j);
    105       //  }
    106       //}
    107       //return gradient;
    10883      var covariances = factors.Select(f => f.GetCovariance(x, i, j)).ToArray();
    10984      for (int ii = 0; ii < factors.Count; ii++) {
     
    12095      return factors.Select(f => f.GetCrossCovariance(x, xt, i, j)).Aggregate((a, b) => a * b);
    12196    }
    122 
    123     private Dictionary<int, Tuple<int, int>> cachedParameterMap;
    124     private void ClearCache() {
    125       cachedParameterMap = null;
    126     }
    127 
    128     private void CalculateParameterMap() {
    129       cachedParameterMap = new Dictionary<int, Tuple<int, int>>();
    130       int k = 0;
    131       for (int ti = 0; ti < factors.Count; ti++) {
    132         for (int ti_k = 0; ti_k < factors[ti].GetNumberOfParameters(numberOfVariables); ti_k++) {
    133           cachedParameterMap[k++] = Tuple.Create(ti, ti_k);
    134         }
    135       }
    136     }
    13797  }
    13898}
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceSEard.cs

    r8484 r8489  
    8888      for (int ii = 0; ii < l.Length; ii++) {
    8989        double sqrDist = Util.SqrDist(x[i, ii] / l[ii], x[j, ii] / l[ii]);
    90         yield return sf2 * Math.Exp(d / 2.0) * sqrDist;
     90        yield return sf2 * Math.Exp(-d / 2.0) * sqrDist;
    9191      }
    92       yield return 2.0 * sf2 * Math.Exp(d / 2.0);
     92      yield return 2.0 * sf2 * Math.Exp(-d / 2.0);
    9393    }
    9494
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceSum.cs

    r8484 r8489  
    5050      this.terms = cloner.Clone(original.terms);
    5151      this.numberOfVariables = original.numberOfVariables;
    52       AttachEventHandlers();
    5352    }
    5453
     
    5655      : base() {
    5756      this.terms = new ItemList<ICovarianceFunction>();
    58       AttachEventHandlers();
    59     }
    60 
    61     private void AttachEventHandlers() {
    62       this.terms.CollectionReset += (sender, args) => ClearCache();
    63       this.terms.ItemsAdded += (sender, args) => ClearCache();
    64       this.terms.ItemsRemoved += (sender, args) => ClearCache();
    65       this.terms.ItemsReplaced += (sender, args) => ClearCache();
    66       this.terms.ItemsMoved += (sender, args) => ClearCache();
    6757    }
    6858
     
    9080    }
    9181
    92     private Dictionary<int, Tuple<int, int>> cachedParameterMap;
    9382    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);
    10083      return terms.Select(t => t.GetGradient(x, i, j)).Aggregate(Enumerable.Concat);
    10184    }
     
    10487      return terms.Select(t => t.GetCrossCovariance(x, xt, i, j)).Sum();
    10588    }
    106 
    107     private void ClearCache() {
    108       cachedParameterMap = null;
    109     }
    110 
    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     //}
    12089  }
    12190}
Note: See TracChangeset for help on using the changeset viewer.