コード例 #1
0
 /**
  * Causes all known instances of {@link RandomGenerator}, and future ones, to be started from a
  * fixed seed. This is useful for making tests deterministic.
  */
 public static void useTestSeed() {
   useTestSeed = true;
   synchronized (INSTANCES) {
     for (RandomGenerator random : INSTANCES.keySet()) {
       random.setSeed(TEST_SEED);
     }
     INSTANCES.clear();
   }
 }
コード例 #2
0
  public GaussianDistribution(final int dims, final double[] pos, final double size) {
    final Random random = Util.R.get();
    this.dims = dims;
    final double[] means = new double[dims];
    for (int i = 0; i < means.length; i++) {
      means[i] = 1;
    }
    final double[][] diaganals = new double[dims][];
    for (int i = 0; i < diaganals.length; i++) {
      diaganals[i] = new double[dims];
      diaganals[i][i] = 1;
    }
    final RandomGenerator rng = new JDKRandomGenerator();
    rng.setSeed(random.nextInt());

    this.pos = pos;
    this.size = size;
  }
コード例 #3
0
  /** Test points that are very close together. See issue MATH-546. */
  @Test
  public void testSmallDistances() {
    // Create a bunch of CloseDoublePoints. Most are identical, but one is different by a
    // small distance.
    int[] repeatedArray = {0};
    int[] uniqueArray = {1};
    DoublePoint repeatedPoint = new DoublePoint(repeatedArray);
    DoublePoint uniquePoint = new DoublePoint(uniqueArray);

    Collection<DoublePoint> points = new ArrayList<DoublePoint>();
    final int NUM_REPEATED_POINTS = 10 * 1000;
    for (int i = 0; i < NUM_REPEATED_POINTS; ++i) {
      points.add(repeatedPoint);
    }
    points.add(uniquePoint);

    // Ask a KMeansPlusPlusClusterer to run zero iterations (i.e., to simply choose initial
    // cluster centers).
    final long RANDOM_SEED = 0;
    final int NUM_CLUSTERS = 2;
    final int NUM_ITERATIONS = 0;
    random.setSeed(RANDOM_SEED);

    KMeansPlusPlusClusterer<DoublePoint> clusterer =
        new KMeansPlusPlusClusterer<DoublePoint>(
            NUM_CLUSTERS, NUM_ITERATIONS, new CloseDistance(), random);
    List<CentroidCluster<DoublePoint>> clusters = clusterer.cluster(points);

    // Check that one of the chosen centers is the unique point.
    boolean uniquePointIsCenter = false;
    for (CentroidCluster<DoublePoint> cluster : clusters) {
      if (cluster.getCenter().equals(uniquePoint)) {
        uniquePointIsCenter = true;
      }
    }
    Assert.assertTrue(uniquePointIsCenter);
  }
コード例 #4
0
 @Before
 public void setUp() {
   random = new JDKRandomGenerator();
   random.setSeed(1746432956321l);
 }