• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Function类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: calcLogP

import beast.core.Function; //导入依赖的package包/类
@Override
public double calcLogP(Function pX) {
	double fLogP = 0;
	int K = 0;
	int N = 0;
	for (int i = 0; i < pX.getDimension(); i++) {
		int n_i = nInput.get().getNativeValue(i);
		if (n_i > 0) {
			fLogP += Math.log(n_i);
			K += 1;
		}
		N += n_i;
	}
	fLogP += org.apache.commons.math.special.Gamma.logGamma(K);
	fLogP -= K * Math.log(N);
	return fLogP;
}
 
开发者ID:Anaphory,项目名称:correlatedcharacters,代码行数:18,代码来源:RescaledDirichlet.java


示例2: log

import beast.core.Function; //导入依赖的package包/类
@Override
public void log(int nSample, PrintStream out) {
    // make sure we get the current version of the inputs
    SpeciesTreeInterface speciesTree = speciesTreeInput.get();
    SpeciesTreeInterface tree = (SpeciesTreeInterface) speciesTree.getCurrent();
    List<Function> metadata = parameterInput.get();
    for (int i = 0; i < metadata.size(); i++) {
        if (metadata.get(i) instanceof StateNode) {
            metadata.set(i, ((StateNode) metadata.get(i)).getCurrent());
        }
    }
    BranchRateModel branchRateModel = clockModelInput.get();
    PopulationModel populationModel = populationModelInput.get();
    // write out the log tree with meta data
    out.print("tree STATE_" + nSample + " = ");
    tree.getRoot().sort();
    out.print(toNewick(tree.getRoot(), metadata, branchRateModel, populationModel));
    //out.print(tree.getRoot().toShortNewick(false));
    out.print(";");
}
 
开发者ID:genomescale,项目名称:starbeast2,代码行数:21,代码来源:SpeciesTreeLogger.java


示例3: evalFunction

import beast.core.Function; //导入依赖的package包/类
public static double evalFunction(Interpreter interpreter, List<Function> functions, String name, Object... args) {
	NamedFunction.evalFunctionInputs(interpreter, functions);
	try {
		double result = - 1;
		This _this = interpreter.getNameSpace().getThis(interpreter);
		Object o = _this.invokeMethod(name, args);
		if (o instanceof Primitive) {
			o = ((Primitive)o).getValue();
		}
		if (o instanceof Number) {
			result = ((Number) o).doubleValue();
		} else {
			throw new RuntimeException(name + " failed: expected a number as result");
		}
		return result;
	} catch (EvalError e) {
		throw new RuntimeException(name + " failed: " + e.getMessage());
	}

}
 
开发者ID:CompEvol,项目名称:beastshell,代码行数:21,代码来源:NamedFunction.java


示例4: calcLogP

