本文整理汇总了Java中com.pholser.junit.quickcheck.random.SourceOfRandomness.nextDouble方法的典型用法代码示例。如果您正苦于以下问题:Java SourceOfRandomness.nextDouble方法的具体用法?Java SourceOfRandomness.nextDouble怎么用?Java SourceOfRandomness.nextDouble使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.pholser.junit.quickcheck.random.SourceOfRandomness
的用法示例。
在下文中一共展示了SourceOfRandomness.nextDouble方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generate
import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入方法依赖的package包/类
@Override
public ConcatVector generate(SourceOfRandomness sourceOfRandomness, GenerationStatus generationStatus) {
ConcatVector v = new ConcatVector(CONCAT_VEC_COMPONENTS);
for (int x = 0; x < CONCAT_VEC_COMPONENTS; x++) {
if (sourceOfRandomness.nextBoolean()) {
v.setSparseComponent(x, sourceOfRandomness.nextInt(CONCAT_VEC_COMPONENT_LENGTH), sourceOfRandomness.nextDouble());
}
else {
double[] val = new double[sourceOfRandomness.nextInt(CONCAT_VEC_COMPONENT_LENGTH)];
for (int y = 0; y < val.length; y++) {
val[y] = sourceOfRandomness.nextDouble();
}
v.setDenseComponent(x, val);
}
}
return v;
}
示例2: generate
import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入方法依赖的package包/类
@Override
public ConcatVector generate(SourceOfRandomness sourceOfRandomness, GenerationStatus generationStatus) {
ConcatVector v = new ConcatVector(CONCAT_VEC_COMPONENTS);
for (int x = 0; x < CONCAT_VEC_COMPONENTS; x++) {
if (sourceOfRandomness.nextBoolean()) {
v.setSparseComponent(x, sourceOfRandomness.nextInt(CONCAT_VEC_COMPONENT_LENGTH), sourceOfRandomness.nextDouble());
} else {
double[] val = new double[sourceOfRandomness.nextInt(CONCAT_VEC_COMPONENT_LENGTH)];
for (int y = 0; y < val.length; y++) {
val[y] = 2.0 * (sourceOfRandomness.nextDouble() - 0.5);
}
v.setDenseComponent(x, val);
}
}
return v;
}
示例3: generate
import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入方法依赖的package包/类
@Override
public ConcatVector generate(SourceOfRandomness sourceOfRandomness, GenerationStatus generationStatus) {
ConcatVector v = new ConcatVector(CONCAT_VEC_COMPONENTS);
for (int x = 0; x < CONCAT_VEC_COMPONENTS; x++) {
if (sourceOfRandomness.nextBoolean()) {
v.setSparseComponent(x, sourceOfRandomness.nextInt(CONCAT_VEC_COMPONENT_LENGTH), sourceOfRandomness.nextDouble());
} else {
double[] val = new double[sourceOfRandomness.nextInt(CONCAT_VEC_COMPONENT_LENGTH)];
for (int y = 0; y < val.length; y++) {
val[y] = sourceOfRandomness.nextDouble();
}
v.setDenseComponent(x, val);
}
}
return v;
}
示例4: recursivelyFillArray
import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入方法依赖的package包/类
private static void recursivelyFillArray(List<Integer> assignmentSoFar, NDDoubleArrayWithGold testPair, SourceOfRandomness sourceOfRandomness) {
if (assignmentSoFar.size() == testPair.array.getDimensions().length) {
int[] arr = new int[assignmentSoFar.size()];
for (int i = 0; i < arr.length; i++) {
arr[i] = assignmentSoFar.get(i);
}
double value = sourceOfRandomness.nextDouble();
testPair.array.setAssignmentValue(arr, value);
testPair.gold.put(arr, value);
} else {
for (int i = 0; i < testPair.array.getDimensions()[assignmentSoFar.size()]; i++) {
List<Integer> newList = new ArrayList<>();
newList.addAll(assignmentSoFar);
newList.add(i);
recursivelyFillArray(newList, testPair, sourceOfRandomness);
}
}
}
示例5: recursivelyFillArray
import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入方法依赖的package包/类
private static void recursivelyFillArray(List<Integer> assignmentSoFar, NDArrayWithGold<Double> testPair, SourceOfRandomness sourceOfRandomness) {
if (assignmentSoFar.size() == testPair.array.getDimensions().length) {
int[] arr = new int[assignmentSoFar.size()];
for (int i = 0; i < arr.length; i++) {
arr[i] = assignmentSoFar.get(i);
}
double value = sourceOfRandomness.nextDouble();
testPair.array.setAssignmentValue(arr, value);
testPair.gold.put(arr, value);
}
else {
for (int i = 0; i < testPair.array.getDimensions()[assignmentSoFar.size()]; i++) {
List<Integer> newList = new ArrayList<>();
newList.addAll(assignmentSoFar);
newList.add(i);
recursivelyFillArray(newList, testPair, sourceOfRandomness);
}
}
}
示例6: generate
import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入方法依赖的package包/类
@Override
public TableFactor generate(SourceOfRandomness sourceOfRandomness, GenerationStatus generationStatus) {
int numNeighbors = sourceOfRandomness.nextInt(1, 3);
int[] neighbors = new int[numNeighbors];
int[] dimensions = new int[numNeighbors];
Set<Integer> usedNeighbors = new HashSet<>();
for (int i = 0; i < neighbors.length; i++) {
while (true) {
int neighbor = sourceOfRandomness.nextInt(0, 3);
if (!usedNeighbors.contains(neighbor)) {
usedNeighbors.add(neighbor);
neighbors[i] = neighbor;
dimensions[i] = variableSizes[neighbor];
break;
}
}
}
// Make sure we get some all-0 factor tables
double multiple = sourceOfRandomness.nextDouble();
TableFactor factor = new TableFactor(neighbors, dimensions);
for (int[] assignment : factor) {
factor.setAssignmentValue(assignment, multiple * sourceOfRandomness.nextDouble());
}
return factor;
}
示例7: generate
import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入方法依赖的package包/类
@Override
public ConcatVector[][][] generate(SourceOfRandomness sourceOfRandomness, GenerationStatus generationStatus) {
int l = sourceOfRandomness.nextInt(10) + 1;
int m = sourceOfRandomness.nextInt(10) + 1;
int n = sourceOfRandomness.nextInt(10) + 1;
ConcatVector[][][] factor3 = new ConcatVector[l][m][n];
for (int i = 0; i < factor3.length; i++) {
for (int j = 0; j < factor3[0].length; j++) {
for (int k = 0; k < factor3[0][0].length; k++) {
int numComponents = sourceOfRandomness.nextInt(7);
ConcatVector v = new ConcatVector(numComponents);
for (int x = 0; x < numComponents; x++) {
if (sourceOfRandomness.nextBoolean()) {
v.setSparseComponent(x, sourceOfRandomness.nextInt(32), sourceOfRandomness.nextDouble());
}
else {
double[] val = new double[sourceOfRandomness.nextInt(12)];
for (int y = 0; y < val.length; y++) {
val[y] = sourceOfRandomness.nextDouble();
}
v.setDenseComponent(x, val);
}
}
factor3[i][j][k] = v;
}
}
}
return factor3;
}
示例8: generate
import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入方法依赖的package包/类
public Page generate(SourceOfRandomness random, GenerationStatus status,
int left, int top, int right, int bottom) {
int elemCount = (int) Math.cbrt(status.size()) + 1;
double[] relativeOffsets = new double[elemCount + 1];
double currentOffset = random.nextDouble(0.1, 1);
for (int i = 0; i < relativeOffsets.length; i++) {
relativeOffsets[i] = currentOffset;
currentOffset += random.nextDouble(0.1, 1);
}
for (int i = 0; i < relativeOffsets.length; i++) {
relativeOffsets[i] /= currentOffset;
}
int[] absoluteOffsets = new int[relativeOffsets.length];
for (int i = 0; i < relativeOffsets.length; i++) {
absoluteOffsets[i] = (int) (relativeOffsets[i] * (bottom - top) + top);
}
ArrayList<Paragraph> elems = new ArrayList<Paragraph>(elemCount);
for (int i = 0; i < elemCount; i++) {
int newRight = (int) (random.nextDouble(0.5, 1.0) * (right - left) + left);
Paragraph p = paragraphGenerator.generate(random, status,
left, absoluteOffsets[i],
newRight, absoluteOffsets[i + 1]);
elems.add(p);
}
return new Page(1, Collections.singletonList(new Area(elems)));
}
示例9: generate
import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入方法依赖的package包/类
public Line generate(SourceOfRandomness random, GenerationStatus status,
int left, int top, int right, int bottom) {
int elemCount = status.size();
double[] relativeOffsets = new double[elemCount + 1];
double currentOffset = random.nextDouble(0.1, 1);
for (int i = 0; i < relativeOffsets.length; i++) {
relativeOffsets[i] = currentOffset;
currentOffset += random.nextDouble(0.1, 1);
}
for (int i = 0; i < relativeOffsets.length; i++) {
relativeOffsets[i] /= currentOffset;
}
int[] absoluteOffsets = new int[relativeOffsets.length];
for (int i = 0; i < relativeOffsets.length; i++) {
absoluteOffsets[i] = (int) (relativeOffsets[i] * (right - left) + left);
}
ArrayList<Word> elems = new ArrayList<Word>(elemCount);
for (int i = 0; i < elemCount; i++) {
Bounds b = boundsGenerator.generate(random, status,
absoluteOffsets[i], top,
absoluteOffsets[i + 1], bottom);
String w = stringGenerator.generate(random, status);
elems.add(new Word(w, b));
}
return new Line(elems);
}
示例10: generate
import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入方法依赖的package包/类
public Paragraph generate(SourceOfRandomness random, GenerationStatus status,
int left, int top, int right, int bottom) {
int elemCount = (int) Math.sqrt(status.size()) + 1;
double[] relativeOffsets = new double[elemCount + 1];
double currentOffset = random.nextDouble(0.1, 1);
for (int i = 0; i < relativeOffsets.length; i++) {
relativeOffsets[i] = currentOffset;
currentOffset += random.nextDouble(0.1, 1);
}
for (int i = 0; i < relativeOffsets.length; i++) {
relativeOffsets[i] /= currentOffset;
}
int[] absoluteOffsets = new int[relativeOffsets.length];
for (int i = 0; i < relativeOffsets.length; i++) {
absoluteOffsets[i] = (int) (relativeOffsets[i] * (bottom - top) + top);
}
ArrayList<Line> elems = new ArrayList<Line>(elemCount);
for (int i = 0; i < elemCount; i++) {
int newRight = (int) (random.nextDouble(0.5, 1.0) * (right - left) + left);
Line l = lineGenerator.generate(random, status,
left, absoluteOffsets[i],
newRight, absoluteOffsets[i + 1]);
elems.add(l);
}
return new Paragraph(elems);
}
示例11: gen
import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入方法依赖的package包/类
static SparseList<Integer> gen(
SourceOfRandomness random,
GenerationStatus status) {
if(random.nextDouble() < 0.2) {
return new SparseList<>();
} else {
SparseList<Integer> list = gen(random, status);
SparseListModification.gen(random, list.size()).apply(list);
return list;
}
}
示例12: generate
import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入方法依赖的package包/类
@Override
public GraphicalModel generate(SourceOfRandomness sourceOfRandomness, GenerationStatus generationStatus) {
GraphicalModel model = new GraphicalModel();
// Create the variables and factors
int[] variableSizes = new int[20];
for (int i = 0; i < 20; i++) {
variableSizes[i] = sourceOfRandomness.nextInt(1, 5);
}
int numFactors = sourceOfRandomness.nextInt(12);
for (int i = 0; i < numFactors; i++) {
int[] neighbors = new int[sourceOfRandomness.nextInt(1, 3)];
int[] neighborSizes = new int[neighbors.length];
for (int j = 0; j < neighbors.length; j++) {
neighbors[j] = sourceOfRandomness.nextInt(20);
neighborSizes[j] = variableSizes[neighbors[j]];
}
ConcatVectorTable table = new ConcatVectorTable(neighborSizes);
for (int[] assignment : table) {
int numComponents = sourceOfRandomness.nextInt(7);
// Generate a vector
ConcatVector v = new ConcatVector(numComponents);
for (int x = 0; x < numComponents; x++) {
if (sourceOfRandomness.nextBoolean()) {
v.setSparseComponent(x, sourceOfRandomness.nextInt(32), sourceOfRandomness.nextDouble());
} else {
double[] val = new double[sourceOfRandomness.nextInt(12)];
for (int y = 0; y < val.length; y++) {
val[y] = sourceOfRandomness.nextDouble();
}
v.setDenseComponent(x, val);
}
}
// set vec in table
table.setAssignmentValue(assignment, () -> v);
}
model.addFactor(table, neighbors);
}
// Add metadata to the variables, factors, and model
generateMetaData(sourceOfRandomness, model.getModelMetaDataByReference());
for (int i = 0; i < 20; i++) {
generateMetaData(sourceOfRandomness, model.getVariableMetaDataByReference(i));
}
for (GraphicalModel.Factor factor : model.factors) {
generateMetaData(sourceOfRandomness, factor.getMetaDataByReference());
}
return model;
}
示例13: generate
import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入方法依赖的package包/类
@Override
public DenseTestVector generate(SourceOfRandomness sourceOfRandomness, GenerationStatus generationStatus) {
int length = sourceOfRandomness.nextInt(10);
double[][] trueValues = new double[length][];
ConcatVector mv = new ConcatVector(length);
for (int i = 0; i < length; i++) {
int type = sourceOfRandomness.nextInt(0,2);
if (type == 0) {
trueValues[i] = new double[SPARSE_VECTOR_LENGTH];
int sparseIndex = sourceOfRandomness.nextInt(SPARSE_VECTOR_LENGTH);
double sparseValue = sourceOfRandomness.nextDouble();
trueValues[i][sparseIndex] = sparseValue;
mv.setSparseComponent(i, sparseIndex, sparseValue);
}
else if (type == 1) {
int numElems = sourceOfRandomness.nextInt(0,3);
trueValues[i] = new double[SPARSE_VECTOR_LENGTH];
int[] sparseIndices = new int[numElems];
double[] sparseValues = new double[numElems];
for (int j = 0; j < numElems; j++) {
sparseValues[j] = sourceOfRandomness.nextDouble();
outer: while (true) {
sparseIndices[j] = sourceOfRandomness.nextInt(SPARSE_VECTOR_LENGTH);
for (int k = 0; k < j; k++) {
if (sparseIndices[j] == sparseIndices[k]) continue outer;
}
trueValues[i][sparseIndices[j]] = sparseValues[j];
break;
}
}
mv.setSparseComponent(i, sparseIndices, sparseValues);
}
else {
trueValues[i] = new double[sourceOfRandomness.nextInt(10)];
// Ensure we have some null components in our generated vector
if (trueValues[i].length > 0) {
for (int j = 0; j < trueValues[i].length; j++) {
trueValues[i][j] = sourceOfRandomness.nextDouble();
}
mv.setDenseComponent(i, trueValues[i]);
}
}
}
return new DenseTestVector(trueValues, mv);
}