Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/01/12 19:02:47 (12 years ago)
Author:
gkronber
Message:

#1902: removed class HyperParameter and changed implementations of covariance and mean functions to remove the parameter value caching and event handlers for parameter caching. Instead it is now possible to create the actual covariance and mean functions as Func from templates and specified parameter values. The instances of mean and covariance functions configured in the GUI are actually templates where the structure and fixed parameters can be specified.

File:
1 edited

Legend:

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

    r8929 r8982  
    1919 */
    2020#endregion
     21
     22using System.Collections.Generic;
    2123using System.Linq;
    2224using HeuristicLab.Common;
     
    5759    }
    5860
    59     public void SetParameter(double[] hyp) {
     61    public void SetParameter(double[] p) {
    6062      int offset = 0;
    6163      foreach (var t in terms) {
    6264        var numberOfParameters = t.GetNumberOfParameters(numberOfVariables);
    63         t.SetParameter(hyp.Skip(offset).Take(numberOfParameters).ToArray());
     65        t.SetParameter(p.Skip(offset).Take(numberOfParameters).ToArray());
    6466        offset += numberOfParameters;
    6567      }
    6668    }
    6769
    68     public double[] GetMean(double[,] x) {
    69       var res = terms.First().GetMean(x);
    70       foreach (var t in terms.Skip(1)) {
    71         var a = t.GetMean(x);
    72         for (int i = 0; i < res.Length; i++) res[i] += a[i];
     70    public ParameterizedMeanFunction GetParameterizedMeanFunction(double[] p, IEnumerable<int> columnIndices) {
     71      var termMf = new List<ParameterizedMeanFunction>();
     72      int totalNumberOfParameters = GetNumberOfParameters(numberOfVariables);
     73      int[] termIndexMap = new int[totalNumberOfParameters]; // maps k-th parameter to the correct mean-term
     74      int[] hyperParameterIndexMap = new int[totalNumberOfParameters]; // maps k-th parameter to the l-th parameter of the correct mean-term
     75      int c = 0;
     76      // get the parameterized mean function for each term
     77      for (int termIndex = 0; termIndex < terms.Count; termIndex++) {
     78        var numberOfParameters = terms[termIndex].GetNumberOfParameters(numberOfVariables);
     79        termMf.Add(terms[termIndex].GetParameterizedMeanFunction(p.Take(numberOfParameters).ToArray(), columnIndices));
     80        p = p.Skip(numberOfParameters).ToArray();
     81
     82        for (int hyperParameterIndex = 0; hyperParameterIndex < numberOfParameters; hyperParameterIndex++) {
     83          termIndexMap[c] = termIndex;
     84          hyperParameterIndexMap[c] = hyperParameterIndex;
     85          c++;
     86        }
    7387      }
    74       return res;
    75     }
    7688
    77     public double[] GetGradients(int k, double[,] x) {
    78       int i = 0;
    79       while (k >= terms[i].GetNumberOfParameters(numberOfVariables)) {
    80         k -= terms[i].GetNumberOfParameters(numberOfVariables);
    81         i++;
    82       }
    83       return terms[i].GetGradients(k, x);
     89      var mf = new ParameterizedMeanFunction();
     90      mf.Mean = (x, i) => termMf.Select(t => t.Mean(x, i)).Sum();
     91      mf.Gradient = (x, i, k) => {
     92        return termMf[termIndexMap[k]].Gradient(x, i, hyperParameterIndexMap[k]);
     93      };
     94      return mf;
    8495    }
    8596  }
Note: See TracChangeset for help on using the changeset viewer.