Changeset 8982 for trunk/sources/HeuristicLab.Tests/HeuristicLab.Algorithms.DataAnalysis-3.4/GaussianProcessFunctionsTest.cs
- Timestamp:
- 12/01/12 19:02:47 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Tests/HeuristicLab.Algorithms.DataAnalysis-3.4/GaussianProcessFunctionsTest.cs
r8620 r8982 66 66 } 67 67 ); 68 sum = new MeanSum(); 69 sum.Terms.Add(new MeanConst()); 70 sum.Terms.Add(new MeanConst()); 68 71 TestMeanFunction(sum, 1, 69 72 new double[] { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }, … … 88 91 } 89 92 ); 93 prod = new MeanProduct(); 94 prod.Factors.Add(new MeanConst()); 95 prod.Factors.Add(new MeanConst()); 90 96 TestMeanFunction(prod, 1, 91 97 new double[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, … … 97 103 ); 98 104 99 prod .Factors.Clear();105 prod = new MeanProduct(); 100 106 prod.Factors.Add(new MeanZero()); 101 107 prod.Factors.Add(new MeanLinear()); … … 111 117 } 112 118 ); 119 prod = new MeanProduct(); 120 prod.Factors.Add(new MeanZero()); 121 prod.Factors.Add(new MeanLinear()); 113 122 TestMeanFunction(prod, 1, 114 123 new double[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, … … 123 132 ); 124 133 125 prod .Factors.Clear();134 prod = new MeanProduct(); 126 135 prod.Factors.Add(new MeanConst()); 127 136 prod.Factors.Add(new MeanLinear()); … … 1334 1343 } 1335 1344 ); 1345 cov = new CovarianceSum(); 1346 cov.Terms.Add(new CovarianceSquaredExponentialIso()); 1347 cov.Terms.Add(new CovarianceLinear()); 1336 1348 TestCovarianceFunction(cov, 1, 1337 1349 new double[,] … … 1441 1453 } 1442 1454 ); 1455 cov = new CovarianceScale(); 1456 cov.CovarianceFunctionParameter.Value = new CovarianceSquaredExponentialIso(); 1443 1457 TestCovarianceFunction(cov, 1, 1444 1458 new double[,] … … 1550 1564 } 1551 1565 ); 1566 cov = new CovarianceProduct(); 1567 cov.Factors.Add(new CovarianceSquaredExponentialIso()); 1568 cov.Factors.Add(new CovarianceLinear()); 1552 1569 TestCovarianceFunction(cov, 1, 1553 1570 new double[,] … … 1603 1620 int nHyp = cf.GetNumberOfParameters(x.GetLength(1)); 1604 1621 var hyp = Enumerable.Repeat(hypValue, nHyp).ToArray(); 1605 cf.SetParameter(hyp);1606 1622 1607 1623 int rows0 = x.GetLength(0); 1608 1624 int rows1 = xt.GetLength(0); 1609 1625 var actualCov = new double[rows0, rows1]; 1626 var covFunction = cf.GetParameterizedCovarianceFunction(hyp, Enumerable.Range(0, x.GetLength(1))); 1610 1627 for (int i = 0; i < rows0; i++) 1611 1628 for (int j = 0; j < rows1; j++) 1612 actualCov[i, j] = c f.GetCrossCovariance(x, xt, i, j);1629 actualCov[i, j] = covFunction.CrossCovariance(x, xt, i, j); 1613 1630 1614 1631 AssertEqual(expectedCov, actualCov, delta); … … 1616 1633 for (int i = 0; i < rows0; i++) 1617 1634 for (int j = 0; j < rows1; j++) { 1618 var g = c f.GetGradient(x, i, j).ToArray();1635 var g = covFunction.CovarianceGradient(x, i, j).ToArray(); 1619 1636 for (int k = 0; k < nHyp; k++) 1620 1637 Assert.AreEqual(expectedGradients[k][i, j], g[k], delta); … … 1629 1646 int nHyp = mf.GetNumberOfParameters(x.GetLength(1)); 1630 1647 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(); 1634 1651 1635 1652 AssertEqual(expectedMean, m); 1636 1653 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); 1640 1657 } 1641 1658 }
Note: See TracChangeset
for help on using the changeset viewer.