List of usage examples for org.apache.commons.math3.random EmpiricalDistribution EmpiricalDistribution
private EmpiricalDistribution(int binCount, RandomDataGenerator randomData)
From source file:cz.cuni.mff.d3s.spl.utils.DistributionUtils.java
/** Create empirical distribution from given samples. * //from w w w . j av a 2s. c o m * @param samples Samples (does not need to be distinct) to use. * @return Empirical distribution built from the samples. */ public static EmpiricalDistribution makeEmpirical(double[] samples) { /* Be deterministic for now. */ RandomGenerator gen = new JDKRandomGenerator(); gen.setSeed(0); EmpiricalDistribution result = new EmpiricalDistribution(samples.length / 10 + 1, gen); result.load(samples); return result; }
From source file:gdsc.smlm.ij.plugins.CreateData.java
/** * @return A photon distribution loaded from a file of floating-point values with the specified population mean. *//* www .j ava2 s. co m*/ private RealDistribution createPhotonDistribution() { if (settings.customPhotonDistribution) { // Get the distribution file String[] path = Utils.decodePath(settings.photonDistribution); OpenDialog chooser = new OpenDialog("Photon_distribution", path[0], path[1]); if (chooser.getFileName() != null) { String newFilename = chooser.getDirectory() + chooser.getFileName(); settings.photonDistribution = newFilename; try { InputStream is = new FileInputStream(new File(settings.photonDistribution)); BufferedReader in = new BufferedReader(new UnicodeReader(is, null)); StoredDataStatistics stats = new StoredDataStatistics(); try { String str = null; double val = 0.0d; while ((str = in.readLine()) != null) { val = Double.parseDouble(str); stats.add(val); } } finally { in.close(); } if (stats.getSum() > 0) { // Update the statistics to the desired mean. double scale = (double) settings.photonsPerSecond / stats.getMean(); double[] values = stats.getValues(); for (int i = 0; i < values.length; i++) values[i] *= scale; // TODO - Investigate the limits of this distribution. // How far above and below the input data will values be generated. // Create the distribution using the recommended number of bins final int binCount = stats.getN() / 10; EmpiricalDistribution dist = new EmpiricalDistribution(binCount, createRandomGenerator()); dist.load(values); return dist; } } catch (IOException e) { // Ignore } catch (NullArgumentException e) { // Ignore } catch (NumberFormatException e) { // Ignore } } } // Fall back to a non-custom distribution settings.customPhotonDistribution = false; return null; }