本文整理汇总了Java中beast.core.parameter.RealParameter.setValue方法的典型用法代码示例。如果您正苦于以下问题:Java RealParameter.setValue方法的具体用法?Java RealParameter.setValue怎么用?Java RealParameter.setValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类beast.core.parameter.RealParameter
的用法示例。
在下文中一共展示了RealParameter.setValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initPopSizes
import beast.core.parameter.RealParameter; //导入方法依赖的package包/类
@Override
public void initPopSizes(double tipInitial) {
final double topInitial = tipInitial * 0.5;
final RealParameter tipPopSizes = tipPopSizesInput.get();
final RealParameter topPopSizes = topPopSizesInput.get();
final double tipLower = tipPopSizes.getLower();
final double tipUpper = tipPopSizes.getUpper();
final double topLower = topPopSizes.getLower();
final double topUpper = topPopSizes.getUpper();
if (tipPopSizes.isEstimatedInput.get() && tipInitial > tipLower && tipInitial < tipUpper) {
for (int i = 0; i < tipPopSizes.getDimension(); i++)
tipPopSizes.setValue(i, tipInitial);
}
if (topPopSizes.isEstimatedInput.get() && topInitial > topLower && topInitial < topUpper) {
for (int i = 0; i < topPopSizes.getDimension(); i++)
topPopSizes.setValue(i, topInitial);
}
}
示例2: proposal
import beast.core.parameter.RealParameter; //导入方法依赖的package包/类
@Override
public double proposal() {
final RealParameter parameter = parameterInput.get();
final Double[] parameterArray = parameter.getValues();
final int[] cycle = chooseK(nNodes);
final int lastNodeNumber = cycle[discreteK - 1];
double previousRate = parameterArray[lastNodeNumber];
for (int i = 0; i < discreteK; i++) {
final int nodeNumber = cycle[i];
parameter.setValue(nodeNumber, previousRate);
previousRate = parameterArray[nodeNumber];
}
return 0.0;
}
示例3: proposal
import beast.core.parameter.RealParameter; //导入方法依赖的package包/类
/**
* override this for proposals,
* returns log of hastingRatio, or Double.NEGATIVE_INFINITY if proposal should not be accepted *
*/
@Override
public double proposal() {
RealParameter param = parameterInput.get(this);
int i = Randomizer.nextInt(param.getDimension());
double value = param.getValue(i);
double newValue = getProposedVal(
value, //original value
i, //index of the value
useGaussian, //whether to use gaussian moves
windowSizes); //window sizes
if (newValue < param.getLower() || newValue > param.getUpper()) {
return Double.NEGATIVE_INFINITY;
}
if (newValue == value) {
// this saves calculating the posterior
return Double.NEGATIVE_INFINITY;
}
param.setValue(i, newValue);
lastChangedValueIndex = i;
return 0.0;
}
示例4: proposal
import beast.core.parameter.RealParameter; //导入方法依赖的package包/类
public double proposal() {
RealParameter param = parameterInput.get(this);
double value = param.getValue(index);
double newValue = value;
if (useGaussian) {
newValue += Randomizer.nextGaussian() * windowSize;
} else {
newValue += Randomizer.nextDouble() * 2 * windowSize - windowSize;
}
if (newValue < param.getLower() || newValue > param.getUpper()) {
return Double.NEGATIVE_INFINITY;
}
if (newValue == value) {
// this saves calculating the posterior
return Double.NEGATIVE_INFINITY;
}
param.setValue(index, newValue);
return 0.0;
}
示例5: proposal
import beast.core.parameter.RealParameter; //导入方法依赖的package包/类
@Override
public double proposal() {
Tree tree = treeInput.get();
final RealParameter rParameter = rInput.get(this);
double r = rParameter.getValue();
if (r != 1 && ((ZeroBranchSATree)tree).getDirectAncestorNodeCount() == 0) {
rParameter.setValue(1.);
return 0.0;
} else if (r == 1) {
rParameter.setValue(Randomizer.nextDouble());
return 0.0;
} else return Double.NEGATIVE_INFINITY;
}
示例6: proposal
import beast.core.parameter.RealParameter; //导入方法依赖的package包/类
/**
* override this for proposals,
* returns log of hastingRatio, or Double.NEGATIVE_INFINITY if proposal should not be accepted *
*/
@Override
public double proposal() {
RealParameter param = parameterInput.get(this);
for (int i = 0; i < param.getDimension(); i++){
double value = param.getValue(i);
double newValue = value;
double windowSize = 0.0;
if (indicatorInput.get().getArrayValue(i) > 0.5)
windowSize = windowSizeOn;
else
windowSize = windowSizeOff;
if (useGaussian) {
newValue += Randomizer.nextGaussian() * windowSize;
} else {
newValue += Randomizer.nextDouble() * 2 * windowSize - windowSize;
}
if (newValue < param.getLower() || newValue > param.getUpper()) {
return Double.NEGATIVE_INFINITY;
}
if (newValue == value) {
// this saves calculating the posterior
return Double.NEGATIVE_INFINITY;
}
param.setValue(i, newValue);
}
return 0.0;
}
示例7: proposal
import beast.core.parameter.RealParameter; //导入方法依赖的package包/类
@Override
public double proposal() {
final RealParameter treeRates = treeRatesInput.get();
final double[] treeRatesArray = treeRates.getDoubleValues();
final int[] network = chooseK(nNodes);
// exchange a new delta between all pairs of nodes in 'network'
for (int i = 0; i < (discreteK - 1); i++) {
for (int j = i + 1; j < discreteK; j++) {
final double delta = (Randomizer.nextDouble() - 0.5) * deltaScaleFactor;
treeRatesArray[network[i]] += delta;
treeRatesArray[network[j]] -= delta;
}
}
for (int i = 0; i < discreteK; i++) {
final int nodeNumber = network[i];
final double newRate = treeRatesArray[nodeNumber];
if (newRate < lowerBound || newRate > upperBound) {
return Double.NEGATIVE_INFINITY;
} else {
treeRates.setValue(nodeNumber, newRate);
}
}
return 0.0;
}
示例8: initPopSizes
import beast.core.parameter.RealParameter; //导入方法依赖的package包/类
@Override
public void initPopSizes(double popInitial) {
final RealParameter popSizes = popSizesInput.get();
final double lower = popSizes.getLower();
final double upper = popSizes.getUpper();
if (popSizes.isEstimatedInput.get() && popInitial > lower && popInitial < upper) {
for (int i = 0; i < popSizes.getDimension(); i++) {
popSizes.setValue(i, popInitial);
}
}
}
示例9: proposal
import beast.core.parameter.RealParameter; //导入方法依赖的package包/类
/**
* override this for proposals,
* returns log of hastingRatio, or Double.NEGATIVE_INFINITY if proposal should not be accepted *
*/
@Override
public double proposal() {
RealParameter param = parameterInput.get(this);
int i = Randomizer.nextInt(param.getDimension());
double value = param.getValue(i);
double newValue = value;
if (useGaussian) {
newValue += Randomizer.nextGaussian() * windowSize;
} else {
newValue += Randomizer.nextDouble() * 2 * windowSize - windowSize;
}
if (newValue < param.getLower() || newValue > param.getUpper()) {
return Double.NEGATIVE_INFINITY;
}
if (newValue == value) {
// this saves calculating the posterior
return Double.NEGATIVE_INFINITY;
}
param.setValue(i, newValue);
return 0.0;
}
示例10: setParameterValue
import beast.core.parameter.RealParameter; //导入方法依赖的package包/类
private void setParameterValue(RealParameter p, int index, double value) {
if (value < p.getLower()) {
value = p.getLower();
}
if (value > p.getUpper()) {
value = p.getUpper();
}
p.setValue(index, value);
}
示例11: proposal
import beast.core.parameter.RealParameter; //导入方法依赖的package包/类
public double proposal(){
Double[] newCounts = new Double[dirichletPriorCounts.getDimension()];
for(int i = 0; i < newCounts.length; i++){
newCounts[i] = dirichletPriorCounts.getValue();
}
int sampleSize = x.getDimension();
for(int i = 0; i < sampleSize; i++){
newCounts[(int)(double)(x.getParameter(i).getValue()-offset)]++;
}
try{
DirichletDistribution dirichlet = new DirichletDistribution(newCounts);
Double[][] draw = dirichlet.sample(1);
RealParameter probs = categoricalProbsInput.get(this);
for(int i = 0 ; i < draw[0].length; i++){
probs.setValue(i,draw[0][i]);
}
}catch(Exception e){
throw new RuntimeException(e);
}
return Double.POSITIVE_INFINITY;
}
示例12: proposal
import beast.core.parameter.RealParameter; //导入方法依赖的package包/类
public double proposal(){
RealParameter parameter = parameterInput.get(this);
int currVertex = (int)(double)parameter.getValue() - offset;
int nextVertex = neighbours[currVertex][Randomizer.nextInt(neighbours[currVertex].length)];
//System.out.println("currVertex: "+currVertex+ ", nextVertex: "+nextVertex);
parameter.setValue(0,(double)nextVertex+offset);
//System.out.println("currVal: "+this.parameter.get());
//System.out.println(logHastingsRatios[currVertex][nextVertex]);
return logHastingsRatios[currVertex][nextVertex];
}
示例13: evaluate
import beast.core.parameter.RealParameter; //导入方法依赖的package包/类
Double evaluate(Evaluator E, RealParameter X, double x) {
X.setValue(0, x);
return evaluate(E);
}
示例14: proposal
import beast.core.parameter.RealParameter; //导入方法依赖的package包/类
/**
* override this for proposals,
* returns log of hastingRatio, or Double.NEGATIVE_INFINITY if proposal should not be accepted *
*/
@Override
public double proposal(Evaluator E) {
int m = 100;
RealParameter X = parameterInput.get();
// Find the density at the current point
Double gx0 = evaluate(E);
// System.err.println("gx0 = " + gx0);
// Get the 1st element
Double x0 = X.getValue(0);
// System.err.println("x0 = " + x0);
// Determine the slice level, in log terms.
double logy = gx0 - Randomizer.nextExponential(1);
// Find the initial interval to sample from.
Double[] range = find_slice_boundaries_stepping_out(E, X, logy, windowSize, m);
Double L = range[0];
Double R = range[1];
// Sample from the interval, shrinking it on each rejection
double x_new = search_interval(E, x0, X, L, R, logy);
X.setValue(x_new);
if (n_learning_iterations > 0) {
n_learning_iterations--;
totalDelta += Math.abs(x_new - x0);
totalNumber++;
double W_predicted = totalDelta / totalNumber * 4.0;
if (totalNumber > 3) {
W = 0.95 * W + 0.05 * W_predicted;
windowSize = W;
}
// System.err.println("W = " + W);
}
return Double.POSITIVE_INFINITY;
}
示例15: proposal
import beast.core.parameter.RealParameter; //导入方法依赖的package包/类
/**
* override this for proposals,
*
* @return log of Hastings Ratio, or Double.NEGATIVE_INFINITY if proposal
* should not be accepted
**/
@Override
public final double proposal() {
double r = Randomizer.nextDouble();
final double scale = (m_fScaleFactor + (r * ((1.0 / m_fScaleFactor) - m_fScaleFactor)));
final double scaleLog = (m_fScaleFactor + r*-2*m_fScaleFactor);
int goingUp = 0, goingDown = 0;
try {
List<StateNode> upList = m_up.get();
for (int i = 0; i < upList.size(); i++) {
StateNode up = upList.get(i).getCurrentEditable(this);
if(isExpUp[i]){
if(up instanceof RealParameter){
RealParameter upParameter = (RealParameter)up;
int upParameterDim = upParameter.getDimension();
for(int j = 0; j < upParameterDim; j++){
double upVal = upParameter.getValue(j);
upParameter.setValue(Math.log(Math.exp(upVal)*scale));
}
}else{
throw new RuntimeException("If isExp is true, then the state node must be a real parameter.");
}
}else{
goingUp += up.scale(scale);
}
}
List<StateNode> downList = m_down.get();
for (int i = 0; i < downList.size(); i++) {
StateNode down = downList.get(i).getCurrentEditable(this);
if(isExpDown[i]){
if(down instanceof RealParameter){
RealParameter downParameter = (RealParameter)down;
int downParameterDim = downParameter.getDimension();
for(int j = 0; j < downParameterDim; j++){
double downVal = downParameter.getValue(j);
downParameter.setValue(Math.log(Math.exp(downVal)*scale));
}
}else{
throw new RuntimeException("If isExp is true, then the state node must be a real parameter.");
}
}else{
goingDown += down.scale(1.0 / scale);
}
}
} catch (Exception e) {
// scale resulted in invalid StateNode, abort proposal
return Double.NEGATIVE_INFINITY;
}
//System.out.println(goingUp - goingDown );
return (goingUp - goingDown - 2) * Math.log(scale);
//return -2 * Math.log(scale);
}