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


Java Likelihood类代码示例

本文整理汇总了Java中dr.inference.model.Likelihood的典型用法代码示例。如果您正苦于以下问题:Java Likelihood类的具体用法?Java Likelihood怎么用?Java Likelihood使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: main

import dr.inference.model.Likelihood; //导入依赖的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);
    }
 
开发者ID:beast-dev,项目名称:beast-mcmc,代码行数:38,代码来源:SliceOperator.java

示例2: testBirthDeathLikelihoodBEAST2

import dr.inference.model.Likelihood; //导入依赖的package包/类
public void testBirthDeathLikelihoodBEAST2() {
    System.out.println("RootHeight = " + tree2.getRootHeight());
    Variable<Double> origin = new Variable.D("origin", 6.0);

    final double birthRate = 2.0;
    final double deathRate = 1.0;
    final double psiRate = 0.5; // rate of sampling taxa through time
    final double sampleProbability = 0.0; // the proportion of taxa sampled, default to fix to 0
    final boolean hasFinalSample = false;
    Variable<Double> b = new Variable.D("b", birthRate);
    Variable<Double> d = new Variable.D("d", deathRate);
    Variable<Double> psi = new Variable.D("psi", psiRate);
    Variable<Double> p = new Variable.D("p", sampleProbability);
    Variable<Double> r = new Variable.D("r", 0.0); // sampleBecomesNonInfectiousProb

    SpeciationModel speciationModel = new BirthDeathSerialSamplingModel(b, d, psi, p, false, r, hasFinalSample, origin, Units.Type.YEARS);
    Likelihood likelihood = new SpeciationLikelihood(tree2, speciationModel, "bdss.like");

    assertEquals(-19.0198, likelihood.getLogLikelihood(), 1e-5);
}
 
开发者ID:beast-dev,项目名称:beast-mcmc,代码行数:21,代码来源:BirthDeathSSLikelihoodTest.java

示例3: CompoundGaussianProcess

import dr.inference.model.Likelihood; //导入依赖的package包/类
public CompoundGaussianProcess(List<GaussianProcessRandomGenerator> gpList, List<Likelihood> likelihoodList,
                               List<Integer> copyList) {
    this.gpList = gpList;
    this.copyList = copyList;
    this.likelihoodList = likelihoodList;
    compoundLikelihood = new CompoundLikelihood(likelihoodList);

    if (USE_POOL) {
        callers = createTasks();
        threadCount = callers.size();
        pool = Executors.newFixedThreadPool(threadCount);
    } else {
        callers = null;
        threadCount = -1;
        pool = null;
    }
}
 
开发者ID:beast-dev,项目名称:beast-mcmc,代码行数:18,代码来源:CompoundGaussianProcess.java

示例4: MLOptimizer

import dr.inference.model.Likelihood; //导入依赖的package包/类
/**
 * Constructor
 * @param chainLength the chain length
 * @param schedule operator schedule to be used in chain.
 */
public MLOptimizer(String id,
	int chainLength,
	Likelihood likelihood,
	OperatorSchedule schedule,
	Logger[] loggers) {

	this.id = id;

	mc = new MarkovChain(likelihood, schedule, new GreatDelugeCriterion(0.2), 2000, 1, MarkovChain.EVALUATION_TEST_THRESHOLD, false);
       //mc = new MarkovChain(null, likelihood, schedule, new HillClimbingCriterion(), false);

	this.chainLength = chainLength;
	this.likelihood = likelihood;
	this.loggers = loggers;

	setOperatorSchedule(schedule);

	//initialize transients
	currentState = 0;
}
 
开发者ID:beast-dev,项目名称:beast-mcmc,代码行数:26,代码来源:MLOptimizer.java

示例5: MarkovChain

import dr.inference.model.Likelihood; //导入依赖的package包/类
public MarkovChain(Likelihood likelihood,
                   OperatorSchedule schedule, Acceptor acceptor,
                   long fullEvaluationCount, int minOperatorCountForFullEvaluation, double evaluationTestThreshold,
                   boolean useCoercion) {

    currentLength = 0;
    this.likelihood = likelihood;
    this.schedule = schedule;
    this.acceptor = acceptor;
    this.useCoercion = useCoercion;

    this.fullEvaluationCount = fullEvaluationCount;
    this.minOperatorCountForFullEvaluation = minOperatorCountForFullEvaluation;
    this.evaluationTestThreshold = evaluationTestThreshold;

    Likelihood.CONNECTED_LIKELIHOOD_SET.add(likelihood);
    Likelihood.CONNECTED_LIKELIHOOD_SET.addAll(likelihood.getLikelihoodSet());

    for (Likelihood l : Likelihood.FULL_LIKELIHOOD_SET) {
        if (!Likelihood.CONNECTED_LIKELIHOOD_SET.contains(l)) {
            System.err.println("WARNING: Likelihood component, " + l.getId() + ", created but not used in the MCMC");
        }
    }

    currentScore = evaluate(likelihood);
}
 
