List of usage examples for java.util Random nextGaussian
public synchronized double nextGaussian()
From source file:dataGen.DataGen.java
/** * Creates anti-correlated Test-Data with the specified Seed * The resulting Data is stored in the resources Folder. * @param dimensions/*from w w w . jav a2 s. com*/ * The dimension count of the resulting Data * @param rowCount * How many data tuples should be created? * @param gaussianData * Should we create gaussian distributed Data? * if false: uniform distributed Data will get created. * @param std * standard deviation value * @param center * center of the distribution * @param saveData * should the Data get Saved? * @param seed * the seed for the Random Generations * @throws IOException * If Stream to a File couldn't be written/closed */ public static CustomRealMatrix genAntiCorrData(int dimensions, int rowCount, boolean gaussianData, float std, float center, boolean saveData, long seed) throws IOException { File file = null; // Generate the Export Files if (gaussianData) { logger.info("Generating gaussian anti-correlated Data with " + rowCount + " Tuples in " + dimensions + " dimensions"); if (saveData) file = new File("src/main/resources/anticorr-gaussian-" + rowCount + "-" + dimensions + ".dat"); } else { logger.info("Generating uniform anti-correlated Data with " + rowCount + " Tuples in " + dimensions + "dimensions"); if (saveData) file = new File("src/main/resources/anticorr-normal-" + rowCount + "-" + dimensions + ".dat"); } Random gen = new Random(seed); //PearsonsCorrelation corr = new PearsonsCorrelation(); //RealMatrix corrMatrix = null; // Files should be created OS/Language independent DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(); dfs.setDecimalSeparator('.'); NumberFormat nf = new DecimalFormat("0.000000000", dfs); // Create a good Start-Matrix: a (dimension x dimension) matrix which fulfills the Anti-Correlation Condition CustomRealMatrix values = new CustomRealMatrix(rowCount, dimensions); int validTupleCount = 0; // Create the remaining Tuples while (validTupleCount < rowCount) { boolean minimalEntryFound = false; double entry = 0d; for (int j = 0; j < dimensions; j++) { if (gaussianData) entry = std * gen.nextGaussian() + center; else entry = std * gen.nextDouble() + center; if (!minimalEntryFound && entry < center) minimalEntryFound = true; else if (minimalEntryFound) { while (entry < center) { if (gaussianData) entry = std * gen.nextGaussian() + center; else entry = std * gen.nextDouble() + center; } } values.setEntry(validTupleCount, j, entry); } validTupleCount = validTupleCount + 1; } logger.info(values.getRowDimension() + " entries generated"); if (saveData) { Writer fw = new FileWriter(file); saveData(values, fw, nf); } return values; }
From source file:eu.amidst.core.exponentialfamily.EF_InverseGamma.java
/** * {@inheritDoc}/*from w w w .ja v a2 s . c om*/ */ @Override public EF_UnivariateDistribution randomInitialization(Random random) { double alpha = random.nextGaussian() * 2 + 1; double beta = random.nextDouble() * 1 + 0.1; this.getNaturalParameters().set(0, -alpha - 1); this.getNaturalParameters().set(1, -beta); this.fixNumericalInstability(); this.updateMomentFromNaturalParameters(); return this; }
From source file:org.apache.edgent.samples.utils.sensor.PeriodicRandomSensor.java
/** * Create a periodic sensor stream with readings from {@link Random#nextGaussian()}. * @param t the topology to add the sensor stream to * @param periodMsec how frequently to generate a reading * @return the sensor value stream/*from ww w .j a v a 2 s .c o m*/ */ public TStream<Pair<Long, Double>> newGaussian(Topology t, long periodMsec) { Random r = newRandom(); return t.poll(() -> new Pair<Long, Double>(System.currentTimeMillis(), r.nextGaussian()), periodMsec, TimeUnit.MILLISECONDS); }
From source file:org.powertac.producer.fossil.SteamPlantTest.java
@Test public void dataGenerateOutputGraph() throws IOException { double adjustmentSpeed = 10000; double variance = 2000; double time = (200000 - 500000) / (signum(200000 - 500000) * adjustmentSpeed); Curve output = new Curve(); output.add(0, 500000);/*www . ja v a 2 s . co m*/ output.add(time, 200000); output.add(time + 10, 200000); Random r = new Random(); new File("data/").mkdir(); PrintWriter fw = new PrintWriter("data/dataFossilOutput.txt"); for (int i = 0; i < 60; i++) { fw.printf("%d,%f%n", i, output.value(i - 5) + r.nextGaussian() * variance); } fw.close(); }
From source file:org.powertac.producer.fossil.SteamPlantTest.java
@Test public void dataGenerateOutputGraph2() throws IOException { double adjustmentSpeed = 4500; double variance = 1000; double time = (600000 - 780000) / (signum(600000 - 780000) * adjustmentSpeed); Curve output = new Curve(); output.add(0, 780000);// ww w. j a v a 2s . c om output.add(time / 2, (signum(600000 - 780000) * adjustmentSpeed) * time / 2 + 780000); output.add(time, 600000); Random r = new Random(); new File("data/").mkdir(); PrintWriter fw = new PrintWriter("data/fossil.txt"); for (int i = 0; i <= 80; i++) { fw.printf(Locale.ENGLISH, "%d,%f%n", i, output.value(i - 20) + r.nextGaussian() * variance); } fw.close(); }
From source file:com.facebook.presto.operator.aggregation.AbstractTestApproximateAggregationFunction.java
@Test public void testCorrectnessOnGaussianData() throws Exception { int originalDataSize = 10000; Random distribution = new Random(0); List<Number> list = new ArrayList<>(); for (int i = 0; i < originalDataSize; i++) { list.add(distribution.nextGaussian() * 100); }//from www. ja va 2 s. c o m testCorrectnessOfErrorFunction(list); }
From source file:dev.il.spiderficationsample.DemoMapActivity.java
private void addDemoMarkersAround(GoogleMap map, LatLng center) { MarkerOptions options = new MarkerOptions(); Random r = new Random(); for (int k = 0; k < 20; k++) { map.addMarker(//from ww w . j a v a2 s . c om options.title("Place " + k) .position(new LatLng(center.latitude + r.nextGaussian() * 0.002, center.longitude + r.nextGaussian() * 0.002)) .clusterGroup(ClusterGroup.FIRST_USER)); } }
From source file:ml.shifu.shifu.core.binning.EqualPopulationBinningTest.java
@Test public void tesGussiantBinning() { Random rd = new Random(System.currentTimeMillis()); EqualPopulationBinning binning = new EqualPopulationBinning(10); for (int i = 0; i < 10000; i++) { binning.addData(Double.toString(rd.nextGaussian() % 1000)); }/* w w w .j av a2 s .c om*/ System.out.println(binning.getDataBin()); }
From source file:eu.amidst.core.inference.ImportanceSamplingExperiments.java
private static Assignment randomEvidence(long seed, double evidenceRatio, BayesianNetwork bn, Variable varInterest) throws UnsupportedOperationException { if (evidenceRatio <= 0 || evidenceRatio >= 1) { throw new UnsupportedOperationException("Error: invalid ratio"); }/*from w ww.j a v a2s. c o m*/ int numVariables = bn.getVariables().getNumberOfVars(); Random random = new Random(seed); //1823716125 int numVarEvidence = (int) Math.ceil(numVariables * evidenceRatio); // Evidence on 20% of variables //numVarEvidence = 0; //List<Variable> varEvidence = new ArrayList<>(numVarEvidence); double[] evidence = new double[numVarEvidence]; Variable aux; HashMapAssignment assignment = new HashMapAssignment(2); int[] indexesEvidence = new int[numVarEvidence + 1]; indexesEvidence[0] = varInterest.getVarID(); //if (Main.VERBOSE) System.out.println(variable.getVarID()); if (Main.VERBOSE) System.out.println("Evidence:"); for (int k = 0; k < numVarEvidence; k++) { int varIndex = -1; do { varIndex = random.nextInt(bn.getNumberOfVars()); //if (Main.VERBOSE) System.out.println(varIndex); aux = bn.getVariables().getVariableById(varIndex); double thisEvidence; if (aux.isMultinomial()) { thisEvidence = random.nextInt(aux.getNumberOfStates()); } else { thisEvidence = random.nextGaussian(); } evidence[k] = thisEvidence; } while (ArrayUtils.contains(indexesEvidence, varIndex)); indexesEvidence[k + 1] = varIndex; //if (Main.VERBOSE) System.out.println(Arrays.toString(indexesEvidence)); if (Main.VERBOSE) System.out.println("Variable " + aux.getName() + " = " + evidence[k]); assignment.setValue(aux, evidence[k]); } if (Main.VERBOSE) System.out.println(); return assignment; }
From source file:ml.shifu.shifu.core.binning.EqualPopulationBinningTest.java
@Test public void testObjectSeri() { Random rd = new Random(System.currentTimeMillis()); EqualPopulationBinning binning = new EqualPopulationBinning(10); for (int i = 0; i < 10000; i++) { binning.addData(Double.toString(rd.nextGaussian() % 1000)); }//w w w .j a v a 2 s. c o m String binningStr = binning.objToString(); String originalBinningData = binning.getDataBin().toString(); ModelConfig modelConfig = new ModelConfig(); modelConfig.getStats().setBinningMethod(BinningMethod.EqualPositive); ColumnConfig columnConfig = new ColumnConfig(); columnConfig.setColumnType(ColumnType.N); AbstractBinning<?> otherBinning = AbstractBinning.constructBinningFromStr(modelConfig, columnConfig, binningStr); String newBinningData = otherBinning.getDataBin().toString(); Assert.assertEquals(originalBinningData, newBinningData); }