Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/01/12 19:02:47 (11 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.Tests/HeuristicLab.Algorithms.DataAnalysis-3.4/GaussianProcessFunctionsTest.cs

    r8620 r8982  
    6666          }
    6767      );
     68      sum = new MeanSum();
     69      sum.Terms.Add(new MeanConst());
     70      sum.Terms.Add(new MeanConst());
    6871      TestMeanFunction(sum, 1,
    6972        new double[] { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
     
    8891          }
    8992      );
     93      prod = new MeanProduct();
     94      prod.Factors.Add(new MeanConst());
     95      prod.Factors.Add(new MeanConst());
    9096      TestMeanFunction(prod, 1,
    9197        new double[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
     
    97103      );
    98104
    99       prod.Factors.Clear();
     105      prod = new MeanProduct();
    100106      prod.Factors.Add(new MeanZero());
    101107      prod.Factors.Add(new MeanLinear());
     
    111117          }
    112118      );
     119      prod = new MeanProduct();
     120      prod.Factors.Add(new MeanZero());
     121      prod.Factors.Add(new MeanLinear());
    113122      TestMeanFunction(prod, 1,
    114123        new double[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
     
    123132      );
    124133
    125       prod.Factors.Clear();
     134      prod = new MeanProduct();
    126135      prod.Factors.Add(new MeanConst());
    127136      prod.Factors.Add(new MeanLinear());
     
    13341343          }
    13351344      );
     1345      cov = new CovarianceSum();
     1346      cov.Terms.Add(new CovarianceSquaredExponentialIso());
     1347      cov.Terms.Add(new CovarianceLinear());
    13361348      TestCovarianceFunction(cov, 1,
    13371349        new double[,]
     
    14411453          }
    14421454      );
     1455      cov = new CovarianceScale();
     1456      cov.CovarianceFunctionParameter.Value = new CovarianceSquaredExponentialIso();
    14431457      TestCovarianceFunction(cov, 1,
    14441458        new double[,]
     
    15501564          }
    15511565      );
     1566      cov = new CovarianceProduct();
     1567      cov.Factors.Add(new CovarianceSquaredExponentialIso());
     1568      cov.Factors.Add(new CovarianceLinear());
    15521569      TestCovarianceFunction(cov, 1,
    15531570        new double[,]
     
    16031620      int nHyp = cf.GetNumberOfParameters(x.GetLength(1));
    16041621      var hyp = Enumerable.Repeat(hypValue, nHyp).ToArray();
    1605       cf.SetParameter(hyp);
    16061622
    16071623      int rows0 = x.GetLength(0);
    16081624      int rows1 = xt.GetLength(0);
    16091625      var actualCov = new double[rows0, rows1];
     1626      var covFunction = cf.GetParameterizedCovarianceFunction(hyp, Enumerable.Range(0, x.GetLength(1)));
    16101627      for (int i = 0; i < rows0; i++)
    16111628        for (int j = 0; j < rows1; j++)
    1612           actualCov[i, j] = cf.GetCrossCovariance(x, xt, i, j);
     1629          actualCov[i, j] = covFunction.CrossCovariance(x, xt, i, j);
    16131630
    16141631      AssertEqual(expectedCov, actualCov, delta);
     
    16161633      for (int i = 0; i < rows0; i++)
    16171634        for (int j = 0; j < rows1; j++) {
    1618           var g = cf.GetGradient(x, i, j).ToArray();
     1635          var g = covFunction.CovarianceGradient(x, i, j).ToArray();
    16191636          for (int k = 0; k < nHyp; k++)
    16201637            Assert.AreEqual(expectedGradients[k][i, j], g[k], delta);
     
    16291646      int nHyp = mf.GetNumberOfParameters(x.GetLength(1));
    16301647      var hyp = Enumerable.Repeat(hypValue, nHyp).ToArray();
    1631       mf.SetParameter(hyp);
    1632 
    1633       var m = mf.GetMean(xt);
     1648      var meanFunction = mf.GetParameterizedMeanFunction(hyp, Enumerable.Range(0, x.GetLength(1)));
     1649
     1650      var m = Enumerable.Range(0, xt.GetLength(0)).Select(i => meanFunction.Mean(xt, i)).ToArray();
    16341651
    16351652      AssertEqual(expectedMean, m);
    16361653
    1637       for (int i = 0; i < nHyp; i++) {
    1638         var g = mf.GetGradients(i, x);
    1639         AssertEqual(expectedGradients[i], g);
     1654      for (int k = 0; k < nHyp; k++) {
     1655        var g = Enumerable.Range(0, xt.GetLength(0)).Select(i => meanFunction.Gradient(x, i, k)).ToArray();
     1656        AssertEqual(expectedGradients[k], g);
    16401657      }
    16411658    }
Note: See TracChangeset for help on using the changeset viewer.