开发者ID:beast-dev,项目名称:beast-mcmc,代码行数:27,代码来源:MarkovChain.java

示例6: doOperation

import dr.inference.model.Likelihood; //导入依赖的package包/类
public double doOperation(Likelihood likelihood) {
    if (!burnin) {
        if (sampleCount < samples * sampleEvery) {
            sampleCount++;
            if (sampleCount % sampleEvery == 0) {
                probabilityEstimater.addTree(tree);
            }
            setAcceptCount(0);
            setRejectCount(0);
            setTransitions(0);

            return doUnguidedOperation();

        } else {
            return doImportanceDistributionOperation(likelihood);
        }
    } else {

        return doUnguidedOperation();

    }
}
 
开发者ID:beast-dev,项目名称:beast-mcmc,代码行数:23,代码来源:AbstractImportanceDistributionOperator.java

示例7: restore

import dr.inference.model.Likelihood; //导入依赖的package包/类
protected void restore(Likelihood likelihood,
                       Model currentModel, MCMCOperator mcmcOperator, double oldScore) {
    currentModel.restoreModelState();

    // This is a test that the state is correctly restored. The restored
    // state is fully evaluated and the likelihood compared with that before
    // the operation was made.
    likelihood.makeDirty();
    final double testScore = evaluate(likelihood, 1.0);

    if (Math.abs(testScore - oldScore) > 1e-6) {
        Logger.getLogger("error").severe(
                "State was not correctly restored after reject step.\n"
                        + "Likelihood before: " + oldScore
                        + " Likelihood after: " + testScore + "\n"
                        + "Operator: " + mcmcOperator + " "
                        + mcmcOperator.getOperatorName());
    }
}
 
开发者ID:beast-dev,项目名称:beast-mcmc,代码行数:20,代码来源:SimpleMetropolizedGibbsOperator.java

示例8: doOperation

