当前位置: 首页>>代码示例>>Java>>正文


Java Attribute.getAttributeValue方法代码示例

本文整理汇总了Java中dr.util.Attribute.getAttributeValue方法的典型用法代码示例。如果您正苦于以下问题:Java Attribute.getAttributeValue方法的具体用法?Java Attribute.getAttributeValue怎么用?Java Attribute.getAttributeValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dr.util.Attribute的用法示例。


在下文中一共展示了Attribute.getAttributeValue方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: calculateLogLikelihood

import dr.util.Attribute; //导入方法依赖的package包/类
public double calculateLogLikelihood() {
        double logL = 0.0;

        for (Attribute<double[]> data : dataList) {
            double[] x =
//                    (data instanceof Parameter) ?
//                            ((Parameter) data).getParameterValues() :
                            data.getAttributeValue();
            if (transforms != null) {
                double[] y = new double[x.length];
                for (int i = 0; i < x.length; ++i) {
                    logL += transforms[i].getLogJacobian(x[i]);
                    y[i] = transforms[i].transform(x[i]);
                }
                logL += distribution.logPdf(y);
            } else {
                logL += distribution.logPdf(x);
            }
        }
        return logL;
    }
 
开发者ID:beast-dev,项目名称:beast-mcmc,代码行数:22,代码来源:MultivariateDistributionLikelihood.java

示例2: doOperation

import dr.util.Attribute; //导入方法依赖的package包/类
/**
 * Called by operate(), does the actual operation.
 *
 * @return the hastings ratio
 * @throws OperatorFailedException if operator fails and should be rejected
 */
public double doOperation() {

    double priorPrecision = 1.0 / prior.variance();
    double priorMean = prior.mean();
    double likelihoodPrecision = 1.0 / likelihood.variance();

    double total = 0;
    int n = 0;
    for ( Attribute<double[]> statistic : dataList ) {
        for (double x : statistic.getAttributeValue()) {
            if (isLog)
                total += Math.log(x);
            else
                total += x;
            n++;
        }
    }

    double precision = priorPrecision + likelihoodPrecision * n;
    double mu = (priorPrecision * priorMean + likelihoodPrecision * total) / precision;
    meanParameter.setParameterValue(0,
            MathUtils.nextGaussian() / Math.sqrt(precision) + mu);  // N(\mu, \precision)
    return 0;
}
 
开发者ID:beast-dev,项目名称:beast-mcmc,代码行数:31,代码来源:NormalNormalMeanGibbsOperator.java

示例3: incrementOuterProduct

import dr.util.Attribute; //导入方法依赖的package包/类
private void incrementOuterProduct(double[][] S,
                                   MultivariateDistributionLikelihood likelihood) {

    double[] mean = likelihood.getDistribution().getMean();

    numberObservations = 0;
    List<Attribute<double[]>> dataList = likelihood.getDataList();
    int count = 0;
    for (Attribute<double[]> d : dataList) {

        double[] data = d.getAttributeValue();
        for (int i = 0; i < dim; i++) {
            data[i] -= mean[i];
        }

        for (int i = 0; i < dim; i++) {  // symmetric matrix,
            for (int j = i; j < dim; j++) {
                S[j][i] = S[i][j] += data[i] * data[j];
            }
        }
        numberObservations += 1;
    }
}
 
开发者ID:beast-dev,项目名称:beast-mcmc,代码行数:24,代码来源:PrecisionMatrixGibbsOperator.java

示例4: calculateLogLikelihood

import dr.util.Attribute; //导入方法依赖的package包/类
/**
 * Calculate the log likelihood of the current state.
 *
 * @return the log likelihood.
 */
public double calculateLogLikelihood() {

    double logL = 0.0;

    for (Attribute<double[]> data : dataList) {  
        // see comment in DistributionLikelihood
        final double[] attributeValue = data.getAttributeValue();

        for (int j = Math.max(0, from); j < Math.min(attributeValue.length, to); j++) {

            double value = attributeValue[j] + offset;
            if (value > lower && value < upper) {
                logL += logPDF(value);
            } else {
                return Double.NEGATIVE_INFINITY;
            }

            if (DEBUG) {
                if (Double.isInfinite(logL)) {
                    System.err.println("Infinite log density in "+
                            (getId() != null ? getId() : fileName)                        
                    );
                    System.err.println("Evaluated at "+value);
                    System.err.println("Min: " + values[0] + " Max: " + values[values.length - 1]);
                }
            }
        }
    }
    return logL;
}
 
