本文整理汇总了Java中beast.core.Function.getDimension方法的典型用法代码示例。如果您正苦于以下问题:Java Function.getDimension方法的具体用法?Java Function.getDimension怎么用?Java Function.getDimension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类beast.core.Function
的用法示例。
在下文中一共展示了Function.getDimension方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: 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;
}
示例3: 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;
}
示例4: 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);
}
}
}
示例5: 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;
}
示例6: 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);
}
示例7: recompute
import beast.core.Function; //导入方法依赖的package包/类
/**
* collect values of the compounds into an array *
*/
private void recompute() {
int k = 0;
for (BEASTObject beastObject : m_values.get()) {
Function valuable = (Function) beastObject;
if (beastObject instanceof StateNode) {
valuable = ((StateNode) beastObject).getCurrent();
}
int dimension = valuable.getDimension();
for (int i = 0; i < dimension; i++) {
m_fValues[k++] = valuable.getArrayValue(i);
}
}
m_bRecompute = false;
}
示例8: compute
import beast.core.Function; //导入方法依赖的package包/类
/**
* do the actual work, and reset flag *
*/
void compute() {
sum = 0;
for (Function v : functionInput.get()) {
for (int i = 0; i < v.getDimension(); i++) {
sum += v.getArrayValue(i);
}
}
needsRecompute = false;
}
示例9: log
import beast.core.Function; //导入方法依赖的package包/类
@Override
public void log(int sampleNr, PrintStream out) {
double sum = 0;
for (Function v : functionInput.get()) {
for (int i = 0; i < v.getDimension(); i++) {
sum += v.getArrayValue(i);
}
}
if (mode == Mode.integer_mode) {
out.print((int) sum + "\t");
} else {
out.print(sum + "\t");
}
}
示例10: calcLogP
import beast.core.Function; //导入方法依赖的package包/类
public double calcLogP(Function x) {
if(requiresRecalculation()){
refresh();
}
double[] xVals = new double[x.getDimension()];
for(int i = 0;i < xVals.length;i++){
xVals[i] = x.getArrayValue(i);
}
return logPdf(xVals);
}
示例11: calcLogP
import beast.core.Function; //导入方法依赖的package包/类
public double calcLogP(Function xList) {
if(requiresRecalculation()){
refresh();
}
int dimParam = xList.getDimension();
double logP = 0.0;
for(int i = 0; i < dimParam; i ++){
//System.out.println(getID()+" "+((ParameterList)xList).getParameter(i));
logP+= baseDistribution.calcLogP(((ParameterList)xList).getParameter(i));
}
//System.out.println("flag1: "+logP);
int[] counts = dpValuable.getClusterCounts();
logP+=counts.length*Math.log(alpha.getValue());
//System.err.println("flag2: "+logP+" counts: "+counts.length+" a: "+alpha.getValue());
for(int count: counts){
//System.err.println(count+" "+gammas[count]);
logP+=gammas[count];
}
//System.err.println("flag3: "+logP);
logP-=denominator;
//if(Double.isNaN(logP))
// throw new RuntimeException("wrong!!!");
return logP;
}
示例12: calcLogP
import beast.core.Function; //导入方法依赖的package包/类
@Override
public double calcLogP(Function pX) {
double scaleVal = scale.getValue();
Double [] fAlpha = alpha.getValues();
if(pX.getArrayValue() == 1.0 || pX.getArrayValue()== 0.0){
return Double.NEGATIVE_INFINITY;
}
if(pX.getArrayValue() > 1.0 || pX.getArrayValue() < 0.0){
throw new RuntimeException("Value must be between 0.0 and 1.0: "+pX.getArrayValue());
}
/*if (alpha.getDimension() != pX.getDimension()) {
throw new Exception("Dimensions of alpha and x should be the same, but dim(alpha)=" + alpha.getDimension()
+ " and dim(x)=" + pX.getDimension());
}*/
for(int i = 0; i < fAlpha.length; i++){
fAlpha[i] = fAlpha[i]*scaleVal;
//System.out.println(alpha.getValue(i)+" "+scaleVal);
}
double fLogP = 0;
double fSumAlpha = 0;
for (int i = 0; i < pX.getDimension(); i++) {
double fX = pX.getArrayValue(i);
fLogP += (fAlpha[i]-1) * Math.log(fX);
//System.out.println((fAlpha[i]-1) +" "+ Math.log(fX));
fLogP -= org.apache.commons.math.special.Gamma.logGamma(fAlpha[i]);
fSumAlpha += fAlpha[i];
}
fLogP += org.apache.commons.math.special.Gamma.logGamma(fSumAlpha);
//System.out.println(fLogP);
return fLogP;
}
示例13: calcLogP
import beast.core.Function; //导入方法依赖的package包/类
@Override
public double calcLogP(Function pX) {
double scaleVal = scale.getValue();
Double [] fAlpha = alpha.getValues();
//System.out.println(alpha.getID());
for(int i = 0; i < pX.getDimension(); i++){
if(pX.getArrayValue(i) == 0.0 || pX.getArrayValue(i) == 1.0){
return Double.NEGATIVE_INFINITY;
}
}
if (alpha.getDimension() != pX.getDimension()) {
throw new RuntimeException("Dimensions of alpha and x should be the same, but dim(alpha)=" + alpha.getDimension()
+ " and dim(x)=" + pX.getDimension());
}
for(int i = 0; i < fAlpha.length; i++){
fAlpha[i] = fAlpha[i]*scaleVal;
//System.out.println(alpha.getValue(i)+" "+scaleVal);
}
double fLogP = 0;
double fSumAlpha = 0;
for (int i = 0; i < pX.getDimension(); i++) {
double fX = pX.getArrayValue(i);
fLogP += (fAlpha[i]-1) * Math.log(fX);
//System.out.println((fAlpha[i]-1) +" "+ Math.log(fX));
fLogP -= org.apache.commons.math.special.Gamma.logGamma(fAlpha[i]);
fSumAlpha += fAlpha[i];
}
fLogP += org.apache.commons.math.special.Gamma.logGamma(fSumAlpha);
//System.out.println(fLogP);
return fLogP;
}
示例14: visitVariable
import beast.core.Function; //导入方法依赖的package包/类
@Override
public Double[] visitVariable(ExpressionParser.VariableContext ctx) {
String paramName = ctx.VARNAME().getText();
if (!functionsMap.containsKey(paramName))
throw new IllegalArgumentException("Paramter/Function " + paramName
+ " in expression was not found in list of provided"
+ " parameters/functions.");
Function param = functionsMap.get(paramName);
int paramIdx = -1;
if (ctx.i != null)
paramIdx = Integer.valueOf(ctx.i.getText());
Double [] res;
if (paramIdx<0) {
res = new Double[param.getDimension()];
for (int i=0; i<res.length; i++)
res[i] = param.getArrayValue(i);
} else {
res = new Double[1];
res[0] = param.getArrayValue(paramIdx);
}
return res;
}
示例15: binarySearch
import beast.core.Function; //导入方法依赖的package包/类
/**
* Use binary search to identify interval index corresponding to given time.
*
* @param rateShiftTimeParam function identifying rate shift times
* @param paramTimesBackwards if true, rate shift times are backwards
* @param time time to place
* @return index into corresponding interval
*/
protected int binarySearch(Function rateShiftTimeParam,
boolean paramTimesBackwards, double time) {
int N = rateShiftTimeParam.getDimension()+1;
int imin=0, imax=N-1;
while (imax>imin) {
int imid = imin + (imax-imin)/2;
if (imid==N-1 || getForwardTime(rateShiftTimeParam, imid, paramTimesBackwards)>time) {
if (imid==0 || getForwardTime(rateShiftTimeParam, imid-1, paramTimesBackwards)<=time)
if (paramTimesBackwards)
return N-1 - imin;
else
return imid;
else
imax = imid;
} else {
imin = imid+1;
}
}
if (paramTimesBackwards)
return N-1 - imin;
else
return imin;
}