List of usage examples for org.apache.commons.math3.stat.descriptive.moment StandardDeviation evaluate
public double evaluate(final double[] values, final double mean) throws MathIllegalArgumentException
From source file:jp.ac.tohoku.ecei.sb.metabolomeqc.basiccorrector.helper.CoefficientOfVariation.java
public static double evaluate(double[] values) { double mean = DoubleStream.of(values).sum() / values.length; StandardDeviation standardDeviation = new StandardDeviation(); double sd = standardDeviation.evaluate(values, mean); return sd / mean; }
From source file:jp.ac.tohoku.ecei.sb.metabolomeqc.basiccorrector.CompoundCVFilter.java
@Override public IntensityMatrix doCorrection(IntensityMatrix original) { List<Sample> globalQC = original.getGlobalQCSamples(); if (globalQC.size() == 0) throw new IllegalArgumentException("No global QC"); Sample selectedGlobalQC = globalQC.get(0); log.info("selected global QC {}", selectedGlobalQC); Map<Integer, Map<Plate, Double>> compound2cv = new HashMap<>(); Map<Integer, Compound> id2compound = new HashMap<>(); for (Compound oneCompound : original.getRowKeys()) { compound2cv.put(oneCompound.getId(), new HashMap<>()); id2compound.put(oneCompound.getId(), oneCompound); }/*from ww w . ja v a 2 s . co m*/ for (Compound oneCompound : original.getRowKeys()) { for (Map.Entry<Plate, List<Injection>> onePlate : original.getInjectionsByPlate().entrySet()) { double[] globalInjectionValues = onePlate.getValue().stream() .filter(i -> i.getSample().equals(selectedGlobalQC) && !i.isIgnored()) .mapToDouble(i -> original.get(oneCompound, i)).toArray(); double mean = DoubleStream.of(globalInjectionValues).sum() / globalInjectionValues.length; StandardDeviation standardDeviation = new StandardDeviation(); double sd = standardDeviation.evaluate(globalInjectionValues, mean); double cv = sd / mean; compound2cv.get(oneCompound.getId()).put(onePlate.getKey(), cv); oneCompound.setAttribute(String.format("Plate-%d-CV", onePlate.getKey().getId()), String.valueOf(cv)); } } Map<Integer, Double> maxcv = new HashMap<>(); List<Compound> newCompounds = new ArrayList<>(); for (Map.Entry<Integer, Map<Plate, Double>> one : compound2cv.entrySet()) { maxcv.put(one.getKey(), one.getValue().values().stream().max(Double::compare).get()); id2compound.get(one.getKey()).setAttribute("MaxCV", maxcv.get(one.getKey())); if (maxcv.get(one.getKey()) < CVThreshold) { newCompounds.add(id2compound.get(one.getKey())); } } IntensityMatrixImpl newMatrix = new IntensityMatrixImpl(newCompounds.size(), original.getSize()[1]); newMatrix.setRowKeys(newCompounds); newMatrix.setColumnKeys(original.getColumnKeys()); for (Compound oneCompound : newCompounds) { for (Injection oneInjection : original.getColumnKeys()) { newMatrix.put(oneCompound, oneInjection, original.get(oneCompound, oneInjection)); } } return newMatrix; }
From source file:RequestStat.java
public void computeStat(double duration, int maxUsers) { double[] times = getDurationAsArray(); min = (long) StatUtils.min(times); max = (long) StatUtils.max(times); double sum = 0; for (double d : times) sum += d;/* www. j a v a2 s. co m*/ avg = sum / times.length; p50 = (long) StatUtils.percentile(times, 50.0); p95 = (long) StatUtils.percentile(times, 95.0); p99 = (long) StatUtils.percentile(times, 99.0); StandardDeviation stdDev = new StandardDeviation(); stddev = (long) stdDev.evaluate(times, avg); this.duration = duration; this.maxUsers = maxUsers; rps = (count - errorCount) / duration; startDate = getDateFromInstant(start); successCount = count - errorCount; }
From source file:net.sf.javaml.clustering.AQBC.java
/** * Normalizes the data to mean 0 and standard deviation 1. This method * discards all instances that cannot be normalized, i.e. they have the same * value for all attributes.//from w ww. j av a 2 s.co m * * @param data * @return */ private Vector<TaggedInstance> normalize(Dataset data) { Vector<TaggedInstance> out = new Vector<TaggedInstance>(); for (int i = 0; i < data.size(); i++) { Double[] old = data.instance(i).values().toArray(new Double[0]); double[] conv = new double[old.length]; for (int j = 0; j < old.length; j++) { conv[j] = old[j]; } Mean m = new Mean(); double MU = m.evaluate(conv); // System.out.println("MU = "+MU); StandardDeviation std = new StandardDeviation(); double SIGM = std.evaluate(conv, MU); // System.out.println("SIGM = "+SIGM); if (!MathUtils.eq(SIGM, 0)) { double[] val = new double[old.length]; for (int j = 0; j < old.length; j++) { val[j] = (float) ((old[j] - MU) / SIGM); } // System.out.println("VAL "+i+" = "+Arrays.toString(val)); out.add(new TaggedInstance(new DenseInstance(val, data.instance(i).classValue()), i)); } } // System.out.println("FIRST = "+out.get(0)); return out; }