import beast.core.Function; //导入依赖的package包/类
@Override
public double calcLogP(Function pX) {
    Double[] alpha = alphaInput.get().getValues();
    if (alphaInput.get().getDimension() != pX.getDimension()) {
        throw new IllegalArgumentException("Dimensions of alpha and x should be the same, but dim(alpha)=" + alphaInput.get().getDimension()
                + " and dim(x)=" + pX.getDimension());
    }
    double logP = 0;
    double sumAlpha = 0;
    for (int i = 0; i < pX.getDimension(); i++) {
        double x = pX.getArrayValue(i);
        logP += (alpha[i] - 1) * Math.log(x);
        logP -= org.apache.commons.math.special.Gamma.logGamma(alpha[i]);
        sumAlpha += alpha[i];
    }
    logP += org.apache.commons.math.special.Gamma.logGamma(sumAlpha);
    return logP;
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:19,代码来源:Dirichlet.java


示例5: log

import beast.core.Function; //导入依赖的package包/类
@Override
public void log(int sample, PrintStream out) {
    // make sure we get the current version of the inputs
    Tree tree = (Tree) treeInput.get().getCurrent();
    List<Function> metadata = parameterInput.get();
    for (int i = 0; i < metadata.size(); i++) {
    	if (metadata.get(i) instanceof StateNode) {
    		metadata.set(i, ((StateNode) metadata.get(i)).getCurrent());
    	}
    }
    BranchRateModel.Base branchRateModel = clockModelInput.get();
    // write out the log tree with meta data
    out.print("tree STATE_" + sample + " = ");
    tree.getRoot().sort();
    out.print(toNewick(tree.getRoot(), metadata, branchRateModel));
    //out.print(tree.getRoot().toShortNewick(false));
    out.print(";");
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:19,代码来源:TreeWithMetaDataLogger.java


示例6: assertParameterCountInPriorIs

import beast.core.Function; //导入依赖的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);
	}
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:23,代码来源:BeautiBase.java


示例7: calcLogP

import beast.core.Function; //导入依赖的package包/类
@Override
public double calcLogP(Function xVec) {
       

       int xVecDim  = xVec.getDimension();
       double xVecSum = 0;
       double sumLogXElFac =0;
       double sumXLogP = 0;

       for(int i = 0; i < xVecDim; i++){
           double xEl = xVec.getArrayValue(i);
           xVecSum += xEl;
           sumLogXElFac += org.apache.commons.math.special.Gamma.logGamma(xEl+1);
           sumXLogP += xEl*Math.log(probs[i]);

       }
       double logNFac = org.apache.commons.math.special.Gamma.logGamma(xVecSum+1);

       double fLogP = logNFac - sumLogXElFac + sumXLogP;
	return fLogP;
}
 
开发者ID:jessiewu,项目名称:substBMA,代码行数:22,代码来源:Multinomial.java


示例8: calcLogP

import beast.core.Function; //导入依赖的package包/类
public double calcLogP(Function val){
    //System.err.println("logDensity");
    if(!(val instanceof DPPointer)){
        throw new RuntimeException("This distriubtion only applies to DPValuable");
    }
    DPPointer pointers = ((DPPointer)val);
    double logL = 0.0;
    //if(pointers.getLastDirty() == -1){

        for(int i = 0; i < pointers.getDimension();i++){
            if(pointers.getParameterValue(i)<0.5){
                logL+=Math.log(0.2);
            }else{
                logL+=Math.log(0.8);
            }
            //System.err.print(pointers.getParameterValue(i)+" ");
        }
    //System.err.println();
    //System.err.println("logL: "+logL);
        return logL;
    //}




}
 
开发者ID:jessiewu,项目名称:substBMA,代码行数:27,代码来源:ContinuousCategoricalDistribution.java


示例9: initAndValidate

import beast.core.Function; //导入依赖的package包/类
@Override
public void initAndValidate() {
    
    // Assemble name->param map
    Map<String, Function> functionsMap = new HashMap<>();
    for (Function func : functionsInput.get()) {
        BEASTObject obj = (BEASTObject)func;
        functionsMap.put(obj.getID(), func);
    }

    // Build AST from expression string
    ANTLRInputStream input = new ANTLRInputStream(expressionInput.get());
    ExpressionLexer lexer = new ExpressionLexer(input);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    ExpressionParser parser = new ExpressionParser(tokens);
    parseTree = parser.expression();
    
    // Create new visitor for calculating expression values:
    visitor = new ExpCalculatorVisitor(functionsMap);
    
    update();
}
 
开发者ID:tgvaughan,项目名称:feast,代码行数:23,代码来源:ExpCalculator.java


示例10: initAndValidate

import beast.core.Function; //导入依赖的package包/类
@Override
public void initAndValidate() {
    
    // Parameter to house real value
    param = new LightParameter(1.0);
    
    // Assemble name->param map
    Map<String, Function> functionsMap = new HashMap<>();
    functionsMap.put("x", param);

    // Build AST from expression string
    ANTLRInputStream input = new ANTLRInputStream(expressionInput.get());
    ExpressionLexer lexer = new ExpressionLexer(input);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    ExpressionParser parser = new ExpressionParser(tokens);
    parseTree = parser.expression();
    
    // Create new visitor for calculating expression values:
    visitor = new ExpCalculatorVisitor(functionsMap);
    
    if (visitor.visit(parseTree).length != 1)
        throw new IllegalArgumentException("ExpCalculatorDistribution "
                + "expressions must be single-valued.");
}
 
开发者ID:tgvaughan,项目名称:feast,代码行数:25,代码来源:ExpCalculatorParametricDistribution.java


示例11: initAndValidate

import beast.core.Function; //导入依赖的package包/类
@Override
public void initAndValidate() {
    
    // Assemble name->param map
    Map<String, Function> functionsMap = new HashMap<>();
    for (Function func : functionsInput.get()) {
        BEASTObject obj = (BEASTObject)func;
        functionsMap.put(obj.getID(), func);
    }

    // Build AST from expression string
    ANTLRInputStream input = new ANTLRInputStream(expressionInput.get());
    ExpressionLexer lexer = new ExpressionLexer(input);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    ExpressionParser parser = new ExpressionParser(tokens);
    parseTree = parser.expression();
    
    // Create new visitor for calculating expression values:
    visitor = new ExpCalculatorVisitor(functionsMap);
    
    update();
    
    if (res.length != 1)
        throw new IllegalArgumentException("ExpCalculatorDistribution "
                + "expressions must be single-valued.");
}
 
开发者ID:tgvaughan,项目名称:feast,代码行数:27,代码来源:ExpCalculatorDistribution.java


示例12: addRateShiftEvents

import beast.core.Function; //导入依赖的package包/类
public void addRateShiftEvents(Function rateShiftParam,
                               Function rateShiftTimesParam,
                               boolean rateShiftTimesBackward,
                               ModelEvent.RateVariableType rateVariableType) {

    if (rateShiftTimesParam != null) {
        for (int i=0; i<rateShiftTimesParam.getDimension(); i++) {
            ModelEvent event = new ModelEvent();
            event.type = ModelEvent.Type.RATE_CHANGE;
            event.rateVariableType = rateVariableType;
            event.time = getForwardTime(rateShiftTimesParam, i, rateShiftTimesBackward);
            event.newRateVariableValue = getRateInInterval(rateShiftParam, i+1, rateShiftTimesBackward);
            modelEventList.add(event);
        }
    }
}
 
开发者ID:tgvaughan,项目名称:EpiInf,代码行数:17,代码来源:EpidemicModel.java


示例13: log

import beast.core.Function; //导入依赖的package包/类
@Override
    public void log(int nSample, PrintStream out) {
    	states = mascotInput.get().dynamicsInput.get().getDimension();
    	
        // make sure we get the current version of the inputs
//        Tree tree = (Tree) mascotInput.get().treeIntervalsInput.get().treeInput.get().getCurrent();
        //calculate the state of each node
    	calculateNodeStates();
    	
    	used = new boolean[stateProbabilities.length];
    	report = false;
        List<Function> metadata = parameterInput.get();
        for (int i = 0; i < metadata.size(); i++) {
        	if (metadata.get(i) instanceof StateNode) {
        		metadata.set(i, ((StateNode) metadata.get(i)).getCurrent());
        	}
        }
        BranchRateModel.Base branchRateModel = clockModelInput.get();
        // write out the log tree with meta data
        out.print("tree STATE_" + nSample + " = ");
        mascotInput.get().treeIntervalsInput.get().treeInput.get().getRoot().sort();
        root = mascotInput.get().treeIntervalsInput.get().treeInput.get().getRoot();
        out.print(toNewick(root, metadata, branchRateModel));
        out.print(";");
        
        for (int i = 0; i < used.length; i++)
        	if(!used[i])
        		System.err.println("not all nodes used");
        if (report)
        	System.err.println("error in node numbers");
    }
 
开发者ID:nicfel,项目名称:Mascot,代码行数:32,代码来源:StructuredTreeLoggerCollaps.java


示例14: log

import beast.core.Function; //导入依赖的package包/类
@Override
    public void log(int nSample, PrintStream out) {
    	states = mascotInput.get().dynamicsInput.get().getDimension();
    	
        // make sure we get the current version of the inputs
//        Tree tree = (Tree) mascotInput.get().treeIntervalsInput.get().treeInput.get().getCurrent();
        //calculate the state of each node
    	try {
			CalculateNodeStates();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	
    	used = new boolean[stateProbabilities.length];
    	report = false;
        List<Function> metadata = parameterInput.get();
        for (int i = 0; i < metadata.size(); i++) {
        	if (metadata.get(i) instanceof StateNode) {
        		metadata.set(i, ((StateNode) metadata.get(i)).getCurrent());
        	}
        }
        BranchRateModel.Base branchRateModel = clockModelInput.get();
        // write out the log tree with meta data
        out.print("tree STATE_" + nSample + " = ");
        mascotInput.get().treeIntervalsInput.get().treeInput.get().getRoot().sort();
        root = mascotInput.get().treeIntervalsInput.get().treeInput.get().getRoot();
        out.print(toNewick(root, metadata, branchRateModel));
        out.print(";");
        
        for (int i = 0; i < used.length; i++)
        	if(!used[i])
        		System.err.println("not all nodes used");
        if (report)
        	System.err.println("error in node numbers");
    }
 
开发者ID:nicfel,项目名称:Mascot,代码行数:37,代码来源:StructuredTreeLogger.java


示例15: evalFunctionInputs

import beast.core.Function; //导入依赖的package包/类
public static void evalFunctionInputs(Interpreter interpreter, List<Function> functions) {
	try {
		for (Function function : functions) {
			String id = ((BEASTObject) function).getID();
			if (function instanceof NamedFunction) {
				id = ((NamedFunction)function).getName();
				interpreter.set(id, ((NamedFunction)function).getFunction());
			} else {
				interpreter.set(id, function);
			}
		}
	} catch (EvalError e) {
		throw new RuntimeException("Error in BSHOperator: " + e.getMessage());
	}
}
 
开发者ID:CompEvol,项目名称:beastshell,代码行数:16,代码来源:NamedFunction.java


示例16: evalVoidFunction

import beast.core.Function; //导入依赖的package包/类
public static void evalVoidFunction(Interpreter interpreter, List<Function> functions, String name, Object... args) {
	NamedFunction.evalFunctionInputs(interpreter, functions);
	try {
		This _this = interpreter.getNameSpace().getThis(interpreter);
		_this.invokeMethod(name, args);
	} catch (EvalError e) {
		throw new RuntimeException(name + " failed: " + e.getMessage());
	}

}
 
开发者ID:CompEvol,项目名称:beastshell,代码行数:11,代码来源:NamedFunction.java


示例17: calcLogP

import beast.core.Function; //导入依赖的package包/类
/**
 * Calculate log probability of a valuable x for this distribution.
 * If x is multidimensional, the components of x are assumed to be independent,
 * so the sum of log probabilities of all elements of x is returned as the prior.
 */
public double calcLogP(final Function fun) {
    final double offset = offsetInput.get();
    double logP = 0;
    for (int i = 0; i < fun.getDimension(); i++) {
        final double x = fun.getArrayValue(i);
        logP += logDensity(x, offset);
    }
    return logP;
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:15,代码来源:ParametricDistribution.java


示例18: log

import beast.core.Function; //导入依赖的package包/类
@Override
public void log(final int sample, final PrintStream out) {
    // make sure we get the current version of the inputs
    final Tree tree = (Tree) treeInput.get().getCurrent();
    Function metadata = parameterInput.get();
    if (metadata instanceof StateNode) {
        metadata = ((StateNode) metadata).getCurrent();
    }
    Function metadataTop = parameterTopInput.get();
    if (metadataTop != null && metadataTop instanceof StateNode) {
        metadataTop = ((StateNode) metadataTop).getCurrent();
    }

    List<Function> metadataList = metadataInput.get();
    for (int i = 0; i < metadataList.size(); i++) {
    	if (metadataList.get(i) instanceof StateNode) {
    		metadataList.set(i, ((StateNode) metadataList.get(i)).getCurrent());
    	}
    }

    // write out the log tree with meta data
    out.print("tree STATE_" + sample + " = ");
    tree.getRoot().sort();
    out.print(toNewick(tree.getRoot(), metadata, metadataTop, metadataList));
    //out.print(tree.getRoot().toShortNewick(false));
    out.print(";");
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:28,代码来源:SpeciesTreeLogger.java


示例19: getMetaDataTopValue

import beast.core.Function; //导入依赖的package包/类
double getMetaDataTopValue(final Node node, final Function metadataTop) {
    int nr = node.getNr();
    if (nr >= metadataTop.getDimension()) {
        nr = node.getTree().getRoot().getNr();
    }
    return metadataTop.getArrayValue(nr);
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:8,代码来源:SpeciesTreeLogger.java


示例20: initAndValidate

import beast.core.Function; //导入依赖的package包/类
@Override
public void initAndValidate() {
    // determine dimension
    int dimension = 0;
    for (BEASTObject beastObject : m_values.get()) {
        if (!(beastObject instanceof Function)) {
            throw new IllegalArgumentException("Input does not implement Valuable");
        }
        dimension += ((Function) beastObject).getDimension();
    }
    m_fValues = new double[dimension];
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:13,代码来源:CompoundValuable.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CollinsHeadFinder类代码示例发布时间:2022-05-22
下一篇:
Java TObjectDoubleProcedure类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap