本文整理汇总了Java中beast.core.parameter.IntegerParameter类的典型用法代码示例。如果您正苦于以下问题:Java IntegerParameter类的具体用法?Java IntegerParameter怎么用?Java IntegerParameter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IntegerParameter类属于beast.core.parameter包,在下文中一共展示了IntegerParameter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCompositionCompoundDataType
import beast.core.parameter.IntegerParameter; //导入依赖的package包/类
public void testCompositionCompoundDataType() throws Exception {
CompoundDataType compound = null;
compound = new CompoundDataType();
DataType d0 = datatype0();
DataType d1 = datatype1();
compound.initByName("components", d0, "components", d1, "ambiguities",
new IntegerParameter(new Integer[] { 0 }));
int counter = 0;
for (int i = 0; i < d0.getStateCount(); ++i) {
for (int j = 0; j < d1.getStateCount(); ++j) {
assertEquals(i, compound.compoundState2componentState(counter, 0));
assertEquals(j, compound.compoundState2componentState(counter, 1));
++counter;
}
}
}
示例2: testCSM
import beast.core.parameter.IntegerParameter; //导入依赖的package包/类
@Test
public void testCSM() throws Exception {
CSMwithPublicMatrix csm = new CSMwithPublicMatrix();
csm.initByName("rates", new RealParameter(rates), "frequencies", freqs, "shape", new IntegerParameter(shape));
final double[][] result = csm.getMatrix();
System.out.printf("%s\n", Arrays.deepToString(result));
System.out.printf("%s\n\n", Arrays.toString(expectedResult));
int i = 0;
for (int k = 0; k < result.length; ++k) {
for (int l = 0; l < result[k].length; ++l) {
assertEquals(expectedResult[i], result[k][l], 1e-10);
++i;
}
}
assertEquals(i, expectedResult.length);
}
示例3: proposal
import beast.core.parameter.IntegerParameter; //导入依赖的package包/类
@Override
public double proposal() {
final IntegerParameter treeRates = treeRatesInput.get();
final Integer[] treeRatesArray = treeRates.getValues();
final int[] cycle = chooseK(nNodes);
final int lastNodeNumber = cycle[discreteK - 1];
int previousRate = treeRatesArray[lastNodeNumber];
for (int i = 0; i < discreteK; i++) {
final int nodeNumber = cycle[i];
treeRates.setValue(nodeNumber, previousRate);
previousRate = treeRatesArray[nodeNumber];
}
return 0.0;
}
示例4: testRates
import beast.core.parameter.IntegerParameter; //导入依赖的package包/类
@Test
public void testRates() throws Exception {
initializeTree();
meanRateParameter = new RealParameter();
stdevParameter = new RealParameter();
branchRatesParameter = new IntegerParameter();
meanRateParameter.initByName("value", String.valueOf(meanRate));
stdevParameter.initByName("value", String.valueOf(1.0));
branchRatesParameter.initByName("value", String.valueOf(initialBranchRate));
// Create dummy state to allow statenode editing
State state = new State();
state.initByName("stateNode", meanRateParameter);
state.initByName("stateNode", branchRatesParameter);
state.initialise();
clockModel = new UncorrelatedRates();
clockModel.initByName("tree", testTree, "rates", branchRatesParameter, "stdev", stdevParameter, "estimateRoot", false, "clock.rate", meanRateParameter);
initializeRates();
checkRates();
}
示例5: initAndValidate
import beast.core.parameter.IntegerParameter; //导入依赖的package包/类
@Override
public void initAndValidate() {
parameter = parameterInput.get();
if (parameter instanceof RealParameter) {
lower = (Double) parameter.getLower();
upper = (Double) parameter.getUpper();
} else if (parameter instanceof IntegerParameter) {
lowerIndex = (Integer) parameter.getLower();
upperIndex = (Integer) parameter.getUpper();
} else {
throw new IllegalArgumentException("parameter should be a RealParameter or IntergerParameter, not " + parameter.getClass().getName());
}
howMany = howManyInput.get();
if (howMany > parameter.getDimension()) {
throw new IllegalArgumentException("howMany it too large: must be less than the dimension of the parameter");
}
}
示例6: proposal
import beast.core.parameter.IntegerParameter; //导入依赖的package包/类
/**
* override this for proposals,
* returns log of hastingRatio, or Double.NEGATIVE_INFINITY if proposal should not be accepted *
*/
@Override
public double proposal() {
final IntegerParameter param = parameterInput.get(this);
final int i = Randomizer.nextInt(param.getDimension());
final int value = param.getValue(i);
final int newValue = value + Randomizer.nextInt(2 * windowSize + 1) - windowSize;
if (newValue < param.getLower() || newValue > param.getUpper()) {
// invalid move, can be rejected immediately
return Double.NEGATIVE_INFINITY;
}
if (newValue == value) {
// this saves calculating the posterior
return Double.NEGATIVE_INFINITY;
}
param.setValue(i, newValue);
return 0.0;
}
示例7: prepare
import beast.core.parameter.IntegerParameter; //导入依赖的package包/类
private void prepare() {
//System.out.println("prepare");
categories = (IntegerParameter) categoryInput.get();
distribution = rateDistInput.get();
tree = treeInput.get();
rates = new double[categories.getDimension()];
try {
for (int i = 0; i < rates.length; i++) {
rates[i] = distribution.inverseCumulativeProbability((i + 0.5) / rates.length);
}
} catch (Exception e) {
// Exception due to distribution not having inverseCumulativeProbability implemented.
// This should already been caught at initAndValidate()
e.printStackTrace();
System.exit(0);
}
//if (normalize) computeFactor();
}
示例8: testMultinomial
import beast.core.parameter.IntegerParameter; //导入依赖的package包/类
public void testMultinomial() throws Exception{
for(Instance test: all){
RealParameter probs = new RealParameter();
IntegerParameter x = new IntegerParameter();
probs.initByName(
"value",test.getProbs(),
"lower","0",
"upper","1");
x.initByName("value", test.getX(),
"lower", "0",
"upper", "100000000");
Multinomial multiNom = new Multinomial();
multiNom.initByName("probs", probs);
double fLogX = multiNom.calcLogP(x);
assertEquals(fLogX, test.getFLogX(), 1e-10);
}
}
示例9: proposal
import beast.core.parameter.IntegerParameter; //导入依赖的package包/类
@Override
public double proposal() {
List<Integer> allIndices = new ArrayList<Integer>(masterList);
int left, right;
do {
if (allIndices.isEmpty()) {
return Double.NEGATIVE_INFINITY;
}
left = allIndices.remove(Randomizer.nextInt(allIndices.size()));
} while (((IntegerParameter)parameter).getValue(left) < 0);
do {
if (allIndices.isEmpty()) {
return Double.NEGATIVE_INFINITY;
}
right = allIndices.remove(Randomizer.nextInt(allIndices.size()));
} while (((IntegerParameter)parameter).getValue(right) < 0);
parameter.swap(left, right);
return 0.0;
}
示例10: main
import beast.core.parameter.IntegerParameter; //导入依赖的package包/类
/**
* Main method for debugging.
*
* @param args
*/
public static void main(String[] args) throws Exception {
RealParameter shiftTimesParam = new RealParameter(new Double[] {5.0});
RealParameter rateParam = new RealParameter(new Double[] {1.0, 0.0});
SISModel model = new SISModel();
model.initByName(
"origin", new RealParameter("10.0"),
"S0", new IntegerParameter("200"),
"infectionRate", new RealParameter("0.01"),
"recoveryRate", new RealParameter("0.1"));
double T = 10.0;
int nSteps = 5;
double dt = T/(nSteps-1);
System.out.println("t\trate");
for (int i=0; i<nSteps; i++) {
double t = i*dt;
System.out.println(t + "\t" + model.getRateAtTime(rateParam, shiftTimesParam, true, t));
}
}
示例11: test6
import beast.core.parameter.IntegerParameter; //导入依赖的package包/类
@Test
public void test6() throws Exception {
SkylinePopulationFunction skyline = new SkylinePopulationFunction();
skyline.initByName(
"acg", acg,
"popSizes", new RealParameter("1.0 1.0 5.0 1.0"),
"groupSizes", new IntegerParameter("0"),
"nGridPoints", 5,
"piecewiseLinear", true);
for (CFEventList.Event cfEvent : acg.getCFEvents()) {
double t = cfEvent.getHeight();
assertTrue(Math.abs(t-skyline.getInverseIntensity(skyline.getIntensity(t)))<1e-14);
}
}
示例12: initAndValidate
import beast.core.parameter.IntegerParameter; //导入依赖的package包/类
@Override
public void initAndValidate() {
try {
maxIndex = parametersInput.get().getDimension();
} catch (NullPointerException e) {
throw new IllegalArgumentException("parameters was left unspecified");
}
if (entryInput.get() == null) {
Integer[] build_entries = new Integer[maxIndex];
for (int i=0; i<maxIndex; ++i) {
build_entries[i] = i;
}
entries = new IntegerParameter(build_entries);
} else {
entries = entryInput.get();
for (Integer entry : entries.getValues()) {
if (entry > groupingsInput.get().getDimension()) {
throw new RuntimeException(
"entries must be valid index of groupings");
}
}
}
// Array-like RealParameters do not implement java.lang.iterable, so we
// must do the iteration by hand.
for (int groupIndex = groupingsInput.get().getDimension() - 1; groupIndex >= 0; --groupIndex) {
if (groupingsInput.get().getNativeValue(groupIndex) >= maxIndex) {
throw new RuntimeException(
"All entries in groupings must be valid indices of parameters");
}
}
// value = parametersInput[groupingsInput[entry]]
}
示例13: testDecompositionCompoundDataType
import beast.core.parameter.IntegerParameter; //导入依赖的package包/类
public void testDecompositionCompoundDataType() {
CompoundDataType compound = null;
compound = new CompoundDataType();
DataType d0 = datatype0();
DataType d1 = datatype1();
compound.initByName("components", d0, "components", d1, "ambiguities",
new IntegerParameter(new Integer[] { 0 }));
int counter = 0;
for (int i = 0; i < d0.getStateCount(); ++i) {
for (int j = 0; j < d1.getStateCount(); ++j) {
assertEquals(counter, compound.componentState2compoundState(new int[] { i, j }));
++counter;
}
}
}
示例14: testGetStateSetIsCompatibleWithIndexOperations
import beast.core.parameter.IntegerParameter; //导入依赖的package包/类
public void testGetStateSetIsCompatibleWithIndexOperations() {
CompoundDataType compound = null;
compound = new CompoundDataType();
DataType d0 = datatype0();
DataType d1 = datatype1();
Integer ambiguities = 1;
compound.initByName("components", d0, "components", d1,
"ambiguities", new IntegerParameter(new Integer[] { ambiguities }));
for (int i = 0; i < d0.getStateCount(); ++i) {
for (int j = 0; j < d1.getStateCount(); ++j) {
int k = compound.componentState2compoundState(new int[] { i, j });
assertEquals(true, compound.getStateSet(k)[k]);
}
}
}
示例15: testUniformity
import beast.core.parameter.IntegerParameter; //导入依赖的package包/类
public void testUniformity() throws Exception {
Double[] m_parameters = new Double[length];
Integer[] m_indices = new Integer[length];
Integer[] m_sizes = new Integer[length];
for (int i = 0; i < length; ++i) {
m_parameters[i] = 1.;
m_indices[i] = i;
m_sizes[i] = 1;
}
StateNode parameters = new RealParameter(m_parameters);
StateNode indices = new IntegerParameter(m_indices);
StateNode sizes = new IntegerParameter(m_sizes);
State state = new State();
state.initByName("stateNode", parameters, "stateNode", indices,
"stateNode", sizes);
RescaledDirichlet rescaledDirichlet = new RescaledDirichlet();
rescaledDirichlet.initByName("sizes", sizes);
Distribution prior = new Prior();
prior.initByName("x", parameters, "distr", rescaledDirichlet);
Operator merger = new MergeOperator();
merger.initByName("parameters", parameters, "groupings", indices,
"sizes", sizes, "weight", 1.);
Operator splitter = new SplitOperator();
splitter.initByName("parameters", parameters, "groupings", indices,
"sizes", sizes, "weight", 1.);
// It would be nice to have a logger that could just write the results
// into a list, so we can easily check the likelihood that this does
// indeed form a uniform prior, and show how to analyse results.
MCMC mcmc = new MCMC();
mcmc.initByName("chainLength", 100000, "preBurnin", 1, "state", state,
"distribution", prior, "operator", merger, "operator", splitter);
mcmc.run();
throw new RuntimeException("The core of this test remains unimplemented");
}