开发者ID:beast-dev,项目名称:beast-mcmc,代码行数:36,代码来源:EmpiricalDistributionLikelihood.java

示例5: calculateLogLikelihood

import dr.util.Attribute; //导入方法依赖的package包/类
/**
 * Calculate the log likelihood of the current state.
 *
 * @return the log likelihood.
 */
public double calculateLogLikelihood() {

    if (DEBUG) {
        System.err.println("Calling DistributionLikelihood.calculateLogLikelihood()");
        System.err.println(distribution.toString());
        System.err.println(dataList.toString() + "\n");
    }

    double logL = 0.0;

    for( Attribute<double[]> data : dataList ) {

        // Using this in the loop is incredibly wasteful, especially in the loop condition to get the length
        final double[] attributeValue = data.getAttributeValue();

        if (DEBUG) {
            System.err.println("\t" + new Vector(attributeValue));
        }

        for (int j = Math.max(0, from); j < Math.min(attributeValue.length, to); j++) {

            final double value = attributeValue[j] - offset;

            if (offset > 0.0 && value < 0.0) {
                // fixes a problem with the offset on exponential distributions not
                // actually bounding the distribution. This only performs this check
                // if a non-zero offset is actually given otherwise it assumes the
                // parameter is either legitimately allowed to go negative or is bounded
                // at zero anyway.
                return Double.NEGATIVE_INFINITY;
            }
            logL += getLogPDF(value);
        }

    }
    return logL;
}
 
开发者ID:beast-dev,项目名称:beast-mcmc,代码行数:43,代码来源:DistributionLikelihood.java

示例6: doOperation

import dr.util.Attribute; //导入方法依赖的package包/类
/**
 * Called by operate(), does the actual operation.
 *
 * @return the hastings ratio
 */
public double doOperation() {

    final double priorMean = prior.mean();
    final double priorVariance = prior.variance();

    double priorRate;
    double priorShape;

    if (priorMean == 0) {
        priorRate = 0;
        priorShape = -0.5; // Uninformative prior
    } else {
        priorRate = priorMean / priorVariance;
        priorShape = priorMean * priorRate;
    }

    // Calculate weighted sum-of-squares
    final double mu = meanParameter.getParameterValue(0);
    double SSE = 0;
    int n = 0;
    for (Attribute<double[]> statistic : dataList) {
        for (double x : statistic.getAttributeValue()) {
            if (isLog) {
                final double logX = Math.log(x);
                SSE += (logX - mu) * (logX - mu);
            } else {
                SSE += (x - mu) * (x - mu);
            }
            n++;
        }
    }

    final double shape = priorShape + n / 2.0;
    final double rate = priorRate + 0.5 * SSE;

    final double draw = MathUtils.nextGamma(shape, rate); // Gamma( \alpha + n/2 , \beta + (1/2)*SSE )
    precisionParameter.setParameterValue(0, draw);

    return 0;
}
 
开发者ID:beast-dev,项目名称:beast-mcmc,代码行数:46,代码来源:NormalGammaPrecisionGibbsOperator.java

示例7: getMeanSum

import dr.util.Attribute; //导入方法依赖的package包/类
private double[] getMeanSum(){
        double[] answer=new double[dim];
        List<Attribute<double[]>> dataList = likelihood.getDataList();
        for(Attribute<double[]> d: dataList){
            for(int i=0; i<d.getAttributeValue().length; i++)
            {
                answer[i]+=d.getAttributeValue()[i];
            }
        }
/*
for(int i=0; i<dim; i++){
System.err.print(answer[i]);
System.err.print("\n");}
*/
        return answer;}
 
开发者ID:beast-dev,项目名称:beast-mcmc,代码行数:16,代码来源:MultivariateNormalGibbsOperator.java


注:本文中的dr.util.Attribute.getAttributeValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。