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

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

Introduction

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

Prototype

public double[] skipTo(final int index) throws NotPositiveException 

Source Link

Document

Skip to the i-th point in the Halton sequence.

Usage

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

/**
 * Create a new uniform distribution using a Halton sequence
 * // ww w. j  a v a  2s  . c o m
 * @param min
 *            The minimum bounds for the distribution
 * @param max
 *            The maximum bounds for the distribution
 * @param seed
 *            Start at the i-th point in the Halton sequence
 */
public UniformDistribution(double[] min, double[] max, int seed) {
    //HaltonSequenceGenerator randomVectorGenerator = new HaltonSequenceGenerator(3);
    // The Halton sequence based on the prime of 2 does not provide great variety in the
    // lesser significant digits when simulating a 512x512 pixel image. This is not suitable for
    // PSF fitting since we require variation to at least 3 decimal places.
    HaltonSequenceGenerator randomVectorGenerator = new HaltonSequenceGenerator(3, new int[] { 3, 5, 7 }, null);
    randomVectorGenerator.skipTo(Math.abs(seed));
    init(min, max, 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  a  2 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.
 * /*  ww w .  j a  va2  s  .  c  o m*/
 * @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);
}