本文整理汇总了Java中beast.core.Distribution类的典型用法代码示例。如果您正苦于以下问题:Java Distribution类的具体用法?Java Distribution怎么用?Java Distribution使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Distribution类属于beast.core包,在下文中一共展示了Distribution类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initAndValidate
import beast.core.Distribution; //导入依赖的package包/类
@Override
public void initAndValidate() {
super.initAndValidate();
if (populationShapeInput.get() == null ^ populationMeanInput.get() == null) {
throw new IllegalArgumentException("Either specify both population size prior parameters for analytical integration,"
+ "or neither for MCMC integration of population sizes.");
} else if (populationShapeInput.get() == null) {
dontCalculate = true;
return;
}
final List<Distribution> geneTrees = pDistributions.get();
dontCalculate = false;
checkHyperparameters(true);
nGeneTrees = geneTrees.size();
perGenePloidy = new double[nGeneTrees];
speciesNodeCount = -1;
for (int geneI = 0; geneI < nGeneTrees; geneI++) {
final Distribution pDist = geneTrees.get(geneI);
if (pDist instanceof GeneTree) {
final GeneTree gt = (GeneTree) pDist;
perGenePloidy[geneI] = gt.getPloidy();
if (speciesNodeCount == -1)
speciesNodeCount = gt.speciesTreeInput.get().getNodeCount();
} else { // check that all input distributions are gene trees
throw new IllegalArgumentException("Input distributions must all be of class GeneTree.");
}
}
if (speciesNodeCount != -1) { // not BEAUTi
allLineageCounts = new int[speciesNodeCount*nGeneTrees];
allEventCounts = new int[speciesNodeCount*nGeneTrees];
allCoalescentTimes = new double[speciesNodeCount*nGeneTrees][];
perBranchLogP = new double[speciesNodeCount];
storedLineageCounts = new int[speciesNodeCount*nGeneTrees];
storedEventCounts = new int[speciesNodeCount*nGeneTrees];
storedCoalescentTimes = new double[speciesNodeCount*nGeneTrees][];
storedPerBranchLogP = new double[speciesNodeCount];
}
}
示例2: addTraitSet
import beast.core.Distribution; //导入依赖的package包/类
/**
* assigns trait to first available tree *
*/
void addTraitSet(TraitSet trait) {
if (trait != null) {
CompoundDistribution likelihood = (CompoundDistribution) pluginmap.get("likelihood");
for (Distribution d : likelihood.pDistributions.get()) {
if (d instanceof GenericTreeLikelihood) {
try {
// TODO: this might not be a valid type conversion from TreeInterface to Tree
Tree tree = (Tree) ((GenericTreeLikelihood) d).treeInput.get();
tree.m_traitList.setValue(trait, tree);
} catch (Exception e) {
e.printStackTrace();
}
scrubAll(true, false);
return;
}
}
}
}
示例3: getNonStochasticLogP
import beast.core.Distribution; //导入依赖的package包/类
@Override
public double getNonStochasticLogP() {
double logP = 0;
if (ignore) {
return logP;
}
// The loop could gain a little bit from being multithreaded
// though getNonStochasticLogP is called for debugging purposes only
// so efficiency is not an immediate issue.
for (Distribution dists : pDistributions.get()) {
logP += dists.getNonStochasticLogP();
if (Double.isInfinite(logP) || Double.isNaN(logP)) {
return logP;
}
}
return logP;
}
示例4: assertParameterCountInPriorIs
import beast.core.Distribution; //导入依赖的package包/类
void assertParameterCountInPriorIs(int i) {
// count nr of parameters in Prior objects in prior
// including those for prior distributions (Normal, etc)
// useful to make sure they do (or do not) get linked
Set<Function> parameters = new LinkedHashSet<>();
CompoundDistribution prior = (CompoundDistribution) doc.pluginmap.get("prior");
for (Distribution p : prior.pDistributions.get()) {
if (p instanceof Prior) {
Prior p2 = (Prior) p;
parameters.add(p2.m_x.get());
for (BEASTInterface o : p2.distInput.get().listActiveBEASTObjects()) {
if (o instanceof Parameter) {
parameters.add((Parameter<?>) o);
}
}
}
}
System.err.println("Number of parameters in prior = " + parameters.size());
if (i >= 0) {
assertThat(parameters.size()).as("Expected " + i + " parameters in prior").isEqualTo(i);
}
}
示例5: updateParticle
import beast.core.Distribution; //导入依赖的package包/类
protected void updateParticle(int sampleNr) {
if (particleCount > 1) {
// init state
state.fromXML(particleStates[Randomizer.nextInt(particleCount)]);
// init calculation nodes & oldLogPrior
robustlyCalcPosterior(posterior);
}
oldLogPrior = 0;
for (Distribution d : samplingDistribution) {
oldLogPrior += d.getArrayValue();
}
if (autoLoopLength) {
int acceptCount = 0;
int j = 0;
while (acceptCount < paramCount * paramCountFactor) {
boolean accept = composeProposal(j + subChainLength * sampleNr);
if (accept) {
acceptCount++;
}
j++;
}
//System.err.println(j);
} else {
for (int j = 0; j < subChainLength; j++) {
composeProposal(j + subChainLength * sampleNr);
}
}
}
示例6: updateParticle
import beast.core.Distribution; //导入依赖的package包/类
@Override
protected void updateParticle(int sampleNr) {
// nsCountDown = new CountDownLatch(1);
// countDown.countDown();
// try {
// nsCountDown.await();
// } catch (InterruptedException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
int n = particlePool.size();
synchronized (particlePool) {
Object [] states = particlePool.keySet().toArray();
//String [] states = (String []) o;
int i = Randomizer.nextInt(n);
while (particlePool.get(states[i]) < minLikelihood) {
i = Randomizer.nextInt(n);
}
state.fromXML((String) states[i]);
}
// init calculation nodes & oldLogPrior
robustlyCalcPosterior(posterior);
oldLogPrior = 0;
for (Distribution d : samplingDistribution) {
oldLogPrior += d.getArrayValue();
}
for (int j = 0; j < subChainLength; j++) {
composeProposal(j + subChainLength * sampleNr);
}
}
示例7: testUniformity
import beast.core.Distribution; //导入依赖的package包/类
public void testUniformity() throws Exception {
Double[] m_parameters = new Double[length];
Integer[] m_indices = new Integer[length];
Integer[] m_sizes = new Integer[length];
for (int i = 0; i < length; ++i) {
m_parameters[i] = 1.;
m_indices[i] = i;
m_sizes[i] = 1;
}
StateNode parameters = new RealParameter(m_parameters);
StateNode indices = new IntegerParameter(m_indices);
StateNode sizes = new IntegerParameter(m_sizes);
State state = new State();
state.initByName("stateNode", parameters, "stateNode", indices,
"stateNode", sizes);
RescaledDirichlet rescaledDirichlet = new RescaledDirichlet();
rescaledDirichlet.initByName("sizes", sizes);
Distribution prior = new Prior();
prior.initByName("x", parameters, "distr", rescaledDirichlet);
Operator merger = new MergeOperator();
merger.initByName("parameters", parameters, "groupings", indices,
"sizes", sizes, "weight", 1.);
Operator splitter = new SplitOperator();
splitter.initByName("parameters", parameters, "groupings", indices,
"sizes", sizes, "weight", 1.);
// It would be nice to have a logger that could just write the results
// into a list, so we can easily check the likelihood that this does
// indeed form a uniform prior, and show how to analyse results.
MCMC mcmc = new MCMC();
mcmc.initByName("chainLength", 100000, "preBurnin", 1, "state", state,
"distribution", prior, "operator", merger, "operator", splitter);
mcmc.run();
throw new RuntimeException("The core of this test remains unimplemented");
}
示例8: createDistribution
import beast.core.Distribution; //导入依赖的package包/类
@Override
public List<Distribution> createDistribution(BeautiDoc doc) {
MRCAPrior prior = new MRCAPrior();
try {
List<Tree> trees = new ArrayList<>();
getDoc().scrubAll(true, false);
State state = (State) doc.pluginmap.get("state");
for (StateNode node : state.stateNodeInput.get()) {
if (node instanceof Tree) { // && ((Tree) node).m_initial.get() != null) {
trees.add((Tree) node);
}
}
int treeIndex = 0;
if (trees.size() > 1) {
String[] treeIDs = new String[trees.size()];
for (int j = 0; j < treeIDs.length; j++) {
treeIDs[j] = trees.get(j).getID();
}
treeIndex = JOptionPane.showOptionDialog(null, "Select a tree", "MRCA selector",
JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null,
treeIDs, trees.get(0));
}
if (treeIndex < 0) {
return null;
}
prior.treeInput.setValue(trees.get(treeIndex), prior);
TaxonSet taxonSet = new TaxonSet();
TaxonSetDialog dlg = new TaxonSetDialog(taxonSet, getTaxonCandidates(prior), doc);
if (!dlg.showDialog() || dlg.taxonSet.getID() == null || dlg.taxonSet.getID().trim().equals("")) {
return null;
}
taxonSet = dlg.taxonSet;
if (taxonSet.taxonsetInput.get().size() == 0) {
JOptionPane.showMessageDialog(doc.beauti, "At least one taxon should be included in the taxon set",
"Error specifying taxon set", JOptionPane.ERROR_MESSAGE);
return null;
}
int i = 1;
String id = taxonSet.getID();
while (doc.pluginmap.containsKey(taxonSet.getID()) && doc.pluginmap.get(taxonSet.getID()) != taxonSet) {
taxonSet.setID(id + i);
i++;
}
BEASTObjectPanel.addPluginToMap(taxonSet, doc);
prior.taxonsetInput.setValue(taxonSet, prior);
prior.setID(taxonSet.getID() + ".prior");
// this sets up the type
prior.distInput.setValue(new OneOnX(), prior);
// this removes the parametric distribution
prior.distInput.setValue(null, prior);
Logger logger = (Logger) doc.pluginmap.get("tracelog");
logger.loggersInput.setValue(prior, logger);
} catch (Exception e) {
// TODO: handle exception
}
List<Distribution> selectedPlugins = new ArrayList<>();
selectedPlugins.add(prior);
g_collapsedIDs.add(prior.getID());
return selectedPlugins;
}
示例9: customConnector
import beast.core.Distribution; //导入依赖的package包/类
public static void customConnector(BeautiDoc doc) {
Object o0 = doc.pluginmap.get("prior");
if (o0 != null && o0 instanceof CompoundDistribution) {
CompoundDistribution p = (CompoundDistribution) o0;
for (Distribution p0 : p.pDistributions.get()) {
if (p0 instanceof MRCAPrior) {
MRCAPrior prior = (MRCAPrior) p0;
if (prior.treeInput.get() != null) {
boolean isInState = false;
for (BEASTInterface o : prior.treeInput.get().getOutputs()) {
if (o instanceof State) {
isInState = true;
break;
}
}
if (!isInState) {
doc.disconnect(prior, "prior", "distribution");
doc.disconnect(prior, "tracelog", "log");
if (prior.onlyUseTipsInput.get()) {
disableTipSampling(prior, doc);
}
doc.unregisterPlugin(prior);
return;
}
}
}
}
}
}
示例10: sample
import beast.core.Distribution; //导入依赖的package包/类
@Override
public void sample(State state, Random random) {
if (sampledFlag)
return;
sampledFlag = true;
for (Distribution distribution : pDistributions.get()) {
distribution.sample(state, random);
}
}
示例11: getArguments
import beast.core.Distribution; //导入依赖的package包/类
@Override
public List<String> getArguments() {
List<String> arguments = new ArrayList<>();
for (Distribution distribution : pDistributions.get()) {
arguments.addAll(distribution.getArguments());
}
return arguments;
}
示例12: getConditions
import beast.core.Distribution; //导入依赖的package包/类
@Override
public List<String> getConditions() {
List<String> conditions = new ArrayList<>();
for (Distribution distribution : pDistributions.get()) {
conditions.addAll(distribution.getConditions());
}
conditions.removeAll(getArguments());
return conditions;
}
示例13: isStochastic
import beast.core.Distribution; //导入依赖的package包/类
@Override
public boolean isStochastic() {
for (Distribution distribution : pDistributions.get()) {
if (distribution.isStochastic())
return true;
}
return false;
}
示例14: requiresRecalculation
import beast.core.Distribution; //导入依赖的package包/类
public boolean requiresRecalculation(){
if(concentrationParameter.somethingIsDirty()){
return true;
}
for(Distribution paramDistr: baseDistributions){
if(paramDistr.isDirtyCalculation()){
return true;
}
}
return false;
}
示例15: calculateLogP
import beast.core.Distribution; //导入依赖的package包/类
@Override
public double calculateLogP() {
super.calculateLogP();
// System.out.println(tmpLogP + " -> " + logP);
if (dontCalculate || Double.isInfinite(logP) || Double.isNaN(logP)) return logP;
// need to recompute all branches if the parameters of the prior distribution have changed
final boolean updatedPrior = checkHyperparameters(false);
final int[] branchLineageCounts = new int[nGeneTrees];
final int[] branchEventCounts = new int[nGeneTrees];
final double[][] branchCoalescentTimes = new double[nGeneTrees][];
final List<Distribution> pDists = pDistributions.get();
final GeneTree[] geneTrees = new GeneTree[pDists.size()];
int nodeGeneI = 0;
for (int nodeI = 0; nodeI < speciesNodeCount; nodeI++) {
boolean dirtyBranch = false;
for (int geneI = 0; geneI < nGeneTrees; geneI++) {
if (nodeI == 0) geneTrees[geneI] = (GeneTree) pDists.get(geneI);
final GeneTree geneTree = geneTrees[geneI];
if (geneTree.isDirtyBranch(nodeI)) {
dirtyBranch = true;
final double[] geneBranchCoalescentTimes = geneTree.getCoalescentTimes(nodeI);
final int geneBranchLineageCount = geneTree.coalescentLineageCounts[nodeI];
final int geneBranchEventCount = geneTree.coalescentCounts[nodeI];
allLineageCounts[nodeGeneI] = geneBranchLineageCount;
allEventCounts[nodeGeneI] = geneBranchEventCount;
allCoalescentTimes[nodeGeneI] = geneBranchCoalescentTimes;
}
branchLineageCounts[geneI] = allLineageCounts[nodeGeneI];
branchEventCounts[geneI] = allEventCounts[nodeGeneI];
branchCoalescentTimes[geneI] = allCoalescentTimes[nodeGeneI];
nodeGeneI++;
}
if (updatedPrior || dirtyBranch)
perBranchLogP[nodeI] = analyticalLogP(alpha, beta, perGenePloidy, branchCoalescentTimes, branchLineageCounts, branchEventCounts);
logP += perBranchLogP[nodeI];
}
return logP;
}