本文整理汇总了Java中dr.util.Attribute类的典型用法代码示例。如果您正苦于以下问题:Java Attribute类的具体用法?Java Attribute怎么用?Java Attribute使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Attribute类属于dr.util包,在下文中一共展示了Attribute类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeGeneralDataType
import dr.util.Attribute; //导入依赖的package包/类
private void writeGeneralDataType(PartitionSubstitutionModel model, XMLWriter writer) {
writer.writeComment("general data type for discrete trait model, '" + model.getName() + "'");
Set<String> states = options.getStatesForDiscreteModel(model);
String prefix = model.getName() + ".";
// <generalDataType>
writer.writeOpenTag(GeneralDataTypeParser.GENERAL_DATA_TYPE, new Attribute[]{
new Attribute.Default<String>(XMLParser.ID, prefix + "dataType")});
int numOfStates = states.size();
writer.writeComment("Number Of States = " + numOfStates);
for (String eachGD : states) {
writer.writeTag(GeneralDataTypeParser.STATE, new Attribute[]{
new Attribute.Default<String>(GeneralDataTypeParser.CODE, eachGD)}, true);
}
writer.writeCloseTag(GeneralDataTypeParser.GENERAL_DATA_TYPE);
}
示例2: main
import dr.util.Attribute; //导入依赖的package包/类
public static void main(String[] arg) throws IOException, TraceException {
// constructing random variable representing mean of normal distribution
Variable.D mean = new Variable.D("mean", 1.0);
// give mean a uniform prior [-1000, 1000]
mean.addBounds(new Parameter.DefaultBounds(1000, -1000, 1));
// constructing random variable representing stdev of normal distribution
Variable.D stdev = new Variable.D("stdev", 1.0);
// give stdev a uniform prior [0, 1000]
stdev.addBounds(new Parameter.DefaultBounds(1000, 0, 1));
// construct normal distribution model
NormalDistributionModel normal = new NormalDistributionModel(mean, stdev);
// construct a likelihood for normal distribution
DistributionLikelihood likelihood = new DistributionLikelihood(normal);
// construct data
Attribute.Default<double[]> d = new Attribute.Default<double[]>(
"x", new double[]{1, 2, 3, 4, 5, 6, 7, 8, 9});
// add data (representing 9 independent observations) to likelihood
likelihood.addData(d);
// construct two "operators" to be used as the proposal distribution
MCMCOperator meanMove = new ScaleOperator(mean, 0.75);
MCMCOperator stdevMove = new ScaleOperator(stdev, 0.75);
// construct a logger to log progress of MCMC run to stdout (screen)
MCLogger logger1 = new MCLogger(100);
logger1.add(mean);
logger1.add(stdev);
// construct a logger to log to a log file for later analysis
MCLogger logger2 = new MCLogger("tutorial1.log", 100, false, 0);
logger2.add(mean);
logger2.add(stdev);
// construct MCMC object
MCMC mcmc = new MCMC("tutorial1:normal");
// initialize MCMC with chain length, likelihood, operators and loggers
mcmc.init(100000, likelihood, new MCMCOperator[]{meanMove, stdevMove}, new Logger[]{logger1, logger2});
// run the mcmc
mcmc.chain();
// perform post-analysis
TraceAnalysis.report("tutorial1.log");
}
示例3: main
import dr.util.Attribute; //导入依赖的package包/类
public static void main(String[] arg) {
// Define normal model
Parameter meanParameter = new Parameter.Default(1.0); // Starting value
Variable<Double> stdev = new Variable.D(1.0, 1); // Fixed value
ParametricDistributionModel densityModel = new NormalDistributionModel(meanParameter, stdev);
DistributionLikelihood likelihood = new DistributionLikelihood(densityModel);
// Define prior
DistributionLikelihood prior = new DistributionLikelihood(new NormalDistribution(0.0, 1.0)); // Hyper-priors
prior.addData(meanParameter);
// Define data
likelihood.addData(new Attribute.Default<double[]>("Data", new double[] {0.0, 1.0, 2.0}));
List<Likelihood> list = new ArrayList<Likelihood>();
list.add(likelihood);
list.add(prior);
CompoundLikelihood posterior = new CompoundLikelihood(0, list);
SliceOperator sliceSampler = new SliceOperator(meanParameter);
final int length = 10000;
double mean = 0;
double variance = 0;
for(int i = 0; i < length; i++) {
sliceSampler.doOperation(posterior);
double x = meanParameter.getValue(0);
mean += x;
variance += x*x;
}
mean /= length;
variance /= length;
variance -= mean*mean;
System.out.println("E(x) = "+mean);
System.out.println("V(x) = "+variance);
}
示例4: parseXMLObject
import dr.util.Attribute; //导入依赖的package包/类
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
String[] names = ((XMLObject)xo.getChild(NAMES)).getStringArrayChild(0);
String[] values =((XMLObject)xo.getChild(VALUES)).getStringArrayChild(0);
if (names.length != values.length) {
throw new XMLParseException("The number of names and values must match.");
}
Attribute[] attributes = new Attribute[names.length];
for (int i =0; i < attributes.length; i++) {
attributes[i] = new Attribute.Default(names[i], values[i]);
}
return attributes;
}
示例5: writeParameter
import dr.util.Attribute; //导入依赖的package包/类
/**
* write a parameter
*
* @param parameterId the parameter name/id
* @param parameterColumn the parameter column from which the samples are taken
* @param fileName the file from which the samples are taken
* @param burnin the number of samples to be discarded
* @param writer the writer
*/
public void writeParameter(String parameterId, String parameterColumn, String fileName, int burnin, XMLWriter writer) {
ArrayList<Attribute.Default> attributes = new ArrayList<Attribute.Default>();
attributes.add(new Attribute.Default<String>(XMLParser.ID, parameterId));
attributes.add(new Attribute.Default<String>("parameterColumn", parameterColumn));
attributes.add(new Attribute.Default<String>("fileName", fileName));
attributes.add(new Attribute.Default<String>("burnin", "" + burnin));
Attribute[] attrArray = new Attribute[attributes.size()];
for (int i = 0; i < attrArray.length; i++) {
attrArray[i] = attributes.get(i);
}
writer.writeTag(ParameterParser.PARAMETER, attrArray, true);
}
示例6: writeDeltaOperator
import dr.util.Attribute; //导入依赖的package包/类
private void writeDeltaOperator(Operator operator, boolean weighted, XMLWriter writer) {
int[] parameterWeights = operator.getParameter1().getParameterDimensionWeights();
Attribute[] attributes;
if (weighted && parameterWeights != null && parameterWeights.length > 1) {
String pw = "" + parameterWeights[0];
for (int i = 1; i < parameterWeights.length; i++) {
pw += " " + parameterWeights[i];
}
attributes = new Attribute[]{
new Attribute.Default<Double>(DeltaExchangeOperatorParser.DELTA, operator.getTuning()),
new Attribute.Default<String>(DeltaExchangeOperatorParser.PARAMETER_WEIGHTS, pw),
getWeightAttribute(operator.getWeight())
};
} else {
attributes = new Attribute[]{
new Attribute.Default<Double>(DeltaExchangeOperatorParser.DELTA, operator.getTuning()),
getWeightAttribute(operator.getWeight())
};
}
writer.writeOpenTag(DeltaExchangeOperatorParser.DELTA_EXCHANGE, attributes);
writeParameter1Ref(writer, operator);
writer.writeCloseTag(DeltaExchangeOperatorParser.DELTA_EXCHANGE);
}
示例7: getMeanPriorAttributes
import dr.util.Attribute; //导入依赖的package包/类
private Attribute[] getMeanPriorAttributes(HierarchicalPhylogeneticModel hpm) {
return new Attribute[] {
new Attribute.Default<String>(XMLParser.ID, getMeanPriorName(hpm)),
new Attribute.Default<Double>(PriorParsers.MEAN, hpm.getConditionalParameterList().get(0).mean),
new Attribute.Default<Double>(PriorParsers.STDEV, hpm.getConditionalParameterList().get(0).stdev),
};
}
示例8: getPrecisionPriorAttributes
import dr.util.Attribute; //导入依赖的package包/类
private Attribute[] getPrecisionPriorAttributes(HierarchicalPhylogeneticModel hpm) {
return new Attribute[] {
new Attribute.Default<String>(XMLParser.ID, getPrecisionPriorName(hpm)),
new Attribute.Default<Double>(PriorParsers.SHAPE, hpm.getConditionalParameterList().get(1).shape),
new Attribute.Default<Double>(PriorParsers.SCALE, hpm.getConditionalParameterList().get(1).scale),
new Attribute.Default<Double>(PriorParsers.OFFSET, 0.0),
};
}
示例9: writeTaxaRef
import dr.util.Attribute; //导入依赖的package包/类
private void writeTaxaRef(String taxaId, PartitionTreeModel model, XMLWriter writer) {
Attribute[] taxaAttribute = {new Attribute.Default<String>(XMLParser.IDREF, taxaId)};
if (options.taxonSets != null && options.taxonSets.size() > 0 && !options.useStarBEAST) { // need !options.useStarBEAST,
// *BEAST case is in STARBEASTGenerator.writeStartingTreeForCalibration(XMLWriter writer)
writer.writeOpenTag(OldCoalescentSimulatorParser.CONSTRAINED_TAXA);
writer.writeTag(TaxaParser.TAXA, taxaAttribute, true);
for (Taxa taxa : options.taxonSets) {
if (options.taxonSetsTreeModel.get(taxa).equals(model)) {
Parameter statistic = options.getStatistic(taxa);
Attribute mono = new Attribute.Default<Boolean>(
OldCoalescentSimulatorParser.IS_MONOPHYLETIC, options.taxonSetsMono.get(taxa));
writer.writeOpenTag(OldCoalescentSimulatorParser.TMRCA_CONSTRAINT, mono);
writer.writeIDref(TaxaParser.TAXA, taxa.getId());
if (model.getPartitionTreePrior().getNodeHeightPrior() == TreePriorType.YULE_CALIBRATION
&& statistic.priorType == PriorType.UNIFORM_PRIOR) {
writeDistribution(statistic, false, writer);
}
writer.writeCloseTag(OldCoalescentSimulatorParser.TMRCA_CONSTRAINT);
}
}
writer.writeCloseTag(OldCoalescentSimulatorParser.CONSTRAINED_TAXA);
} else {
writer.writeTag(TaxaParser.TAXA, taxaAttribute, true);
}
}
示例10: writeGLMCoefficientOperator
import dr.util.Attribute; //导入依赖的package包/类
private void writeGLMCoefficientOperator(PartitionSubstitutionModel model, XMLWriter writer) {
writer.writeOpenTag(MultivariateNormalOperator.MVN_OPERATOR,
new Attribute[]{
new Attribute.Default<Double>(MultivariateNormalOperator.SCALE_FACTOR, 1.0),
new Attribute.Default<Double>(MultivariateNormalOperator.WEIGHT,5.0),
new Attribute.Default<String>(MultivariateNormalOperator.FORM_XTX, "true")
}
);
String prefix = model.getName() + ".";
writeParameterRef(prefix + "coefficients", writer);
writer.writeOpenTag(MultivariateNormalOperator.VARIANCE_MATRIX);
writeParameterRef(prefix + DesignMatrix.DESIGN_MATRIX, writer);
writer.writeCloseTag(MultivariateNormalOperator.VARIANCE_MATRIX);
writer.writeCloseTag(MultivariateNormalOperator.MVN_OPERATOR);
}
示例11: prettyName
import dr.util.Attribute; //导入依赖的package包/类
@Override
public String prettyName() {
String s = distribution.getClass().getName();
String[] parts = s.split("\\.");
s = parts[parts.length - 1];
if( s.endsWith("Distribution") ) {
s = s.substring(0, s.length() - "Distribution".length());
}
s = s + '(';
for( Attribute<double[]> data : dataList ) {
String name = data.getAttributeName();
if( name == null ) {
name = "?";
}
s = s + name + ',';
}
s = s.substring(0,s.length()-1) + ')';
return s;
}
示例12: 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;
}
示例13: writeTaxonTraits
import dr.util.Attribute; //导入依赖的package包/类
private void writeTaxonTraits(Taxon taxon, XMLWriter writer) {
for (AbstractPartitionData partition : options.getDataPartitions(ContinuousDataType.INSTANCE)) {
writer.writeOpenTag(AttributeParser.ATTRIBUTE, new Attribute[]{
new Attribute.Default<String>(Attribute.NAME, partition.getName())});
StringBuilder sb = new StringBuilder();
boolean first = true;
for (TraitData trait : partition.getTraits()) {
if (!first) {
sb.append(" ");
}
if (taxon.containsAttribute(trait.getName())) {
sb.append(taxon.getAttribute(trait.getName()).toString());
} else {
sb.append("?");
}
first = false;
}
writer.writeText(sb.toString());
writer.writeCloseTag(AttributeParser.ATTRIBUTE);
}
}
示例14: writeGLMBinomialLikelihood
import dr.util.Attribute; //导入依赖的package包/类
private void writeGLMBinomialLikelihood(PartitionSubstitutionModel model, XMLWriter writer) {
double proportion = 1.0 - Math.exp(Math.log(0.5) / model.getTraitData().getIncludedPredictorCount());
String prefix = model.getName() + ".";
writer.writeComment("Using the binomialLikelihood we specify a 50% prior mass on no predictors being included.");
writer.writeOpenTag(BinomialLikelihood.BINOMIAL_LIKELIHOOD);
writer.writeOpenTag(BinomialLikelihoodParser.PROPORTION);
writer.writeTag("parameter", new Attribute.Default<Double>("value", proportion), true);
writer.writeCloseTag(BinomialLikelihoodParser.PROPORTION);
// the dimension of this parameter will be set automatically to be the same as the counts.
writer.writeOpenTag(BinomialLikelihoodParser.TRIALS);
writer.writeTag("parameter", new Attribute[]{
new Attribute.Default<Double>("value", 1.0)
}, true);
writer.writeCloseTag(BinomialLikelihoodParser.TRIALS);
writer.writeOpenTag(BinomialLikelihoodParser.COUNTS);
writeParameterRef(prefix + "coefIndicators", writer);
writer.writeCloseTag(BinomialLikelihoodParser.COUNTS);
writer.writeCloseTag(BinomialLikelihood.BINOMIAL_LIKELIHOOD);
}
示例15: writeStatisticModel
import dr.util.Attribute; //导入依赖的package包/类
private void writeStatisticModel(PartitionSubstitutionModel model, XMLWriter writer) {
String prefix = model.getName() + ".";
writer.writeOpenTag(SumStatisticParser.SUM_STATISTIC, new Attribute[]{
new Attribute.Default<String>(XMLParser.ID, prefix + "nonZeroRates"),
new Attribute.Default<Boolean>(SumStatisticParser.ELEMENTWISE, true)});
writer.writeIDref(ParameterParser.PARAMETER, prefix + "indicators");
writer.writeCloseTag(SumStatisticParser.SUM_STATISTIC);
writer.writeOpenTag(ProductStatisticParser.PRODUCT_STATISTIC, new Attribute[]{
new Attribute.Default<String>(XMLParser.ID, prefix + "actualRates"),
new Attribute.Default<Boolean>(SumStatisticParser.ELEMENTWISE, false)});
writer.writeIDref(ParameterParser.PARAMETER, prefix + "indicators");
writer.writeIDref(ParameterParser.PARAMETER, prefix + "rates");
writer.writeCloseTag(ProductStatisticParser.PRODUCT_STATISTIC);
}