本文整理汇总了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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;}