import dr.inference.model.Likelihood; //导入依赖的package包/类
@Override
public double doOperation(Likelihood likelihood) {

    final double[] initialPosition = leapFrogEngine.getInitialPosition();
    final double initialLogLikelihood = gradientProvider.getLikelihood().getLogLikelihood();

    if (stepSizeInformation == null) {
        stepSizeInformation = findReasonableStepSize(initialPosition);

        final double testLogLikelihood = gradientProvider.getLikelihood().getLogLikelihood();
        assert (testLogLikelihood == initialLogLikelihood);
        assert (Arrays.equals(leapFrogEngine.getInitialPosition(), initialPosition));
    }

    double[] position = takeOneStep(getCount() + 1, initialPosition);
    leapFrogEngine.setParameter(position);

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

示例9: constructInterval

import dr.inference.model.Likelihood; //导入依赖的package包/类
public Interval constructInterval(Likelihood likelihood, double x0,
                                  double cutoffDensity, double w) {
    // Taken from Fig 3 in Neal (2003)
    double L = x0 -  w * MathUtils.nextDouble();
    double R = L +  w;
    int J = MathUtils.nextInt(m);
    int K = (m - 1) - J;
    while (J > 0 && cutoffDensity < evaluate(likelihood, L) ) {
        L -=  w;
        J--;
    }
    while (K > 0 && cutoffDensity < evaluate(likelihood, R) ) {
        R +=  w;
        K--;
    }
    return new Interval(L,R);
}
 
开发者ID:beast-dev,项目名称:beast-mcmc,代码行数:18,代码来源:SliceInterval.java

示例10: ClusterOperator

import dr.inference.model.Likelihood; //导入依赖的package包/类
public ClusterOperator(Parameter assignments, MatrixParameter virusLocations, double weight, double windowSize, NPAntigenicLikelihood Likelihood, Parameter links) {
         	//System.out.println("Constructor");
             this.links = links;           	
             this.assignments = assignments;
             this.virusLocations = virusLocations;
             this.windowSize = windowSize;
             this.modelLikelihood = Likelihood;
             
             setWeight(weight);
             
             
             //load in the virusLocations
             System.out.println((int)assignments.getParameterValue(0));
             Parameter vLoc = virusLocations.getParameter(0);
     
     		//double d0=  vLoc.getParameterValue(0);
     		//double d1= vLoc.getParameterValue(1);
     		//System.out.println( d0 + "," + d1);
     		
             
             //System.exit(0);

}
 
开发者ID:beast-dev,项目名称:beast-mcmc,代码行数:24,代码来源:ClusterOperator.java

示例11: parseXMLObject

import dr.inference.model.Likelihood; //导入依赖的package包/类
public Object parseXMLObject(XMLObject xo) throws XMLParseException {

        ThreadedCompoundLikelihood compoundLikelihood = new ThreadedCompoundLikelihood();

        for (int i = 0; i < xo.getChildCount(); i++) {
            if (xo.getChild(i) instanceof Likelihood) {
                compoundLikelihood.addLikelihood((Likelihood) xo.getChild(i));
            } else {

                Object rogueElement = xo.getChild(i);

                throw new XMLParseException("An element (" + rogueElement + ") which is not a likelihood has been added to a " + THREADED_COMPOUND_LIKELIHOOD + " element");
            }
        }

        double weight = xo.getAttribute(WEIGHT, 0.0);
        if (weight < 0)
            throw new XMLParseException("Robust weight must be non-negative.");
        compoundLikelihood.setWeightFactor(Math.exp(-weight));

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

示例12: parseXMLObject

import dr.inference.model.Likelihood; //导入依赖的package包/类
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    int iterationCount = 1000;

    if (xo.hasAttribute("iterationCount")) {
        iterationCount = xo.getIntegerAttribute("iterationCount");
    }

    List<Likelihood> likelihoods = new ArrayList<Likelihood>();

    for (int i = 0; i < xo.getChildCount(); i++) {
        Object xco = xo.getChild(i);
        if (xco instanceof Likelihood) {
            likelihoods.add((Likelihood) xco);
        }
    }

    if (likelihoods.size() == 0) {
        throw new XMLParseException("No likelihoods for benchmarking");
    }

    return new LikelihoodBenchmarker(likelihoods, iterationCount);
}
 
开发者ID:beast-dev,项目名称:beast-mcmc,代码行数:23,代码来源:LikelihoodBenchmarkerParser.java

示例13: parseXMLObject

import dr.inference.model.Likelihood; //导入依赖的package包/类
public Object parseXMLObject(XMLObject xo) throws XMLParseException {

        int chainLength = xo.getIntegerAttribute(CHAIN_LENGTH);

        OperatorSchedule opsched = null;
        dr.inference.model.Likelihood likelihood = null;
        ArrayList<Logger> loggers = new ArrayList<Logger>();

        for (int i = 0; i < xo.getChildCount(); i++) {
            Object child = xo.getChild(i);
            if (child instanceof dr.inference.model.Likelihood) {
                likelihood = (dr.inference.model.Likelihood)child;
            } else if (child instanceof OperatorSchedule) {
                opsched = (OperatorSchedule)child;
            } else if (child instanceof Logger) {
                loggers.add((Logger)child);
            } else {
                throw new XMLParseException("Unrecognized element found in optimizer element:" + child);
            }
        }

        Logger[] loggerArray = new Logger[loggers.size()];
        loggers.toArray(loggerArray);

        return new MLOptimizer("optimizer1", chainLength, likelihood, opsched, loggerArray);
    }
 
开发者ID:beast-dev,项目名称:beast-mcmc,代码行数:27,代码来源:MLOptimizerParser.java

示例14: parseXMLObject

import dr.inference.model.Likelihood; //导入依赖的package包/类
@Override
	public Object parseXMLObject(XMLObject xo) throws XMLParseException {

		TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);

		// if(xo.hasChildNamed(TreeModel.TREE_MODEL)) {
		//
		// treeModel = (TreeModel) xo.getChild(TreeModel.class);
		// }

		Parameter zParameter = (Parameter) xo
				.getElementFirstChild(DirichletProcessPriorParser.CATEGORIES);

		List<Likelihood> likelihoods = new ArrayList<Likelihood>();

		XMLObject cxo = (XMLObject) xo.getChild(UNIQUE_LIKELIHOODS);
		for (int i = 0; i < cxo.getChildCount(); i++) {

			Likelihood likelihood = (Likelihood) cxo.getChild(i);
			likelihoods.add(likelihood);
		}

		return null;
//		new BeagleBranchLikelihood(
////				treeModel, likelihoods, zParameter
//				);
	}
 
开发者ID:beast-dev,项目名称:beast-mcmc,代码行数:28,代码来源:BeagleBranchLikelihoodParser.java

示例15: parseXMLObject

import dr.inference.model.Likelihood; //导入依赖的package包/类
@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {

	DirichletProcessPrior dpp = (DirichletProcessPrior) xo.getChild(DirichletProcessPrior.class);
	Likelihood likelihood = (Likelihood) xo .getElementFirstChild(DATA_LOG_LIKELIHOOD);
	Parameter categoriesParameter = (Parameter) xo.getElementFirstChild(  DirichletProcessPriorParser.CATEGORIES);
	
	CountableRealizationsParameter allParameters = (CountableRealizationsParameter) xo.getChild(CountableRealizationsParameter.class);
	CompoundParameter uniquelyRealizedParameters = (CompoundParameter) xo.getChild(CompoundParameter.class);
	
	int M = xo.getIntegerAttribute(MH_STEPS);
	final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);

	return new DirichletProcessOperator(dpp, // 
			categoriesParameter, //
			uniquelyRealizedParameters, //
			allParameters, //
			likelihood, //
			M, //
			weight //
			);
	
}
 
开发者ID:beast-dev,项目名称:beast-mcmc,代码行数:24,代码来源:DirichletProcessOperatorParser.java


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