List of usage examples for java.util Random nextGaussian
public synchronized double nextGaussian()
From source file:TestHTTPSource.java
public void doTestHttps(String protocol) throws Exception { Type listType = new TypeToken<List<JSONEvent>>() { }.getType();/*w ww . j a v a2 s . c om*/ List<JSONEvent> events = Lists.newArrayList(); Random rand = new Random(); for (int i = 0; i < 10; i++) { Map<String, String> input = Maps.newHashMap(); for (int j = 0; j < 10; j++) { input.put(String.valueOf(i) + String.valueOf(j), String.valueOf(i)); } input.put("MsgNum", String.valueOf(i)); JSONEvent e = new JSONEvent(); e.setHeaders(input); e.setBody(String.valueOf(rand.nextGaussian()).getBytes("UTF-8")); events.add(e); } Gson gson = new Gson(); String json = gson.toJson(events, listType); HttpsURLConnection httpsURLConnection = null; try { TrustManager[] trustAllCerts = { new X509TrustManager() { @Override public void checkClientTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) throws CertificateException { // noop } @Override public void checkServerTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) throws CertificateException { // noop } public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } } }; SSLContext sc = null; javax.net.ssl.SSLSocketFactory factory = null; if (System.getProperty("java.vendor").contains("IBM")) { sc = SSLContext.getInstance("SSL_TLS"); } else { sc = SSLContext.getInstance("SSL"); } HostnameVerifier hv = new HostnameVerifier() { public boolean verify(String arg0, SSLSession arg1) { return true; } }; sc.init(null, trustAllCerts, new SecureRandom()); if (protocol != null) { factory = new DisabledProtocolsSocketFactory(sc.getSocketFactory(), protocol); } else { factory = sc.getSocketFactory(); } HttpsURLConnection.setDefaultSSLSocketFactory(factory); HttpsURLConnection.setDefaultHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); URL sslUrl = new URL("https://0.0.0.0:" + sslPort); httpsURLConnection = (HttpsURLConnection) sslUrl.openConnection(); httpsURLConnection.setDoInput(true); httpsURLConnection.setDoOutput(true); httpsURLConnection.setRequestMethod("POST"); httpsURLConnection.getOutputStream().write(json.getBytes()); int statusCode = httpsURLConnection.getResponseCode(); Assert.assertEquals(200, statusCode); Transaction transaction = channel.getTransaction(); transaction.begin(); for (int i = 0; i < 10; i++) { Event e = channel.take(); Assert.assertNotNull(e); Assert.assertEquals(String.valueOf(i), e.getHeaders().get("MsgNum")); } transaction.commit(); transaction.close(); } finally { httpsURLConnection.disconnect(); } }
From source file:org.opensha.sha.gcim.calc.GcimCalculator.java
/** * this function obtains realizations of the IMi values from the GCIM distributions. * The primary purpose of this method is to output random realizations of the IMi values * which can then be used to select ground motion records for seismic response analysis * Returns true if it was successfully else return false * *@param numGcimRealizations: the number of random realizations of the IMi vector to compute * @param imri: selected IMRi object (that for which the distribution is desired i.e. IMi) * @param imCorrelationRelationship: selected correlation object for IMi and IMj * @param maxDist: maxDist of sources to consider * @param magDistFilter: Magnitude-Distance filter for sources * @return boolean/* ww w .j a v a2 s .c o m*/ */ public boolean getGcimRealizations(int numGcimRealizations, int numIMi, ArrayList<? extends Map<TectonicRegionType, ScalarIMR>> imiAttenRels, ArrayList<String> imiTypes, ArrayList<? extends Map<TectonicRegionType, ImCorrelationRelationship>> imijCorrRels, ArrayList<? extends Map<TectonicRegionType, ImCorrelationRelationship>> imikCorrRels, double maxDist, ArbitrarilyDiscretizedFunc magDistFilter) { this.numGcimRealizations = numGcimRealizations; randIMiRealizations = new double[numIMi][numGcimRealizations]; randIMiRealizationStdevs = new double[numIMi][numGcimRealizations]; //Now loop over the number of different realizations desired for (int m = 0; m < numGcimRealizations; m++) { //Get a random earthquake source and rupture boolean randSourceRupUpdated = getRandomSourceRupture(); ProbEqkSource source = eqkRupForecast.getSource(randSourceId); ProbEqkRupture rupture = source.getRupture(randRupId); //For the given rupture obtain the conditional mean and variance of all of the IMis double[] mulnIMi_RandRupIMj = new double[numIMi]; double[] stdlnIMi_RandRupIMj = new double[numIMi]; double[] rho_lnIMilnIMj = new double[numIMi]; double[][] rho_lnIMilnIMk_lnIMj = new double[numIMi][numIMi]; double[] mulnIMi_RandRup = new double[numIMi]; double[] stdlnIMi_RandRup = new double[numIMi]; for (int i = 0; i < numIMi; i++) { //Get the IMi, AttenRel, CorrRel, (and period later if IMi is SA) Map<TectonicRegionType, ScalarIMR> imriMap = imiAttenRels.get(i); Map<TectonicRegionType, ImCorrelationRelationship> corrImijMap = imijCorrRels.get(i); //Set the site in imri for (ScalarIMR imri : imriMap.values()) { imri.resetParameterEventListeners(); imri.setUserMaxDistance(maxDist); imri.setSite(site); } // set the IMR according to the tectonic region of the source (if there is more than one) TectonicRegionType trt = source.getTectonicRegionType(); ScalarIMR imri = TRTUtils.getIMRforTRT(imriMap, trt); ImCorrelationRelationship imijCorrRel = Utils.getIMCorrRelForTRT(corrImijMap, trt); //compute the correlation coefficient between lnIMi and lnIMj for the given source rho_lnIMilnIMj[i] = imijCorrRel.getImCorrelation(); // set the rupture in the imr imri.setEqkRupture(rupture); // get the unconditional mean, stdDev of lnIMi for the given rupture mulnIMi_RandRup[i] = imri.getMean(); stdlnIMi_RandRup[i] = imri.getStdDev(); // get the conditional mean, stdDev of lnIMi for the given rupture mulnIMi_RandRupIMj[i] = mulnIMi_RandRup[i] + stdlnIMi_RandRup[i] * rho_lnIMilnIMj[i] * epsilonIMj[randSourceId][randRupId]; stdlnIMi_RandRupIMj[i] = stdlnIMi_RandRup[i] * Math.sqrt(1 - Math.pow(rho_lnIMilnIMj[i], 2.0)); //Now setup the covariance matrix between the different IMi's rho_lnIMilnIMk_lnIMj[i][i] = 1.0; for (int k = 0; k < i; k++) { //Determine the (unconditional) correlation between lnIMi and lnIMk int corrImikIndex = (i) * (i - 1) / 2 + k; Map<TectonicRegionType, ImCorrelationRelationship> corrImikMap = imikCorrRels .get(corrImikIndex); //Get the correlation relation associated with the TRT ImCorrelationRelationship imikCorrRel = Utils.getIMCorrRelForTRT(corrImikMap, trt); //compute the correlation coefficient between lnIMi and lnIMk for the given source double rho_lnIMilnIMk = imikCorrRel.getImCorrelation(); //Now get the conditional correlation rho_lnIMilnIMk_lnIMj[i][k] = (rho_lnIMilnIMk - rho_lnIMilnIMj[i] * rho_lnIMilnIMj[k]) / Math .sqrt((1.0 - Math.pow(rho_lnIMilnIMj[i], 2)) * (1.0 - Math.pow(rho_lnIMilnIMj[k], 2))); //Then as conditional correlation matrix is symmetric rho_lnIMilnIMk_lnIMj[k][i] = rho_lnIMilnIMk_lnIMj[i][k]; } } //determine the cholesky decomposition of the correlation matrix Matrix rho_lnIMilnIMk_lnIMj_matrix = new Matrix(rho_lnIMilnIMk_lnIMj); CholeskyDecomposition cholDecomp = new CholeskyDecomposition(rho_lnIMilnIMk_lnIMj_matrix); // CholeskyDecomposition cholDecomp = rho_lnIMilnIMk_lnIMj_matrix.chol(); //This JAMA .chol doesnt work well //Check if the matrix is PD then get L Matrix L_matrix; if (cholDecomp.isSPD()) { L_matrix = cholDecomp.getL(); } else { corrMatrixPD = false; corrMatrixNotPDString = getMatrixAsString(rho_lnIMilnIMk_lnIMj_matrix); if (D) { System.out.println("The corr matrix below is not PD"); rho_lnIMilnIMk_lnIMj_matrix.print(10, 4); } //First compute the nearest PD matrix NearPD nearPd = new NearPD(); nearPd.setKeepDiag(true); // nearPd.setEigTol(1.e-6); boolean success = nearPd.calcNearPD(rho_lnIMilnIMk_lnIMj_matrix); normFrob = nearPd.getFrobNorm(); if (!success) { throw new RuntimeException("Error: nearPD failed to converge, the correlation matrix maybe" + " significantly different from a PD matrix, check that the correlation equations" + "used are reasonable"); } Matrix rho_lnIMilnIMk_lnIMj_PDmatrix = nearPd.getX(); corrMatrixPDString = getMatrixAsString(rho_lnIMilnIMk_lnIMj_PDmatrix); if (D) { System.out.println("This is the nearest PD matrix to corr matrix"); rho_lnIMilnIMk_lnIMj_PDmatrix.print(10, 6); } //Now get the CholDecomp of this nearest matrix CholeskyDecomposition cholDecompPD = new CholeskyDecomposition(rho_lnIMilnIMk_lnIMj_PDmatrix); // CholeskyDecomposition cholDecompPD = rho_lnIMilnIMk_lnIMj_PDmatrix.chol(); //THis JAMA one doesnt work if (cholDecompPD.isSPD()) { L_matrix = cholDecompPD.getL(); } else { throw new RuntimeException("Error: Even after NearPD the matrix is not PD"); } } // L = cholesky(rho_lnIMilnIMk_lnIMj); //compute an uncorrelated array of standard normal random variables // Random generator = new Random(); // double[] randArray = new double[numIMi]; // for (int i=0; i<numIMi; i++) { // randArray[i] = generator.nextGaussian(); // } Random generator = new Random(); double[][] randArray = new double[numIMi][1]; for (int i = 0; i < numIMi; i++) { randArray[i][0] = generator.nextGaussian(); } Matrix randArray_matrix = new Matrix(randArray); //multiply by the cholesky decomposition to get correlation random variables Matrix corrRandArray_matrix = L_matrix.times(randArray_matrix); // double[] corrRandArray = matrixVectorMultiplication(L, randArray); //Compute the random realization of IMi for (int i = 0; i < numIMi; i++) { randIMiRealizations[i][m] = Math .exp(mulnIMi_RandRupIMj[i] + stdlnIMi_RandRupIMj[i] * corrRandArray_matrix.get(i, 0)); // randIMiRealizations[i][m]=Math.exp(mulnIMi_RandRupIMj[i]+stdlnIMi_RandRupIMj[i]*corrRandArray[i]); randIMiRealizationStdevs[i][m] = stdlnIMi_RandRupIMj[i]; } } gcimRealizationsComplete = true; return gcimRealizationsComplete; }
From source file:de.cebitec.readXplorer.differentialExpression.plot.ExpressTestGraphicsTopComponent.java
public Map<PersistentFeature, Pair<Double, Double>> createSamplePoints(int n) { Random r = new Random(System.nanoTime()); Map<PersistentFeature, Pair<Double, Double>> points = new HashMap<>(); for (int i = 0; i < n; i++) { PersistentFeature dummyFeature = new PersistentFeature(0, 0, "", "", "", "", 0, 0, true, FeatureType.ANY, ""); double random = Math.random(); if (random > 0.95) { points.put(dummyFeature, new Pair<>(r.nextDouble() * 256.0d, Double.POSITIVE_INFINITY)); points.put(dummyFeature, new Pair<>(r.nextDouble() * 256.0d, Double.NEGATIVE_INFINITY)); } else {/* w ww .j a v a2 s . c o m*/ points.put(dummyFeature, new Pair<>(2 * i + (r.nextGaussian() - 0.5d), r.nextDouble() * 256.0d)); } } PersistentFeature dummyFeature = new PersistentFeature(0, 0, "", "", "", "", 0, 0, true, FeatureType.ANY, ""); points.put(dummyFeature, new Pair<>(200d, 300d)); dummyFeature = new PersistentFeature(0, 0, "", "", "", "", 0, 0, true, FeatureType.ANY, ""); points.put(dummyFeature, new Pair<>(100d, Double.POSITIVE_INFINITY)); return points; }
From source file:edu.cornell.med.icb.goby.stats.TestStatistics.java
@Test public void testTwoStats() { final Random randomEngine = new Random(37); final DifferentialExpressionCalculator deCalc = new DifferentialExpressionCalculator() { @Override/*from www. j a v a 2s .c o m*/ public double getNormalizedExpressionValue(final String sample, final NormalizationMethod method, final MutableString elementId) { if (sample.startsWith("A")) { return 2 * Math.abs(randomEngine.nextGaussian()); } else { return Math.abs(randomEngine.nextGaussian()); } // fold change A/B = 2 } @Override public int getOverlapCount(final String sample, final MutableString elementId) { final NormalizationMethod normalizationMethod = new AlignedCountNormalization(); return (int) (getNormalizedExpressionValue(sample, normalizationMethod, elementId) * 100); } }; deCalc.defineElement("id-1"); deCalc.defineElement("id-2"); deCalc.defineGroup("A"); deCalc.defineGroup("B"); final int numReplicates = 2000; deCalc.reserve(2, numReplicates * 2); for (int i = 0; i < numReplicates; i++) { deCalc.associateSampleToGroup("A-" + i, "A"); deCalc.associateSampleToGroup("B-" + i, "B"); } // observe the counts to populate internal data structures: for (final String sampleId : deCalc.samples()) { final MutableString id1 = new MutableString("id-1"); final MutableString id2 = new MutableString("id-2"); deCalc.observe(sampleId, "id-1", deCalc.getOverlapCount(sampleId, id1)); deCalc.observe(sampleId, "id-2", deCalc.getOverlapCount(sampleId, id2)); } //deCalc.associateSampleToGroup("A-", "A"); //deCalc.associateSampleToGroup("B-1", "B"); final DifferentialExpressionInfo info = new DifferentialExpressionInfo("id-1"); final DifferentialExpressionResults results = new DifferentialExpressionResults(); final FoldChangeCalculator foldChange = new FoldChangeCalculator(results); final TTestCalculator tTest = new TTestCalculator(results); final FisherExactTestCalculator fisher = new FisherExactTestCalculator(results); final NormalizationMethod normalizationMethod = new AlignedCountNormalization(); foldChange.evaluate(deCalc, normalizationMethod, results, info, "A", "B"); tTest.evaluate(deCalc, normalizationMethod, results, info, "A", "B"); fisher.evaluate(deCalc, normalizationMethod, results, info, "A", "B"); assertEquals("fold-change does not match", 2d, results.getStatistic(info, foldChange.statisticIds.get(0)), .1); assertTrue("T-test must be significant", results.getStatistic(info, tTest.statisticIds.get(0)) < 0.01); assertTrue("fisher test must not be significant", results.getStatistic(info, fisher.statisticIds.get(0)) > 0.05); }
From source file:edu.cornell.med.icb.goby.stats.TestStatistics.java
public void testParalellLarge() { final Random randomEngine = new Random(); final DifferentialExpressionCalculator deCalc = new DifferentialExpressionCalculator() { @Override//from www . j a v a 2s . c om public double getNormalizedExpressionValue(final String sample, final NormalizationMethod method, final MutableString elementId) { if (sample.startsWith("A")) { return 2 * Math.abs(randomEngine.nextGaussian() + 3); } else { return Math.abs(randomEngine.nextGaussian() + 20); } // fold change A/B = 2 } @Override public int getOverlapCount(final String sample, final MutableString elementId) { final NormalizationMethod normalizationMethod = new AlignedCountNormalization(); return (int) (getNormalizedExpressionValue(sample, normalizationMethod, elementId) * 100); } }; deCalc.setRunInParallel(true); int elementsPerSample = 1000; for (int i = 0; i < elementsPerSample; i++) { deCalc.defineElement("id-" + i); } deCalc.defineGroup("A"); deCalc.defineGroup("B"); final int numReplicates = 2; deCalc.reserve(elementsPerSample, numReplicates * 2); for (int i = 0; i < numReplicates; i++) { deCalc.associateSampleToGroup("A-" + i, "A"); deCalc.associateSampleToGroup("B-" + i, "B"); } // observe the counts to populate internal data structures: for (int i = 0; i < numReplicates; i++) { for (final String sampleId : deCalc.samples()) { MutableString elementId = new MutableString("id-" + i); deCalc.observe(sampleId, "id-" + i, deCalc.getOverlapCount(sampleId, elementId)); } } DifferentialExpressionResults list = new DifferentialExpressionResults(); final FoldChangeCalculator foldChange = new FoldChangeCalculator(list); final AverageCalculator average = new AverageCalculator(list); final TTestCalculator tTest = new TTestCalculator(list); final FisherExactRCalculator fisher = new FisherExactRCalculator(list); final NormalizationMethod normalizationMethod = new AlignedCountNormalization(); list = foldChange.evaluate(deCalc, normalizationMethod, list, "A", "B"); list = average.evaluate(deCalc, normalizationMethod, list, "A", "B"); list = tTest.evaluate(deCalc, normalizationMethod, list, "A", "B"); list = fisher.evaluate(deCalc, normalizationMethod, list, "A", "B"); assertTrue(list != null); }
From source file:edu.cornell.med.icb.goby.stats.TestStatistics.java
@Test public void testParalell() { final Random randomEngine = new Random(); final DifferentialExpressionCalculator deCalc = new DifferentialExpressionCalculator() { @Override//from www .j av a2 s . c om public double getNormalizedExpressionValue(final String sample, final NormalizationMethod method, final MutableString elementId) { if (sample.startsWith("A")) { return 2 * Math.abs(randomEngine.nextGaussian()); } else { return Math.abs(randomEngine.nextGaussian()); } // fold change A/B = 2 } @Override public int getOverlapCount(final String sample, final MutableString elementId) { final NormalizationMethod normalizationMethod = new AlignedCountNormalization(); return (int) (getNormalizedExpressionValue(sample, normalizationMethod, elementId) * 100); } }; deCalc.setRunInParallel(true); deCalc.defineElement("id-1"); deCalc.defineElement("id-2"); deCalc.defineGroup("A"); deCalc.defineGroup("B"); final int numReplicates = 2000; deCalc.reserve(2, numReplicates * 2); for (int i = 0; i < numReplicates; i++) { deCalc.associateSampleToGroup("A-" + i, "A"); deCalc.associateSampleToGroup("B-" + i, "B"); } // observe the counts to populate internal data structures: for (final String sampleId : deCalc.samples()) { final MutableString id1 = new MutableString("id-1"); final MutableString id2 = new MutableString("id-2"); deCalc.observe(sampleId, "id-1", deCalc.getOverlapCount(sampleId, id1)); deCalc.observe(sampleId, "id-2", deCalc.getOverlapCount(sampleId, id2)); } //deCalc.associateSampleToGroup("A-", "A"); //deCalc.associateSampleToGroup("B-1", "B"); DifferentialExpressionResults list = new DifferentialExpressionResults(); DifferentialExpressionInfo info1 = new DifferentialExpressionInfo("id-1"); DifferentialExpressionInfo info2 = new DifferentialExpressionInfo("id-2"); final FoldChangeCalculator foldChange = new FoldChangeCalculator(list); final AverageCalculator average = new AverageCalculator(list); final TTestCalculator tTest = new TTestCalculator(list); final FisherExactRCalculator fisher = new FisherExactRCalculator(list); final NormalizationMethod normalizationMethod = new AlignedCountNormalization(); list.add(info1); list.add(info2); list = foldChange.evaluate(deCalc, normalizationMethod, list, "A", "B"); list = average.evaluate(deCalc, normalizationMethod, list, "A", "B"); list = tTest.evaluate(deCalc, normalizationMethod, list, "A", "B"); list = fisher.evaluate(deCalc, normalizationMethod, list, "A", "B"); final MutableString foldChangeIndex = foldChange.statisticIds.get(0); final DifferentialExpressionInfo info = list.get(0); assertEquals("fold-change must match", 2d, list.getStatistic(info, foldChangeIndex), .2); assertTrue("T-test must be significant", list.getStatistic(info1, tTest.statisticIds.get(0)) < 0.01); }
From source file:org.broadinstitute.gatk.tools.walkers.genotyper.ReadLikelihoodsUnitTest.java
private double[][][] fillWithRandomLikelihoods(final String[] samples, final Allele[] alleles, final ReadLikelihoods<Allele> result) { final Random rnd = Utils.getRandomGenerator(); final double[][][] likelihoods = new double[samples.length][alleles.length][]; for (int s = 0; s < likelihoods.length; s++) { final ReadLikelihoods.Matrix<Allele> sampleLikelihoods = result.sampleMatrix(s); for (int a = 0; a < likelihoods[s].length; a++) { likelihoods[s][a] = new double[result.sampleReadCount(s)]; for (int r = 0; r < likelihoods[s][a].length; r++) sampleLikelihoods.set(a, r, likelihoods[s][a][r] = -Math.abs(rnd.nextGaussian())); }/*from www . j av a2s . c o m*/ } return likelihoods; }
From source file:com.rapidminer.gui.plotter.charts.Abstract2DChartPlotter.java
private void prepareNumericalData() { this.nominal = false; dataSet = new DefaultXYZDataset(); if (axis[X_AXIS] >= 0 && axis[Y_AXIS] >= 0) { this.minColor = Double.POSITIVE_INFINITY; this.maxColor = Double.NEGATIVE_INFINITY; List<double[]> dataList = new LinkedList<double[]>(); List<String> idList = new LinkedList<String>(); synchronized (dataTable) { Iterator<DataTableRow> i = this.dataTable.iterator(); while (i.hasNext()) { DataTableRow row = i.next(); double xValue = Double.NaN; if (axis[X_AXIS] >= 0) { xValue = row.getValue(axis[X_AXIS]); }//from w w w .ja v a2 s . c om double yValue = Double.NaN; if (axis[Y_AXIS] >= 0) { yValue = row.getValue(axis[Y_AXIS]); } double colorValue = Double.NaN; if (colorColumn >= 0) { colorValue = row.getValue(colorColumn); } if (plotColumnsLogScale) { if (Tools.isLessEqual(colorValue, 0.0d)) { colorValue = 0; } else { colorValue = Math.log10(colorValue); } } // TM: removed check // if (!Double.isNaN(xValue) && !Double.isNaN(yValue)) { double[] data = new double[3]; data[X_AXIS] = xValue; data[Y_AXIS] = yValue; data[COLOR_AXIS] = colorValue; if (!Double.isNaN(colorValue)) { this.minColor = Math.min(this.minColor, colorValue); this.maxColor = Math.max(this.maxColor, colorValue); } dataList.add(data); idList.add(row.getId()); // } } } double[][] data = new double[3][dataList.size()]; double minX = Double.POSITIVE_INFINITY; double maxX = Double.NEGATIVE_INFINITY; double minY = Double.POSITIVE_INFINITY; double maxY = Double.NEGATIVE_INFINITY; int index = 0; for (double[] d : dataList) { data[X_AXIS][index] = d[X_AXIS]; data[Y_AXIS][index] = d[Y_AXIS]; data[COLOR_AXIS][index] = d[COLOR_AXIS]; minX = MathFunctions.robustMin(minX, d[X_AXIS]); maxX = MathFunctions.robustMax(maxX, d[X_AXIS]); minY = MathFunctions.robustMin(minY, d[Y_AXIS]); maxY = MathFunctions.robustMax(maxY, d[Y_AXIS]); index++; } // jittering if (this.jitterAmount > 0) { Random jitterRandom = new Random(2001); double oldXRange = maxX - minX; double oldYRange = maxY - minY; for (int i = 0; i < dataList.size(); i++) { if (Double.isInfinite(oldXRange) || Double.isNaN(oldXRange)) { oldXRange = 0; } if (Double.isInfinite(oldYRange) || Double.isNaN(oldYRange)) { oldYRange = 0; } double pertX = oldXRange * (jitterAmount / 200.0d) * jitterRandom.nextGaussian(); double pertY = oldYRange * (jitterAmount / 200.0d) * jitterRandom.nextGaussian(); data[X_AXIS][i] += pertX; data[Y_AXIS][i] += pertY; } } // add data ((DefaultXYZDataset) dataSet).addSeries("All", data); // id handling int idCounter = 0; for (String id : idList) { idMap.put(new SeriesAndItem(0, idCounter++), id); } } }
From source file:br.fapesp.myutils.MyUtils.java
/** * Generates a Gaussian data set with K clusters and m dimensions * // w w w. ja v a 2 s . c o m * @param centers * K x m matrix * @param sigmas * K x m matrix * @param pointsPerCluster * number of points per cluster * @param seed * for the RNG * @param randomize * should the order of the instances be randomized? * @param supervised * should class label be present? if true, the class is the m+1 * attribute * * @return */ public static Instances genGaussianDataset(double[][] centers, double[][] sigmas, int pointsPerCluster, long seed, boolean randomize, boolean supervised) { Random r = new Random(seed); int K = centers.length; // number of clusters int m = centers[0].length; // number of dimensions FastVector atts = new FastVector(m); for (int i = 0; i < m; i++) atts.addElement(new Attribute("at" + i)); if (supervised) { FastVector cls = new FastVector(K); for (int i = 0; i < K; i++) cls.addElement("Gauss-" + i); atts.addElement(new Attribute("Class", cls)); } Instances data; if (supervised) data = new Instances(K + "-Gaussians-supervised", atts, K * pointsPerCluster); else data = new Instances(K + "-Gaussians", atts, K * pointsPerCluster); if (supervised) data.setClassIndex(m); Instance ith; for (int i = 0; i < K; i++) { for (int j = 0; j < pointsPerCluster; j++) { if (!supervised) ith = new DenseInstance(m); else ith = new DenseInstance(m + 1); ith.setDataset(data); for (int k = 0; k < m; k++) ith.setValue(k, centers[i][k] + (r.nextGaussian() * sigmas[i][k])); if (supervised) ith.setValue(m, "Gauss-" + i); data.add(ith); } } // run randomization filter if desired if (randomize) data.randomize(r); return data; }
From source file:jhplot.H2D.java
/** Fill the histogram with random numbers from Gaussian (Normal) distribution. * Seed is taken from time. //from w ww. j av a 2 s. c om * @param TotNumber number generated events * @param meanX mean of the gaussian in X * @param sdX standard deviation in X * @param meanY mean of the gaussian in Y * @param sdY standard deviation in Y */ public void fillGauss(int TotNumber, double meanX, double sdX, double meanY, double sdY) { java.util.Random random = new java.util.Random(); for (int i = 0; i < TotNumber; i++) h1.fill(sdX * random.nextGaussian() + meanX, sdY * random.nextGaussian() + meanY); }