Пример #1
0
 private CovarianceProduct(CovarianceProduct original, Cloner cloner)
     : base(original, cloner)
 {
     this.factors           = cloner.Clone(original.factors);
     this.numberOfVariables = original.numberOfVariables;
 }
        private ICovarianceFunction TreeToCovarianceFunction(ISymbolicExpressionTreeNode node)
        {
            switch (node.Symbol.Name)
            {
            case "Sum": {
                var sum = new CovarianceSum();
                sum.Terms.Add(TreeToCovarianceFunction(node.GetSubtree(0)));
                sum.Terms.Add(TreeToCovarianceFunction(node.GetSubtree(1)));
                return(sum);
            }

            case "Product": {
                var prod = new CovarianceProduct();
                prod.Factors.Add(TreeToCovarianceFunction(node.GetSubtree(0)));
                prod.Factors.Add(TreeToCovarianceFunction(node.GetSubtree(1)));
                return(prod);
            }

            // covFunction is cloned by the model so we can reuse instances of terminal covariance functions
            case "Linear": return(linear);

            case "LinearArd": return(linearArd);

            case "MaternIso1": return(maternIso1);

            case "MaternIso3": return(maternIso3);

            case "MaternIso5": return(maternIso5);

            case "NeuralNetwork": return(neuralNetwork);

            case "Periodic": return(periodic);

            case "PiecewisePolynomial0": return(piecewisePoly0);

            case "PiecewisePolynomial1": return(piecewisePoly1);

            case "PiecewisePolynomial2": return(piecewisePoly2);

            case "PiecewisePolynomial3": return(piecewisePoly3);

            case "Polynomial2": return(poly2);

            case "Polynomial3": return(poly3);

            case "RationalQuadraticArd": return(ratQuadraticArd);

            case "RationalQuadraticIso": return(ratQuadraticIso);

            case "SpectralMixture1": return(spectralMixture1);

            case "SpectralMixture3": return(spectralMixture3);

            case "SpectralMixture5": return(spectralMixture5);

            case "SquaredExponentialArd": return(sqrExpArd);

            case "SquaredExponentialIso": return(sqrExpIso);

            default: throw new InvalidProgramException(string.Format("Found invalid symbol {0}", node.Symbol.Name));
            }
        }
    public void CovProdTest() {
      var cov = new CovarianceProduct();
      cov.Factors.Add(new CovarianceSquaredExponentialIso());
      cov.Factors.Add(new CovarianceLinear());
      TestCovarianceFunction(cov, 0,
        new double[,]
          {
{    0.5245,    0.5389,    1.6120,    0.4836,    1.5106,    0.7554,    0.8386,    0.8239,    0.6239,    1.1336},
{    0.2889,    0.5225,    0.8337,    0.2496,    1.0595,    0.5710,    0.5052,    0.5547,    0.3724,    0.6822},
{    1.0623,    1.1239,    1.7263,    0.8459,    1.0618,    1.6839,    1.3988,    0.7607,    0.9521,    1.3106},
{    0.6585,    0.3625,    1.1117,    0.5349,    0.5137,    0.7756,    1.0648,    0.7942,    0.7510,    0.8516},
{    0.7040,    0.3275,    0.9490,    0.7125,    0.3548,    0.4404,    0.7037,    0.7073,    0.6680,    0.7798},
{    0.4641,    0.3741,    0.6234,    0.3844,    0.3673,    0.5306,    0.6413,    0.5193,    0.5036,    0.5608},
{    0.5385,    0.9383,    1.1840,    0.4565,    1.7927,    0.8766,    0.7518,    0.5198,    0.5765,    1.0608},
{    0.8694,    1.0060,    1.8506,    0.7108,    1.7052,    1.3654,    1.2234,    0.6698,    0.8427,    1.4060},
{    0.6989,    0.9246,    1.7118,    0.6277,    1.6927,    1.0667,    0.9339,    0.7510,    0.7057,    1.2768},
{    0.1972,    0.5055,    0.6262,    0.1263,    0.7928,    0.7002,    0.4950,    0.4913,    0.2894,    0.4889},

          },
        new double[][,]
          {      
            new double[,]
              {
{         0,    0.4127,    1.0287,    0.6741,    0.5630,    0.4325,    0.5722,    1.0336,    0.4752,    0.5617},
{    0.4127,         0,    0.6880,    0.3738,    0.2907,    0.1730,    0.4679,    0.8675,    0.4878,    0.1286},
{    1.0287,    0.6880,         0,    0.7937,    0.6606,    0.5323,    0.9538,    0.9634,    0.8138,    0.6381},
{    0.6741,    0.3738,    0.7937,         0,    0.3455,    0.1881,    0.6345,    0.9714,    0.7339,    0.3214},
{    0.5630,    0.2907,    0.6606,    0.3455,         0,    0.1313,    0.5056,    0.8485,    0.6038,    0.2630},
{    0.4325,    0.1730,    0.5323,    0.1881,    0.1313,         0,    0.3748,    0.6687,    0.4734,    0.1491},
{    0.5722,    0.4679,    0.9538,    0.6345,    0.5056,    0.3748,         0,    0.6955,    0.5871,    0.5059},
{    1.0336,    0.8675,    0.9634,    0.9714,    0.8485,    0.6687,    0.6955,         0,    0.9475,    0.6932},
{    0.4752,    0.4878,    0.8138,    0.7339,    0.6038,    0.4734,    0.5871,    0.9475,         0,    0.6046},
{    0.5617,    0.1286,    0.6381,    0.3214,    0.2630,    0.1491,    0.5059,    0.6932,    0.6046,         0},
              },
            new double[,]
              {
{    4.0023,    2.1261,    1.8626,    1.6054,    1.4771,    0.9102,    2.7697,    2.9858,    3.3730,    1.2556},
{    2.1261,    1.9372,    1.0981,    0.7172,    0.9121,    0.6569,    1.6947,    1.2703,    2.1250,    1.5231},
{    1.8626,    1.0981,    4.6784,    1.6055,    1.6490,    1.1138,    1.9438,    3.6140,    3.0330,    0.9581},
{    1.6054,    0.7172,    1.6055,    2.5635,    1.2584,    1.1688,    1.1565,    1.9117,    1.1689,    0.5622},
{    1.4771,    0.9121,    1.6490,    1.2584,    1.8469,    0.9049,    0.8350,    1.2221,    1.5977,    0.6577},
{    0.9102,    0.6569,    1.1138,    1.1688,    0.9049,    0.8258,    0.7611,    0.9541,    0.8954,    0.6253},
{    2.7697,    1.6947,    1.9438,    1.1565,    0.8350,    0.7611,    3.6346,    3.5720,    2.9305,    0.9789},
{    2.9858,    1.2703,    3.6140,    1.9117,    1.2221,    0.9541,    3.5720,    5.8240,    3.4327,    0.7368},
{    3.3730,    2.1250,    3.0330,    1.1689,    1.5977,    0.8954,    2.9305,    3.4327,    4.3277,    1.4057},
{    1.2556,    1.5231,    0.9581,    0.5622,    0.6577,    0.6253,    0.9789,    0.7368,    1.4057,    1.7151},
              },
          }
      );
      cov = new CovarianceProduct();
      cov.Factors.Add(new CovarianceSquaredExponentialIso());
      cov.Factors.Add(new CovarianceLinear());
      TestCovarianceFunction(cov, 1,
        new double[,]
          {
{    6.2342,    6.7795,   13.6134,    5.8887,   14.2405,   10.1987,    8.8183,    7.8217,    6.6344,    9.9609},
{    3.2242,    5.2384,    8.2928,    2.8624,   10.2826,    7.2613,    5.2743,    4.8651,    3.6758,    6.0948},
{    9.7926,   10.6338,   14.7280,    8.6537,   12.8640,   15.3218,   12.0130,    8.0240,    8.9653,   11.3359},
{    6.0497,    4.4825,   10.1916,    5.2725,    7.5223,    9.0848,    8.6907,    6.5563,    6.2868,    7.4352},
{    5.7877,    3.8005,    8.8010,    5.7766,    5.6360,    6.2037,    6.3872,    5.6164,    5.3671,    6.5321},
{    3.8501,    3.6110,    6.2543,    3.3286,    5.0963,    6.1672,    5.3421,    4.0085,    3.8812,    4.6925},
{    6.0719,    8.8301,   11.5124,    5.4433,   14.9080,   10.6099,    8.0304,    5.7589,    6.0753,    9.3107},
{    9.8306,   11.1183,   16.3892,    8.8231,   16.9213,   15.2084,   12.3844,    8.3980,    9.3789,   12.8390},
{    7.6019,    9.3580,   14.3105,    7.1044,   15.2800,   12.2846,    9.6031,    7.6887,    7.3699,   10.8667},
{    2.3372,    4.9884,    6.9233,    1.6100,    8.7070,    7.9328,    5.0646,    4.3597,    2.9643,    4.8145},
          },
        new double[][,]
          {            
            new double[,]
              {
{         0,    0.4881,    1.6583,    0.9692,    0.7827,    0.6522,    0.6841,    1.3942,    0.5367,    0.8270},
{    0.4881,         0,    1.1827,    0.5867,    0.3830,    0.2172,    0.5941,    1.5658,    0.5949,    0.1383},
{    1.6583,    1.1827,         0,    1.2171,    0.9340,    0.8047,    1.4579,    1.2131,    1.0263,    1.1349},
{    0.9692,    0.5867,    1.2171,         0,    0.4382,    0.2161,    1.0197,    1.5073,    1.2629,    0.5270},
{    0.7827,    0.3830,    0.9340,    0.4382,         0,    0.1488,    0.8534,    1.5465,    0.8372,    0.3717},
{    0.6522,    0.2172,    0.8047,    0.2161,    0.1488,         0,    0.5737,    1.2259,    0.7478,    0.1832},
{    0.6841,    0.5941,    1.4579,    1.0197,    0.8534,    0.5737,         0,    0.8230,    0.6981,    0.7909},
{    1.3942,    1.5658,    1.2131,    1.5073,    1.5465,    1.2259,    0.8230,         0,    1.2028,    1.5638},
{    0.5367,    0.5949,    1.0263,    1.2629,    0.8372,    0.7478,    0.6981,    1.2028,         0,    0.8770},
{    0.8270,    0.1383,    1.1349,    0.5270,    0.3717,    0.1832,    0.7909,    1.5638,    0.8770,         0},
              },
            new double[,]
              {
{   29.5729,   18.5805,   22.1876,   17.0550,   15.1746,   10.1428,   24.4678,   29.7604,   28.1516,   13.6594},
{   18.5805,   14.3139,   13.9483,    8.3170,    8.8785,    6.0953,   15.8990,   16.9410,   19.1490,   12.1067},
{   22.1876,   13.9483,   34.5691,   18.1905,   17.2281,   12.4415,   21.9535,   33.6266,   28.2630,   12.5918},
{   17.0550,    8.3170,   18.1905,   18.9418,   11.7900,    9.9253,   13.7325,   21.9184,   14.8634,    6.8107},
{   15.1746,    8.8785,   17.2281,   11.7900,   13.6471,    7.5799,   10.4142,   16.4592,   16.3685,    6.8676},
{   10.1428,    6.0953,   12.4415,    9.9253,    7.5799,    6.1018,    8.6086,   12.9238,   10.4507,    5.6783},
{   24.4678,   15.8990,   21.9535,   13.7325,   10.4142,    8.6086,   26.8561,   31.2335,   25.7489,   11.3079},
{   29.7604,   16.9410,   33.6266,   21.9184,   16.4592,   12.9238,   31.2335,   43.0336,   32.2012,   12.2815},
{   28.1516,   19.1490,   28.2630,   14.8634,   16.3685,   10.4507,   25.7489,   32.2012,   31.9778,   15.0663},
{   13.6594,   12.1067,   12.5918,    6.8107,    6.8676,    5.6783,   11.3079,   12.2815,   15.0663,   12.6728},
              },
          }
      , 5e-3);
    }
Пример #4
0
 private CovarianceProduct(CovarianceProduct original, Cloner cloner)
   : base(original, cloner) {
   this.factors = cloner.Clone(original.factors);
   this.numberOfVariables = original.numberOfVariables;
 }