本文整理汇总了Java中beast.core.Function.getArrayValue方法的典型用法代码示例。如果您正苦于以下问题:Java Function.getArrayValue方法的具体用法?Java Function.getArrayValue怎么用?Java Function.getArrayValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类beast.core.Function
的用法示例。
在下文中一共展示了Function.getArrayValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: 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);
}
示例5: 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;
}
示例6: 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;
}
示例7: 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");
}
}
示例8: 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);
}
示例9: 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;
}
示例10: 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;
}
示例11: calcLogP
import beast.core.Function; //导入方法依赖的package包/类
public double calcLogP(Function val){
//System.err.println("Hello?");
if(val.getArrayValue() > 0.0 && val.getArrayValue()<0.5){
return Math.log(1.0);
}else if (val.getArrayValue()>0.5 && val.getArrayValue()<1.0){
return Math.log(1.0);
}else{
return Double.NEGATIVE_INFINITY;
}
}
示例12: 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;
}
示例13: getRateAtTime
import beast.core.Function; //导入方法依赖的package包/类
/**
* Retrieve rate at given time.
*
* @param rateParam parameter defining rate
* @param rateShiftTimeParam parameter defining rate change times
* @param paramTimesBackwards if true, rate shift times are backwards
* @param time time at which to evaluate rate.
*
* @return rate effective at given time
*/
protected double getRateAtTime(Function rateParam, Function rateShiftTimeParam,
boolean paramTimesBackwards, double time) {
if (rateParam != null) {
if (rateShiftTimeParam != null) {
return rateParam.getArrayValue(
binarySearch(rateShiftTimeParam, paramTimesBackwards, time));
} else
return rateParam.getArrayValue();
} else
return 0.0;
}
示例14: depends
import beast.core.Function; //导入方法依赖的package包/类
public boolean depends(int component, int dependsOn) {
// Check whether the evolution rates of `component` depend on the state
// of `dependsOn`.
// TODO: Currently, this gives the more generic result (“is dependent
// on”) when `frequencies` are not all equal, but compatible with
// independent evolution, and the base rates make up for the difference
// in actual rates introduced by fixing frequencies.
double[] fFreqs = frequencies.getFreqs();
double freq0 = fFreqs[0];
for (double freq : fFreqs) {
if (freq != freq0) {
return true;
}
}
Function rates = ratesInput.get();
int componentMax = 0;
int componentMin = 0;
int dependsOnStep = nrOfStates;
for (int c = 0; c <= component || c <= dependsOn; ++c) {
if (c <= component) {
componentMin = componentMax;
componentMax += shape[c] - 1;
}
if (c <= dependsOn) {
dependsOnStep /= shape[c];
}
}
boolean[] checked = new boolean[nrOfStates];
for (int from = 0; from < nrOfStates; ++from) {
if (!checked[from]) {
checked[from] = true;
for (int componentTo = componentMin; componentTo < componentMax; ++componentTo) {
double thisRate = rates.getArrayValue(from * nonzeroTransitions + componentTo);
for (int other = 1; other < shape[dependsOn]; ++other) {
int otherIndex = from + dependsOnStep * other;
checked[otherIndex] = true;
// System.out.printf("> %d ?= %d\n", from, otherIndex);
double otherRate = rates.getArrayValue(otherIndex * nonzeroTransitions + componentTo);
if (thisRate != otherRate) {
// System.out.printf(" No: %f vs. %f\n", thisRate,
// otherRate);
return true;
}
}
}
}
}
return false;
}
示例15: setupRelativeRates
import beast.core.Function; //导入方法依赖的package包/类
protected void setupRelativeRates() {
Function rates = this.ratesInput.get();
for (int i = 0; i < rates.getDimension(); i++) {
relativeRates[i] = rates.getArrayValue(i);
}
}