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/CovarianceFunctions/CovarianceSum.cs

    r8929 r8982  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using System.Linq.Expressions;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
     
    6667    }
    6768
    68     public void SetParameter(double[] hyp) {
    69       if (terms.Count == 0) throw new ArgumentException("At least one term is needed for sum covariance function.");
     69    public void SetParameter(double[] p) {
    7070      int offset = 0;
    7171      foreach (var t in terms) {
    7272        var numberOfParameters = t.GetNumberOfParameters(numberOfVariables);
    73         t.SetParameter(hyp.Skip(offset).Take(numberOfParameters).ToArray());
     73        t.SetParameter(p.Skip(offset).Take(numberOfParameters).ToArray());
    7474        offset += numberOfParameters;
    7575      }
    7676    }
    7777
    78     public double GetCovariance(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
    79       return terms.Select(t => t.GetCovariance(x, i, j, columnIndices)).Sum();
    80     }
     78    public ParameterizedCovarianceFunction GetParameterizedCovarianceFunction(double[] p, IEnumerable<int> columnIndices) {
     79      if (terms.Count == 0) throw new ArgumentException("at least one term is necessary for the product covariance function.");
     80      var functions = new List<ParameterizedCovarianceFunction>();
     81      foreach (var t in terms) {
     82        var numberOfParameters = t.GetNumberOfParameters(numberOfVariables);
     83        functions.Add(t.GetParameterizedCovarianceFunction(p.Take(numberOfParameters).ToArray(), columnIndices));
     84        p = p.Skip(numberOfParameters).ToArray();
     85      }
    8186
    82     public IEnumerable<double> GetGradient(double[,] x, int i, int j, IEnumerable<int> columnIndices) {
    83       return terms.Select(t => t.GetGradient(x, i, j, columnIndices)).Aggregate(Enumerable.Concat);
    84     }
    85 
    86     public double GetCrossCovariance(double[,] x, double[,] xt, int i, int j, IEnumerable<int> columnIndices) {
    87       return terms.Select(t => t.GetCrossCovariance(x, xt, i, j, columnIndices)).Sum();
     87      var sum = new ParameterizedCovarianceFunction();
     88      sum.Covariance = (x, i, j) => functions.Select(e => e.Covariance(x, i, j)).Sum();
     89      sum.CrossCovariance = (x, xt, i, j) => functions.Select(e => e.CrossCovariance(x, xt, i, j)).Sum();
     90      sum.CovarianceGradient = (x, i, j) => functions.Select(e => e.CovarianceGradient(x, i, j)).Aggregate(Enumerable.Concat);
     91      return sum;
    8892    }
    8993  }
Note: See TracChangeset for help on using the changeset viewer.