コード例 #1
0
        public Object parseXMLObject(XMLObject xo) throws XMLParseException {

          MultivariateDistributionLikelihood likelihood;

          if (xo.hasAttribute(NON_INFORMATIVE) && xo.getBooleanAttribute(NON_INFORMATIVE)) {
            // Make non-informative settings
            XMLObject cxo = xo.getChild(DATA);
            int dim = ((MatrixParameter) cxo.getChild(0)).getColumnDimension();
            likelihood = new MultivariateDistributionLikelihood(new WishartDistribution(dim));
          } else {
            if (!xo.hasAttribute(DF) || !xo.hasChildNamed(SCALE_MATRIX)) {
              throw new XMLParseException("Must specify both a df and scaleMatrix");
            }

            double df = xo.getDoubleAttribute(DF);

            XMLObject cxo = xo.getChild(SCALE_MATRIX);
            MatrixParameter scaleMatrix = (MatrixParameter) cxo.getChild(MatrixParameter.class);

            likelihood =
                new MultivariateDistributionLikelihood(
                    new WishartDistribution(df, scaleMatrix.getParameterAsMatrix()));
          }

          XMLObject cxo = xo.getChild(DATA);
          for (int j = 0; j < cxo.getChildCount(); j++) {
            if (cxo.getChild(j) instanceof MatrixParameter) {
              likelihood.addData((MatrixParameter) cxo.getChild(j));
            } else {
              throw new XMLParseException(
                  "illegal element in " + xo.getName() + " element " + cxo.getName());
            }
          }

          return likelihood;
        }
コード例 #2
0
        public Object parseXMLObject(XMLObject xo) throws XMLParseException {

          int df = xo.getIntegerAttribute(DF);

          XMLObject cxo = xo.getChild(SCALE_MATRIX);
          MatrixParameter scaleMatrix = (MatrixParameter) cxo.getChild(MatrixParameter.class);
          InverseWishartDistribution invWishart =
              new InverseWishartDistribution(df, scaleMatrix.getParameterAsMatrix());

          MultivariateDistributionLikelihood likelihood =
              new MultivariateDistributionLikelihood(invWishart);

          cxo = xo.getChild(DATA);
          for (int j = 0; j < cxo.getChildCount(); j++) {
            if (cxo.getChild(j) instanceof MatrixParameter) {
              likelihood.addData((MatrixParameter) cxo.getChild(j));
            } else {
              throw new XMLParseException(
                  "illegal element in " + xo.getName() + " element " + cxo.getName());
            }
          }

          return likelihood;
        }
コード例 #3
0
        public Object parseXMLObject(XMLObject xo) throws XMLParseException {

          XMLObject cxo = xo.getChild(MVN_MEAN);
          Parameter mean = (Parameter) cxo.getChild(Parameter.class);

          cxo = xo.getChild(MVN_PRECISION);
          MatrixParameter precision = (MatrixParameter) cxo.getChild(MatrixParameter.class);

          if (mean.getDimension() != precision.getRowDimension()
              || mean.getDimension() != precision.getColumnDimension())
            throw new XMLParseException(
                "Mean and precision have wrong dimensions in " + xo.getName() + " element");

          Transform[] transforms = parseListOfTransforms(xo, mean.getDimension());

          MultivariateDistributionLikelihood likelihood =
              new MultivariateDistributionLikelihood(
                  new MultivariateNormalDistribution(
                      mean.getParameterValues(), precision.getParameterAsMatrix()),
                  transforms);
          cxo = xo.getChild(DATA);
          if (cxo != null) {
            for (int j = 0; j < cxo.getChildCount(); j++) {
              if (cxo.getChild(j) instanceof Parameter) {
                Parameter data = (Parameter) cxo.getChild(j);
                if (data instanceof MatrixParameter) {
                  MatrixParameter matrix = (MatrixParameter) data;
                  if (matrix.getParameter(0).getDimension() != mean.getDimension())
                    throw new XMLParseException(
                        "dim("
                            + data.getStatisticName()
                            + ") = "
                            + matrix.getParameter(0).getDimension()
                            + " is not equal to dim("
                            + mean.getStatisticName()
                            + ") = "
                            + mean.getDimension()
                            + " in "
                            + xo.getName()
                            + "element");

                  for (int i = 0; i < matrix.getParameterCount(); i++) {
                    likelihood.addData(matrix.getParameter(i));
                  }
                } else {
                  if (data.getDimension() != mean.getDimension())
                    throw new XMLParseException(
                        "dim("
                            + data.getStatisticName()
                            + ") = "
                            + data.getDimension()
                            + " is not equal to dim("
                            + mean.getStatisticName()
                            + ") = "
                            + mean.getDimension()
                            + " in "
                            + xo.getName()
                            + "element");
                  likelihood.addData(data);
                }
              } else {
                throw new XMLParseException("illegal element in " + xo.getName() + " element");
              }
            }
          }

          return likelihood;
        }