List of usage examples for org.apache.commons.math3.stat.descriptive DescriptiveStatistics addValue
public void addValue(double v)
From source file:classifiers.ComplexClassifierZufall.java
@Override public void BewertunginProzent() throws Exception { /* if (Model.getAnzahlkanten() != 0) { System.out.println("Parameter:" + "Vernetzungsprozent:" + this.vernetzung + "(" + (Model.getMoeglischeAnzahlKanten() * vernetzung) / Model.getAnzahlkanten() + ")," + " " + "Anzahldurchlauf:" + this.anzahldurchlauf + " " + "max Anzahlkanten:" + Model.getAnzahlkanten() + "(" + Model.getMoeglischeAnzahlKanten() + " )"); } else {/* w ww . j av a 2s . c o m*/ System.out.println("Parameter:" + "Vernetzungsprozent:" + this.vernetzung + "(" + (Model.getMoeglischeAnzahlKanten() * vernetzung) + ")," + " " + "Anzahldurchlauf:" + this.anzahldurchlauf + " " + "max Anzahlkanten:" + Model.getAnzahlkanten() + "(" + Model.getMoeglischeAnzahlKanten() + " )"); } System.out.println("----------------------------------------------------------------------------------------");*/ double count = 0; double[][] bestergeb = new double[1][2]; double max = 100; double[][] hilf; double[][] hilf2; double[] erg = new double[5]; for (int i = 0; i < anzahldurchlauf; i++) { Bootstrap(Modelmenge); train(this.traindaten); // System.out.println("training NR" + " " + i + ":"); // System.out.println("trainingsdeaten:"); hilf = new double[1][2]; hilf2 = new double[1][2]; hilf = test(traindaten); this.trainergebnisse[i][0] = hilf[0][0]; this.trainergebnisse[i][1] = hilf[0][1]; // System.out.println("Fehlerquote TrainingNR" + " " + i + ":" + " " + (double) (int) (this.trainergebnisse[i][0] * 100) / 100 + "%" + " " + "Dauer:" + " " + (int) (this.trainergebnisse[i][1]) + "ms"); hilf2 = test(testdaten); this.testergebnisse[i][0] = hilf2[0][0]; this.testergebnisse[i][1] = hilf2[0][1]; /* if(testergebnisse[i][0]<=max) { max=testergebnisse[i][0]; bestemodel=Model; bestergeb[0][0]=testergebnisse[i][0]; bestergeb[0][1]=testergebnisse[i][1]; }*/ //System.out.println("Validierung NR" + " " + i + ":"); //System.out.println("Validierungsngsdaten:"); // System.out.println("Fehlerquote Validierungs NR" + " " + i + ":" + " " + (double) (int) (this.testergebnisse[i][0] * 100) / 100 + "%" + " " + "Dauer:" + " " + (int) (this.testergebnisse[i][1]) + "ms"); //System.out.println("----------------------------------------------------------------------------------------"); } DescriptiveStatistics stats1 = new DescriptiveStatistics(); DescriptiveStatistics stat1 = new DescriptiveStatistics(); // Add the data from the array for (int i = 0; i < trainergebnisse.length; i++) { stats1.addValue(trainergebnisse[i][0]); stat1.addValue(trainergebnisse[i][1]); } double mean1 = stats1.getMean(); double std1 = stats1.getStandardDeviation(); double meanzeit1 = stat1.getMean(); double stdzeit1 = stat1.getStandardDeviation(); // System.out.println("Mittlere Felehrquote des Tainings:" + " " + (double) (int) (mean1 * 100) / 100 + "%" + "(" + (double) (int) ((std1 / Math.sqrt(anzahldurchlauf)) * 100) / 100 + "%)"); //System.out.println("Mittlere Dauer des trainings:" + " " + (int) (meanzeit1) + " " + "ms" + "(" + (int) ((stdzeit1 / Math.sqrt(anzahldurchlauf))) + "ms)"); //System.out.println("--------------------------------------------------------------------------------------"); DescriptiveStatistics stats = new DescriptiveStatistics(); DescriptiveStatistics stat = new DescriptiveStatistics(); // Add the data from the array for (int i = 0; i < testergebnisse.length; i++) { stats.addValue(testergebnisse[i][0]); stat.addValue(testergebnisse[i][1]); } this.Mittlerevalidierungsquote = stats.getMean(); this.stadartdeviationvalidierung = (int) (stats.getStandardDeviation() / Math.sqrt(anzahldurchlauf)); this.Mittlerezeit = stat.getMean(); this.standartdeviationtime = (int) (stat.getStandardDeviation() / Math.sqrt(anzahldurchlauf)); // System.out.println("Mittlere Fehlerquote der Validierungsmengen:" + " " + (double) (int) (Mittlerevalidierungsquote * 100) / 100 + "%" + "(" + (double) (int) ((stadartdeviationvalidierung / Math.sqrt(anzahldurchlauf)) * 100) / 100 + "%)"); //System.out.println("Mittlere Dauer der Validierung :" + " " + (int) (Mittlerezeit) + " " + "ms" + "(" + (int) ((standartdeviationtime / Math.sqrt(anzahldurchlauf))) + "ms)"); erg[0] = vernetzung; erg[1] = (double) (int) (Mittlerevalidierungsquote * 100) / 100; erg[2] = Mittlerezeit; erg[3] = (double) (int) ((stadartdeviationvalidierung / Math.sqrt(anzahldurchlauf)) * 100) / 100; erg[4] = (int) ((standartdeviationtime / Math.sqrt(anzahldurchlauf))); train(this.Modelmenge); hilf = test(Modelmenge); this.Modelergebnisse[0][0] = hilf[0][0]; this.Modelergebnisse[0][1] = hilf[0][1]; hilf = test(validierungsmenge); validierungsergebnisse[0][0] = hilf[0][0]; validierungsergebnisse[0][1] = hilf[0][1]; struct.setErgebnisse(erg); /* System.out.println("---------------------------------------------------------------------------------------");*/ ///System.out.println("Fehlerquote der training auf dem Datensatz:" + " " + (double) (int) (Modelergebnisse[0][0] * 100) / 100 + "%"); //System.out.println("Zeit des trainings (Datensatz):" + " " + (int) (Modelergebnisse[0][1]) + " " + "ms"); //System.out.println("---------------------------------------------------------------------------------------"); //System.out.println("Fehlerquote der Test:" + " " + (double) (int) (validierungsergebnisse[0][0] * 100) / 100 + "%"); // System.out.println("Zeit der Test:" + " " + (int) (validierungsergebnisse[0][1]) + " " + "ms"); /* System.out.println(); System.out.println("Beste Struktur:"+" "+"Validierung:"+" "+(int)bestergeb[0][0]+"%"+" "+"Zeit:"+" "+(int)bestergeb[0][1]+"ms"); System.out.println("---------------------------------------------------------------------------------------"); bestemodel=Model; if(bestemodel!=null) bestemodel.ToString();*/ }
From source file:cn.pku.sei.GHRC.MySpectralClusterer.java
/** * Generates a clusterer by the mean of spectral clustering algorithm. * //from w w w . j av a 2 s. com * @param data * set of instances serving as training data */ public void buildClusterer(final GHGraphBuilder data) { setData(data); final int n = data.getNodeNum(); final DoubleMatrix2D w = useSparseMatrix ? DoubleFactory2D.sparse.make(n, n) : DoubleFactory2D.dense.make(n, n); /* * final double[][] v1 = new double[n][]; for (int i = 0; i < n; i++) * v1[i] = data.instance(i).toDoubleArray(); final DoubleMatrix2D v = * DoubleFactory2D.dense.make(v1); */ final double sigma_sq = sigma * sigma; DescriptiveStatistics stats = new DescriptiveStatistics(); stats.addValue(1); // Sets up similarity matrix try (Transaction tx = data.getGraphDb().beginTx()) { Iterator<Relationship> rels = data.getAllRelationships(); int id1, id2; double score; double previousScore; while (rels.hasNext()) { Relationship rel = rels.next(); score = GHRepository.getScore(rel); // score = Math.exp(-(score * score) / (2 * sigma_sq)); id1 = (int) rel.getStartNode().getId(); id2 = (int) rel.getEndNode().getId(); previousScore = w.get(id2, id1); w.set(id1, id2, score + previousScore); w.set(id2, id1, score + previousScore); } tx.success(); } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { double s = w.get(i, j); if (s > 0) { stats.addValue(s); } } } double median = stats.getPercentile(persentile); System.out.println("-------------Sim Matrix--------------"); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { double s = w.get(i, j) / median; s = s >= 1 ? 0.99 : s; w.set(i, j, s); System.out.print(w.get(i, j) + "\t"); } w.set(i, i, 1); System.out.println(); } System.out.println(median); // Compute point partitions final int[][] p = partition(w /* , alpha_star */); // Deploys results numOfClusters = p.length; cluster = new int[n]; for (int i = 0; i < p.length; i++) for (int j = 0; j < p[i].length; j++) cluster[p[i][j]] = i; }
From source file:gr.iti.mklab.reveal.forensics.maps.dq.DQExtractor.java
public void detectDQDiscontinuities() { int imWidth = dcts.length; int imHeight = dcts[0].length; int[] p_h_avg = new int[maxCoeffs]; int[] p_h_fft = new int[maxCoeffs]; int[] p_final = new int[maxCoeffs]; double[][] pTampered = new double[maxCoeffs][]; double[][] pUntampered = new double[maxCoeffs][]; for (int coeffIndex = 0; coeffIndex < maxCoeffs; coeffIndex++) { int coe = coeff[coeffIndex]; int startY = coe % 8 - 1; if (startY == -1) { startY = 8;// ww w. j ava2 s . com } int startX = (int) Math.floor((coe - 1) / 8); List<Integer> selectedCoeffs = new ArrayList<Integer>(); for (int ii = startX; ii < imWidth; ii += 8) { for (int jj = startY; jj < imHeight; jj += 8) { selectedCoeffs.add(dcts[ii][jj]); } } int minCoeffValue = Collections.min(selectedCoeffs); int maxCoeffValue = Collections.max(selectedCoeffs); int s_0; Double[] coeffHist = new Double[0]; if (maxCoeffValue - minCoeffValue > 0) { //will be a power of 2 to allow for fft (zero padded) int trueHistRange = maxCoeffValue - minCoeffValue + 1; //int histLength = trueHistRange; int histLength = (int) Math.pow(2, Math.ceil(Math.log(trueHistRange) / Math.log(2))); coeffHist = new Double[histLength]; for (int ii = 0; ii < coeffHist.length; ii++) { coeffHist[ii] = 0.0; } for (Integer selectedCoeff : selectedCoeffs) { coeffHist[selectedCoeff - minCoeffValue] += 1; } List<Double> coeffHistList = Arrays.asList(coeffHist); s_0 = coeffHistList.indexOf(Collections.max(coeffHistList)); List<Double> h = new ArrayList<>(); DescriptiveStatistics vals; for (int coeffInd = 1; coeffInd < coeffHistList.size(); coeffInd++) { vals = new DescriptiveStatistics(); for (int leapInd = s_0; leapInd < coeffHistList.size(); leapInd += coeffInd) { vals.addValue(coeffHistList.get(leapInd)); } for (int leapInd = s_0 - coeffInd; leapInd >= 0; leapInd -= coeffInd) { vals.addValue(coeffHistList.get(leapInd)); } h.add(vals.getMean()); } p_h_avg[coeffIndex] = (h.indexOf(Collections.max(h))); FastFourierTransformer fastFourierTransformer = new FastFourierTransformer( DftNormalization.STANDARD); Complex[] fft = fastFourierTransformer.transform(ArrayUtils.toPrimitive(coeffHist), TransformType.FORWARD); double[] power = new double[fft.length]; for (int ii = 0; ii < power.length; ii++) { power[ii] = fft[ii].abs(); } //Find first local minimum, to bypass DC peak double DC = power[0]; int FreqValley = 1; while (FreqValley < power.length - 1 & power[FreqValley] >= power[FreqValley + 1]) { FreqValley++; } int maxFFTInd = 0; double maxFFTVal = 0; double minFFTVal = Double.MAX_VALUE; for (int ii = FreqValley; ii < power.length / 2; ii++) { if (power[ii] > maxFFTVal) { maxFFTInd = ii; maxFFTVal = power[ii]; } if (power[ii] < minFFTVal) { minFFTVal = power[ii]; } } if (maxFFTInd == 0 | maxFFTVal < (DC / 5) | minFFTVal / maxFFTVal > 0.9) { p_h_fft[coeffIndex] = 1; } else { p_h_fft[coeffIndex] = Math.round(coeffHist.length / maxFFTInd); } } else { p_h_avg[coeffIndex] = 1; p_h_fft[coeffIndex] = 1; s_0 = 0; } if (p_h_avg[coeffIndex] < p_h_fft[coeffIndex]) { p_final[coeffIndex] = p_h_avg[coeffIndex]; } else { p_final[coeffIndex] = p_h_fft[coeffIndex]; } pTampered[coeffIndex] = new double[selectedCoeffs.size()]; pUntampered[coeffIndex] = new double[selectedCoeffs.size()]; int[] adjustedCoeffs = new int[selectedCoeffs.size()]; int[] period_start = new int[selectedCoeffs.size()]; int[] period; int[] num = new int[selectedCoeffs.size()]; int[] denom = new int[selectedCoeffs.size()]; double[] P_u = new double[selectedCoeffs.size()]; double[] P_t = new double[selectedCoeffs.size()]; if (p_final[coeffIndex] != 1) { for (int ii = 0; ii < adjustedCoeffs.length; ii++) { adjustedCoeffs[ii] = selectedCoeffs.get(ii) - minCoeffValue; period_start[ii] = adjustedCoeffs[ii] - rem(adjustedCoeffs[ii] - s_0, p_final[coeffIndex]); } for (int kk = 0; kk < selectedCoeffs.size(); kk++) { if (period_start[kk] > s_0) { period = new int[p_final[coeffIndex]]; for (int ii = 0; ii < p_final[coeffIndex]; ii++) { period[ii] = period_start[kk] + ii; if (period[ii] >= coeffHist.length) { period[ii] = period[ii] - p_final[coeffIndex]; } } num[kk] = (int) coeffHist[adjustedCoeffs[kk]].doubleValue(); denom[kk] = 0; for (int ll = 0; ll < period.length; ll++) { denom[kk] = denom[kk] + (int) coeffHist[period[ll]].doubleValue(); } } else { period = new int[p_final[coeffIndex]]; for (int ii = 0; ii < p_final[coeffIndex]; ii++) { period[ii] = period_start[kk] - ii; if (period_start[kk] - p_final[coeffIndex] + 1 <= 0) { if (period[ii] <= 0) { period[ii] = period[ii] + p_final[coeffIndex]; } } } num[kk] = (int) coeffHist[adjustedCoeffs[kk]].doubleValue(); denom[kk] = 0; for (int ll = 0; ll < period.length; ll++) { denom[kk] = denom[kk] + (int) coeffHist[period[ll]].doubleValue(); } } P_u[kk] = ((double) num[kk] / denom[kk]); P_t[kk] = (1.0 / p_final[coeffIndex]); if (P_u[kk] + P_t[kk] != 0) { pTampered[coeffIndex][kk] = P_t[kk] / (P_u[kk] + P_t[kk]); pUntampered[coeffIndex][kk] = P_u[kk] / (P_u[kk] + P_t[kk]); } else { pTampered[coeffIndex][kk] = 0.5; pUntampered[coeffIndex][kk] = 0.5; } } } else { for (int kk = 0; kk < selectedCoeffs.size(); kk++) { pTampered[coeffIndex][kk] = 0.5; pUntampered[coeffIndex][kk] = 0.5; } } } double[] pTamperedOverall = new double[pTampered[0].length]; double pTamperedProd; double pUntamperedProd; for (int locationIndex = 0; locationIndex < pTampered[0].length; locationIndex++) { pTamperedProd = 1; pUntamperedProd = 1; for (int coeffIndex = 0; coeffIndex < pTampered.length; coeffIndex++) { pTamperedProd = pTamperedProd * pTampered[coeffIndex][locationIndex]; pUntamperedProd = pUntamperedProd * pUntampered[coeffIndex][locationIndex]; } if (pTamperedProd + pUntamperedProd != 0) { pTamperedOverall[locationIndex] = pTamperedProd / (pTamperedProd + pUntamperedProd); } else { pTamperedOverall[locationIndex] = 0; } } int blocksH = imWidth / 8; int blocksV = imHeight / 8; double[][] outputMap = new double[blocksV][blocksH]; for (int kk = 0; kk < pTamperedOverall.length; kk++) { outputMap[kk % blocksV][(int) Math.floor(kk / blocksV)] = pTamperedOverall[kk]; if (pTamperedOverall[kk] > maxProbValue) { maxProbValue = pTamperedOverall[kk]; } if (pTamperedOverall[kk] < minProbValue) { minProbValue = pTamperedOverall[kk]; } } probabilityMap = outputMap; BufferedImage outputIm = visualizeWithJet(outputMap); // output displaySurface = outputIm; }
From source file:mase.app.allocation.AllocationProblem.java
private DescriptiveStatistics pairDistances(RealMatrix distMatrix) { DescriptiveStatistics ds = new DescriptiveStatistics(); distMatrix = distMatrix.copy();/*from ww w .java 2 s .co m*/ for (int k = 0; k < numAgents; k++) { // find closest pair double min = Double.POSITIVE_INFINITY; int minI = -1, minJ = -1; for (int i = 0; i < numAgents; i++) { for (int j = 0; j < numAgents; j++) { double d = distMatrix.getEntry(i, j); if (!Double.isNaN(d) && d < min) { min = d; minI = i; minJ = j; } } } ds.addValue(min); distMatrix.setRow(minI, nulify); distMatrix.setColumn(minJ, nulify); } return ds; }
From source file:knop.psfj.heatmap.FractionnedSpace.java
/** * Gets the pixel value.// w ww.j a v a2 s . c o m * * @param f the f * @return the pixel value */ public float getPixelValue(Fraction f) { DescriptiveStatistics stats = new DescriptiveStatistics(); float median = Float.NaN; //System.out.println(f); if (f.size() != 0) { for (Point p : f) { //System.out.println(p.getValue()); if (stats == null) System.out.println(stats); if (p == null) continue; stats.addValue(p.getValue()); } median = new Float(stats.getPercentile(50)); //System.out.println("Resultat : "+median); } return median; }
From source file:knop.utils.stats.DataSet.java
/** * Gets the maximum column size./*from w w w . j a va 2 s . co m*/ * * @return the maximum column size */ public int getMaximumColumnSize() { DescriptiveStatistics stats = new DescriptiveStatistics(); for (String column : getColumnList()) { stats.addValue(getColumnSize(column)); } return MathUtils.round(stats.getMax()); }
From source file:knop.utils.stats.DataSet.java
/** * Gets the minimum column size./*from ww w . j a va 2 s .c o m*/ * * @return the minimum column size */ public int getMinimumColumnSize() { DescriptiveStatistics stats = new DescriptiveStatistics(); for (String column : getColumnList()) { stats.addValue(getColumnSize(column)); } return MathUtils.round(stats.getMin()); }
From source file:cc.kave.commons.pointsto.evaluation.events.MRREvaluation.java
private double calcMRR(ICallsRecommender<Query> recommender, Map<ICompletionEvent, List<Usage>> eventQueries) { DescriptiveStatistics reciprocalRank = new DescriptiveStatistics(); for (Map.Entry<ICompletionEvent, List<Usage>> eventEntry : eventQueries.entrySet()) { ICompletionEvent event = eventEntry.getKey(); IProposal expectedProposal = event.getLastSelectedProposal(); ICoReMethodName expectedMethod = CoReNameConverter .convert((cc.kave.commons.model.naming.codeelements.IMethodName) expectedProposal.getName()); for (Usage query : eventEntry.getValue()) { double rr = measure.calculate(recommender, Query.createAsCopyFrom(query), ImmutableSet.of(expectedMethod)); reciprocalRank.addValue(rr); }// ww w .ja v a 2s. c o m } return reciprocalRank.getMean(); }
From source file:at.ofai.music.util.WormFileParseException.java
public double getBPM() { double maxbpm = 165; double minbpm = 67; ArrayList<Double> onsetList = new ArrayList<Double>(); for (Iterator<Event> it = iterator(); it.hasNext();) { Event e = it.next();//from w w w . ja va 2 s . co m onsetList.add(e.keyDown); } DescriptiveStatistics stats = new DescriptiveStatistics(); if (onsetList.size() > 1) for (int i = 1; i < onsetList.size(); i++) { stats.addValue(onsetList.get(i) - onsetList.get(i - 1)); } double median = stats.getPercentile(50); double bpm = 60 / median; if (bpm > maxbpm) { bpm = bpm / 2; } else if (bpm < minbpm) { bpm = bpm * 2; } return bpm; }
From source file:com.alibaba.dubbo.demo.consumer.DemoAction.java
public void start() throws Exception { int threads = 100; final DescriptiveStatistics stats = new SynchronizedDescriptiveStatistics(); DubboBenchmark.BenchmarkMessage msg = prepareArgs(); final byte[] msgBytes = msg.toByteArray(); int n = 1000000; final CountDownLatch latch = new CountDownLatch(n); ExecutorService es = Executors.newFixedThreadPool(threads); final AtomicInteger trans = new AtomicInteger(0); final AtomicInteger transOK = new AtomicInteger(0); long start = System.currentTimeMillis(); for (int i = 0; i < n; i++) { es.submit(() -> {/* w w w . j a v a 2s. c o m*/ try { long t = System.currentTimeMillis(); DubboBenchmark.BenchmarkMessage m = testSay(msgBytes); t = System.currentTimeMillis() - t; stats.addValue(t); trans.incrementAndGet(); if (m != null && m.getField1().equals("OK")) { transOK.incrementAndGet(); } } catch (InterruptedException e) { e.printStackTrace(); } finally { latch.countDown(); } }); } latch.await(); start = System.currentTimeMillis() - start; System.out.printf("sent requests : %d\n", n); System.out.printf("received requests : %d\n", trans.get()); System.out.printf("received requests_OK : %d\n", transOK.get()); System.out.printf("throughput (TPS) : %d\n", n * 1000 / start); System.out.printf("mean: %f\n", stats.getMean()); System.out.printf("median: %f\n", stats.getPercentile(50)); System.out.printf("max: %f\n", stats.getMax()); System.out.printf("min: %f\n", stats.getMin()); System.out.printf("99P: %f\n", stats.getPercentile(90)); }