当前位置: 首页>>代码示例>>Java>>正文


Java SourceOfRandomness.nextBoolean方法代码示例

本文整理汇总了Java中com.pholser.junit.quickcheck.random.SourceOfRandomness.nextBoolean方法的典型用法代码示例。如果您正苦于以下问题:Java SourceOfRandomness.nextBoolean方法的具体用法?Java SourceOfRandomness.nextBoolean怎么用?Java SourceOfRandomness.nextBoolean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.pholser.junit.quickcheck.random.SourceOfRandomness的用法示例。


在下文中一共展示了SourceOfRandomness.nextBoolean方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
 
开发者ID:keenon,项目名称:lense,代码行数:18,代码来源:GameTest.java

示例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;
}
 
开发者ID:keenon,项目名称:loglinear,代码行数:17,代码来源:CliqueTreeTest.java

示例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;
}
 
开发者ID:keenon,项目名称:loglinear,代码行数:17,代码来源:LogLikelihoodFunctionTest.java

示例4: generate

import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入方法依赖的package包/类
@Override
public SwitchAction generate(SourceOfRandomness random, GenerationStatus status) {
    final boolean nextState = random.nextBoolean();
    return new SwitchAction() {
        @Override
        public void apply(LightSwitch lightSwitch, LightSwitchModel model) {
            lightSwitch.switchLight(nextState);
            model.hasLight = nextState;
        }

        @Override
        public String toString() {
            return "-> " + nextState;
        }
    };
}
 
开发者ID:ahitrin,项目名称:jq-example,代码行数:17,代码来源:SwitchActionGenerator.java

示例5: generate

import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入方法依赖的package包/类
@Override
public Person generate(final SourceOfRandomness random, final GenerationStatus status)
{
	return new Person(
			random.nextBoolean() ? Gender.Male : Gender.Female,
			random.nextInt(1, 130));
}
 
开发者ID:StefanMacke,项目名称:pbt-junit-quickcheck,代码行数:8,代码来源:PersonGenerator.java

示例6: generate

import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入方法依赖的package包/类
@Override
public TableFactorToMarginalize generate(SourceOfRandomness random, GenerationStatus status) {
  TableFactor tableFactor = tableFactorGenerator.generate(random, status);

  List<Integer> subset = new ArrayList<>();
  for (int i = 0; i < tableFactor.neighborIndices.length; i++) {
    if (random.nextBoolean()) {
      subset.add(tableFactor.neighborIndices[i]);
    }
  }
  if (subset.size() == 0) subset.add(tableFactor.neighborIndices[random.nextInt(tableFactor.neighborIndices.length)]);
  int[] subsetArr = new int[subset.size()];
  for (int i = 0; i < subset.size(); i++) subsetArr[i] = subset.get(i);
  return new TableFactorToMarginalize(tableFactor, subsetArr, subset);
}
 
开发者ID:keenon,项目名称:loglinear,代码行数:16,代码来源:TableFactorTest.java

示例7: generate

import com.pholser.junit.quickcheck.random.SourceOfRandomness; //导入方法依赖的package包/类
@Override
public ConcatVectorNamespace generate(SourceOfRandomness sourceOfRandomness, GenerationStatus generationStatus) {
    ConcatVectorNamespace namespace = new ConcatVectorNamespace();
    namespace.featureToIndex.putAll(generateFeatureMap(sourceOfRandomness));
    for (ObjectCursor<String> key : namespace.featureToIndex.keys()) {
        if (sourceOfRandomness.nextBoolean()) {
            ObjectIntMap<String> sparseMap = generateFeatureMap(sourceOfRandomness);
            IntObjectMap< String> reverseSparseMap = new IntObjectHashMap<>();
            for (ObjectCursor<String> sparseKey : sparseMap.keys()) reverseSparseMap.put(sparseMap.get(sparseKey.value), sparseKey.value);
            namespace.sparseFeatureIndex.put(key.value, sparseMap);
            namespace.reverseSparseFeatureIndex.put(key.value, reverseSparseMap);
        }
    }
    return namespace;
}
 
开发者ID:keenon,项目名称:loglinear,代码行数:16,代码来源:ConcatVectorNamespaceTest.java

示例8: 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;
}
 
开发者ID:keenon,项目名称:loglinear,代码行数:30,代码来源:ConcatVectorTableTest.java

示例9: 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;
}
 
开发者ID:keenon,项目名称:loglinear,代码行数:55,代码来源:GraphicalModelTest.java


注:本文中的com.pholser.junit.quickcheck.random.SourceOfRandomness.nextBoolean方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。