Example usage for org.apache.commons.math3.random HaltonSequenceGenerator HaltonSequenceGenerator

List of usage examples for org.apache.commons.math3.random HaltonSequenceGenerator HaltonSequenceGenerator

Introduction

In this page you can find the example usage for org.apache.commons.math3.random HaltonSequenceGenerator HaltonSequenceGenerator.

Prototype

public HaltonSequenceGenerator(final int dimension) throws OutOfRangeException 

Source Link

Document

Construct a new Halton sequence generator for the given space dimension.

Usage

From source file:gdsc.smlm.model.UniformDistribution.java

private void init(double[] min, double[] max, RandomVectorGenerator randomVectorGenerator) {
    if (min == null)
        min = new double[0];
    if (max == null)
        max = new double[0];

    this.min = new double[3];
    for (int i = 0; i < min.length; i++)
        this.min[i] = min[i];
    this.max = new double[3];
    for (int i = 0; i < max.length; i++) {
        if (max[i] < this.min[i])
            throw new IllegalArgumentException(
                    String.format("Max %f must be greater than min %f", max[i], this.min[i]));
        this.max[i] = max[i];
    }/*ww w  .ja v a 2 s .c  o  m*/

    this.range = new double[3];
    for (int i = 0; i < this.max.length; i++)
        this.range[i] = this.max[i] - this.min[i];

    if (randomVectorGenerator == null)
        randomVectorGenerator = new HaltonSequenceGenerator(3);
    this.vectorGenerator = randomVectorGenerator;
}

From source file:com.vmware.photon.controller.cloudstore.xenon.entity.SchedulingConstantGenerator.java

private void nextValue(State state) {
    if (state == null) {
        throw new RuntimeException("state == null");
    }// w ww . j a  v  a2 s . c  om
    if (state.nextHaltonSequenceIndex == null) {
        throw new RuntimeException("state.nextHaltonSequenceIndex == null");
    }

    HaltonSequenceGenerator hsg = new HaltonSequenceGenerator(1);
    if (hsg == null) {
        throw new RuntimeException("hsg == null");
    }
    double[] nextValues = hsg.skipTo(state.nextHaltonSequenceIndex);

    state.nextHaltonSequenceIndex++;
    state.lastSchedulingConstant = (long) (nextValues[0] * HostService.MAX_SCHEDULING_CONSTANT);
}

From source file:gdsc.smlm.ij.plugins.DensityImage.java

/**
 * Compute the Ripley's L-function for user selected radii and show it on a plot.
 * // w ww.j  a v a 2 s .  c om
 * @param results
 */
private void computeRipleysPlot(MemoryPeakResults results) {
    GenericDialog gd = new GenericDialog(TITLE);
    gd.addMessage("Compute Ripley's L(r) - r plot");
    gd.addNumericField("Min_radius", minR, 2);
    gd.addNumericField("Max_radius", maxR, 2);
    gd.addNumericField("Increment", incrementR, 2);
    gd.addCheckbox("Confidence_intervals", confidenceIntervals);

    gd.showDialog();
    if (gd.wasCanceled())
        return;
    minR = gd.getNextNumber();
    maxR = gd.getNextNumber();
    incrementR = gd.getNextNumber();
    confidenceIntervals = gd.getNextBoolean();

    if (minR > maxR || incrementR < 0 || gd.invalidNumber()) {
        IJ.error(TITLE, "Invalid radius parameters");
        return;
    }

    DensityManager dm = new DensityManager(results);
    double[][] values = calculateLScores(dm);

    // 99% confidence intervals
    final int iterations = (confidenceIntervals) ? 99 : 0;
    double[] upper = null;
    double[] lower = null;
    Rectangle bounds = results.getBounds();
    // Use a uniform distribution for the coordinates
    HaltonSequenceGenerator dist = new HaltonSequenceGenerator(2);
    dist.skipTo(new Well19937c(System.currentTimeMillis() + System.identityHashCode(this)).nextInt());
    for (int i = 0; i < iterations; i++) {
        IJ.showProgress(i, iterations);
        IJ.showStatus(String.format("L-score confidence interval %d / %d", i + 1, iterations));

        // Randomise coordinates
        float[] x = new float[results.size()];
        float[] y = new float[x.length];
        for (int j = x.length; j-- > 0;) {
            final double[] d = dist.nextVector();
            x[j] = (float) (d[0] * bounds.width);
            y[j] = (float) (d[1] * bounds.height);
        }
        double[][] values2 = calculateLScores(new DensityManager(x, y, bounds));
        if (upper == null) {
            upper = values2[1];
            lower = new double[upper.length];
            System.arraycopy(upper, 0, lower, 0, upper.length);
        } else {
            for (int m = upper.length; m-- > 0;) {
                if (upper[m] < values2[1][m])
                    upper[m] = values2[1][m];
                if (lower[m] > values2[1][m])
                    lower[m] = values2[1][m];
            }
        }
    }

    String title = results.getName() + " Ripley's (L(r) - r) / r";
    Plot2 plot = new Plot2(title, "Radius", "(L(r) - r) / r", values[0], values[1]);
    // Get the limits
    double yMin = min(0, values[1]);
    double yMax = max(0, values[1]);
    if (iterations > 0) {
        yMin = min(yMin, lower);
        yMax = max(yMax, upper);
    }
    plot.setLimits(0, values[0][values[0].length - 1], yMin, yMax);
    if (iterations > 0) {
        plot.setColor(Color.BLUE);
        plot.addPoints(values[0], upper, 1);
        plot.setColor(Color.RED);
        plot.addPoints(values[0], lower, 1);
        plot.setColor(Color.BLACK);
    }
    Utils.display(title, plot);
}

From source file:yaphyre.core.samplers.HaltonSampler.java

private void setupSampler(int numberOfSamples) {
    RandomVectorGenerator vectorGenerator = new HaltonSequenceGenerator(2);
    unitSquareSamples = Lists.newArrayListWithCapacity(numberOfSamples);
    for (int i = 0; i < numberOfSamples; i++) {
        unitSquareSamples.add(Point2D.of(vectorGenerator.nextVector()));
    }//from  w  w w.j ava 2 s.  co m
    unitSquareSamples = Collections.unmodifiableList(unitSquareSamples);
}