本文整理汇总了Java中dr.util.Attribute.Default方法的典型用法代码示例。如果您正苦于以下问题:Java Attribute.Default方法的具体用法?Java Attribute.Default怎么用?Java Attribute.Default使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dr.util.Attribute
的用法示例。
在下文中一共展示了Attribute.Default方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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");
}
示例2: 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);
}
示例3: 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);
}
示例4: 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);
}
}
示例5: getModelAttributes
import dr.util.Attribute; //导入方法依赖的package包/类
private Attribute[] getModelAttributes(HierarchicalPhylogeneticModel hpm) {
switch (hpm.getPriorType()){
case NORMAL_HPM_PRIOR:
return new Attribute[] {
new Attribute.Default<String>(XMLParser.ID, getModelName(hpm)),
};
case LOGNORMAL_HPM_PRIOR:
return new Attribute[] {
new Attribute.Default<String>(XMLParser.ID, getModelName(hpm)),
//new Attribute.Default<Boolean>(LogNormalDistributionModelParser.MEAN_IN_REAL_SPACE, false),
};
default:
}
throw new RuntimeException("Unimplemented HPM prior type");
}
示例6: 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),
};
}
示例7: 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),
};
}
示例8: 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;
}
示例9: writeParameter
import dr.util.Attribute; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
private void writeParameter(String wrapper, String id, int dimension,
String value, XMLWriter writer) {
if (wrapper != null) {
writer.writeOpenTag(wrapper);
}
ArrayList<Attribute.Default> attributes = new ArrayList<Attribute.Default>();
if (id != null) {
attributes.add(new Attribute.Default<String>(XMLParser.ID, id));
}
if (dimension > 1) {
attributes.add(new Attribute.Default<String>(
ParameterParser.DIMENSION, String.valueOf(dimension)));
}
if (value != null) {
attributes.add(new Attribute.Default<String>(ParameterParser.VALUE,
value));
}
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);
if (wrapper != null) {
writer.writeCloseTag(wrapper);
}
}
示例10: writeTaxon
import dr.util.Attribute; //导入方法依赖的package包/类
/**
* Generate a taxa block from these beast options
*
* @param writer the writer
* @param taxon the taxon to write
* @throws dr.app.util.Arguments.ArgumentException
* ArgumentException
*/
private void writeTaxon(Taxon taxon, boolean hasDate, boolean hasAttr, XMLWriter writer) throws Arguments.ArgumentException {
writer.writeTag(TaxonParser.TAXON, new Attribute[]{
new Attribute.Default<String>(XMLParser.ID, taxon.getId())},
!(hasDate || hasAttr)); // false if any of hasDate or hasAttr is true
if (hasDate) {
dr.evolution.util.Date date = (dr.evolution.util.Date) taxon.getAttribute(dr.evolution.util.Date.DATE);
Attribute[] attributes;
if (date.getUncertainty() > 0.0) {
attributes = new Attribute[] {
new Attribute.Default<Double>(DateParser.VALUE, date.getTimeValue()),
new Attribute.Default<String>(DateParser.DIRECTION, date.isBackwards() ? DateParser.BACKWARDS : DateParser.FORWARDS),
new Attribute.Default<String>(DateParser.UNITS, Units.Utils.getDefaultUnitName(options.units)),
new Attribute.Default<Double>(DateParser.UNCERTAINTY, date.getUncertainty())
};
} else {
attributes = new Attribute[] {
new Attribute.Default<Double>(DateParser.VALUE, date.getTimeValue()),
new Attribute.Default<String>(DateParser.DIRECTION, date.isBackwards() ? DateParser.BACKWARDS : DateParser.FORWARDS),
new Attribute.Default<String>(DateParser.UNITS, Units.Utils.getDefaultUnitName(options.units))
//new Attribute.Default("origin", date.getOrigin()+"")
};
}
writer.writeTag(dr.evolution.util.Date.DATE, attributes, true);
}
for (TraitData trait : options.traits) {
// there is no harm in allowing the species trait to be listed in the taxa
// if (!trait.getName().equalsIgnoreCase(TraitData.TRAIT_SPECIES)) {
writer.writeOpenTag(AttributeParser.ATTRIBUTE, new Attribute[]{
new Attribute.Default<String>(Attribute.NAME, trait.getName())});
// denotes missing data using '?'
writer.writeText(taxon.containsAttribute(trait.getName()) ? taxon.getAttribute(trait.getName()).toString() : "?");
writer.writeCloseTag(AttributeParser.ATTRIBUTE);
// }
}
generateInsertionPoint(ComponentGenerator.InsertionPoint.IN_TAXON, taxon, writer);
if (hasDate || hasAttr) writer.writeCloseTag(TaxonParser.TAXON);
}
示例11: writeTreeLikelihood
import dr.util.Attribute; //导入方法依赖的package包/类
/**
* Write the tree likelihood XML block.
*
* @param id the id of the tree likelihood
* @param num the likelihood number
* @param partition the partition to write likelihood block for
* @param writer the writer
*/
private void writeTreeLikelihood(String tag, String id, int num, PartitionData partition, XMLWriter writer) {
PartitionSubstitutionModel substModel = partition.getPartitionSubstitutionModel();
PartitionTreeModel treeModel = partition.getPartitionTreeModel();
PartitionClockModel clockModel = partition.getPartitionClockModel();
writer.writeComment("Likelihood for tree given sequence data");
String prefix;
if (num > 0) {
prefix = partition.getPrefix() + substModel.getPrefixCodon(num);
} else {
prefix = partition.getPrefix();
}
String idString = prefix + id;
Attribute[] attributes;
if (tag.equals(MarkovJumpsTreeLikelihoodParser.MARKOV_JUMP_TREE_LIKELIHOOD)) {
AncestralStatesComponentOptions ancestralStatesOptions = (AncestralStatesComponentOptions) options
.getComponentOptions(AncestralStatesComponentOptions.class);
boolean saveCompleteHistory = ancestralStatesOptions.isCompleteHistoryLogging(partition);
attributes = new Attribute[]{
new Attribute.Default<String>(XMLParser.ID, idString),
new Attribute.Default<Boolean>(TreeLikelihoodParser.USE_AMBIGUITIES, substModel.isUseAmbiguitiesTreeLikelihood()),
new Attribute.Default<Boolean>(MarkovJumpsTreeLikelihoodParser.USE_UNIFORMIZATION, true),
new Attribute.Default<Integer>(MarkovJumpsTreeLikelihoodParser.NUMBER_OF_SIMULANTS, 1),
new Attribute.Default<String>(AncestralStateTreeLikelihoodParser.RECONSTRUCTION_TAG_NAME, prefix + AncestralStateTreeLikelihoodParser.RECONSTRUCTION_TAG),
new Attribute.Default<String>(MarkovJumpsTreeLikelihoodParser.SAVE_HISTORY, saveCompleteHistory ? "true" : "false"),
};
} else if (tag.equals(TreeLikelihoodParser.ANCESTRAL_TREE_LIKELIHOOD)) {
attributes = new Attribute[]{
new Attribute.Default<String>(XMLParser.ID, idString),
new Attribute.Default<Boolean>(TreeLikelihoodParser.USE_AMBIGUITIES, substModel.isUseAmbiguitiesTreeLikelihood()),
new Attribute.Default<String>(AncestralStateTreeLikelihoodParser.RECONSTRUCTION_TAG_NAME, prefix + AncestralStateTreeLikelihoodParser.RECONSTRUCTION_TAG),
};
} else {
attributes = new Attribute[]{
new Attribute.Default<String>(XMLParser.ID, idString),
new Attribute.Default<Boolean>(TreeLikelihoodParser.USE_AMBIGUITIES, substModel.isUseAmbiguitiesTreeLikelihood())
};
}
writer.writeOpenTag(tag, attributes);
if (!options.samplePriorOnly) {
if (num > 0) {
writeCodonPatternsRef(prefix, num, substModel.getCodonPartitionCount(), writer);
} else {
writer.writeIDref(SitePatternsParser.PATTERNS, prefix + SitePatternsParser.PATTERNS);
}
} else {
// We just need to use the dummy alignment
writer.writeIDref(AlignmentParser.ALIGNMENT, partition.getAlignment().getId());
}
writer.writeIDref(TreeModel.TREE_MODEL, treeModel.getPrefix() + TreeModel.TREE_MODEL);
if (num > 0) {
writer.writeIDref(GammaSiteModel.SITE_MODEL, substModel.getPrefix(num) + SiteModel.SITE_MODEL);
} else {
writer.writeIDref(GammaSiteModel.SITE_MODEL, substModel.getPrefix() + SiteModel.SITE_MODEL);
}
ClockModelGenerator.writeBranchRatesModelRef(clockModel, writer);
generateInsertionPoint(ComponentGenerator.InsertionPoint.IN_TREE_LIKELIHOOD, partition, prefix, writer);
writer.writeCloseTag(tag);
}
示例12: writeStartingTreeForCalibration
import dr.util.Attribute; //导入方法依赖的package包/类
public void writeStartingTreeForCalibration(XMLWriter writer) {
writer.writeComment("species starting tree for calibration");
writer.writeText("");
writer.writeOpenTag(OldCoalescentSimulatorParser.COALESCENT_TREE,
new Attribute[]{new Attribute.Default<String>(XMLParser.ID, SP_START_TREE)}
);
Attribute[] taxaAttribute = {new Attribute.Default<String>(XMLParser.IDREF, ALL_SPECIES)};
writer.writeOpenTag(OldCoalescentSimulatorParser.CONSTRAINED_TAXA);
writer.writeTag(TaxaParser.TAXA, taxaAttribute, true);
for (Taxa taxa : options.speciesSets) {
Parameter statistic = options.getStatistic(taxa);
Attribute mono = new Attribute.Default<Boolean>(
OldCoalescentSimulatorParser.IS_MONOPHYLETIC, options.speciesSetsMono.get(taxa));
writer.writeOpenTag(OldCoalescentSimulatorParser.TMRCA_CONSTRAINT, mono);
writer.writeIDref(TaxaParser.TAXA, taxa.getId());
if (options.getPartitionTreePriors().get(0).getNodeHeightPrior() == TreePriorType.SPECIES_YULE_CALIBRATION
&& statistic.priorType == PriorType.UNIFORM_PRIOR) {
writeDistribution(statistic, false, writer);
}
writer.writeCloseTag(OldCoalescentSimulatorParser.TMRCA_CONSTRAINT);
}
writer.writeCloseTag(OldCoalescentSimulatorParser.CONSTRAINED_TAXA);
writer.writeOpenTag(ConstantPopulationModelParser.CONSTANT_POPULATION_MODEL,
new Attribute[]{
new Attribute.Default<String>(XMLParser.ID, "spInitDemo"),
new Attribute.Default<String>("units", Units.Utils.getDefaultUnitName(options.units))
});
writer.writeOpenTag(ConstantPopulationModelParser.POPULATION_SIZE);
double popSizeValue = options.getPartitionTreePriors().get(0).getParameter("constant.popSize").getInitial(); // "initial" is "value"
writer.writeTag(ParameterParser.PARAMETER, new Attribute[]{
new Attribute.Default<String>(XMLParser.ID, "sp.popSize"),
new Attribute.Default<Double>(ParameterParser.VALUE, popSizeValue)
}, true);
writer.writeCloseTag(ConstantPopulationModelParser.POPULATION_SIZE);
writer.writeCloseTag(ConstantPopulationModelParser.CONSTANT_POPULATION_MODEL);
writer.writeCloseTag(OldCoalescentSimulatorParser.COALESCENT_TREE);
}
示例13: writeOperatorSchedule
import dr.util.Attribute; //导入方法依赖的package包/类
/**
* Write the operator schedule XML block.
*
* @param operators the list of operators
* @param writer the writer
*/
public void writeOperatorSchedule(List<Operator> operators, XMLWriter writer) {
Attribute[] operatorAttributes;
// certain models would benefit from a logarithm operator optimization
boolean shouldLogCool = false;
for (PartitionTreePrior partition : options.getPartitionTreePriors()) {
if (partition.getNodeHeightPrior() == TreePriorType.SKYGRID ||
partition.getNodeHeightPrior() == TreePriorType.GMRF_SKYRIDE) {
shouldLogCool = true;
break;
}
}
for (PartitionSubstitutionModel model : options.getPartitionSubstitutionModels()) {
if (model.getDataType().getType() == DataType.GENERAL ||
model.getDataType().getType() == DataType.CONTINUOUS) {
shouldLogCool = true;
break;
}
}
operatorAttributes = new Attribute[] {
new Attribute.Default<String>(XMLParser.ID, "operators"),
new Attribute.Default<String>(SimpleOperatorScheduleParser.OPTIMIZATION_SCHEDULE,
(shouldLogCool ?
OperatorSchedule.OptimizationTransform.LOG.toString() :
OperatorSchedule.OptimizationTransform.DEFAULT.toString()))
};
writer.writeComment("Define operators");
writer.writeOpenTag(
SimpleOperatorScheduleParser.OPERATOR_SCHEDULE,
operatorAttributes
// new Attribute[]{new Attribute.Default<String>(XMLParser.ID, "operators")}
);
for (Operator operator : operators) {
if (operator.getWeight() > 0. && operator.isUsed()) {
writeOperator(operator, writer);
}
}
generateInsertionPoint(ComponentGenerator.InsertionPoint.IN_OPERATORS, writer); // Added for special operators
writer.writeCloseTag(SimpleOperatorScheduleParser.OPERATOR_SCHEDULE);
}
示例14: getWeightAttribute
import dr.util.Attribute; //导入方法依赖的package包/类
private Attribute getWeightAttribute(double weight) {
if (weight == (int) weight) {
return new Attribute.Default<Integer>("weight", (int) weight);
} else {
return new Attribute.Default<Double>("weight", weight);
}
}
示例15: writeSubTree
import dr.util.Attribute; //导入方法依赖的package包/类
private void writeSubTree(String treeId, String taxaId, Taxa taxa, PartitionTreeModel model, XMLWriter writer) {
Double height = options.taxonSetsHeights.get(taxa);
if (height == null) {
height = Double.NaN;
}
Attribute[] attributes = new Attribute[] {};
if (treeId != null) {
if (Double.isNaN(height)) {
attributes = new Attribute[] {
new Attribute.Default<String>(XMLParser.ID, treeId)
};
} else {
attributes = new Attribute[] {
new Attribute.Default<String>(XMLParser.ID, treeId),
new Attribute.Default<String>(CoalescentSimulatorParser.HEIGHT, "" + height)
};
}
} else {
if (!Double.isNaN(height)) {
attributes = new Attribute[] {
new Attribute.Default<String>(CoalescentSimulatorParser.HEIGHT, "" + height)
};
}
}
// construct a subtree
writer.writeOpenTag(
CoalescentSimulatorParser.COALESCENT_SIMULATOR,
attributes
);
List<Taxa> subsets = new ArrayList<Taxa>();
// Taxa remainingTaxa = new Taxa(taxa);
for (Taxa taxa2 : options.taxonSets) {
boolean sameTree = model.equals(options.taxonSetsTreeModel.get(taxa2));
boolean isMono = options.taxonSetsMono.get(taxa2);
boolean hasHeight = options.taxonSetsHeights.get(taxa2) != null;
boolean isSubset = taxa.containsAll(taxa2);
if (sameTree && (isMono || hasHeight) && taxa2 != taxa && isSubset) {
subsets.add(taxa2);
}
}
List<Taxa> toRemove = new ArrayList<Taxa>();
for (Taxa taxa3 : subsets) {
boolean isSubSubSet = false;
for (Taxa taxa4 : subsets) {
if (!taxa4.equals(taxa3) && taxa4.containsAll(taxa3)) {
isSubSubSet = true;
}
}
if (isSubSubSet) {
toRemove.add(taxa3);
}
}
subsets.removeAll(toRemove);
for (Taxa taxa5 : subsets) {
// remainingTaxa.removeTaxa(taxa5);
writeSubTree(null, null, taxa5, model, writer);
}
if (taxaId == null) {
writer.writeIDref(TaxaParser.TAXA, taxa.getId());
} else {
writer.writeIDref(TaxaParser.TAXA, taxaId);
}
writeInitialDemoModelRef(model, writer);
writer.writeCloseTag(CoalescentSimulatorParser.COALESCENT_SIMULATOR);
}