List of usage examples for org.apache.commons.math3.analysis.interpolation LoessInterpolator LoessInterpolator
public LoessInterpolator(double bandwidth, int robustnessIters, double accuracy) throws OutOfRangeException, NotPositiveException
From source file:jp.ac.tohoku.ecei.sb.metabolomeqc.basiccorrector.LoessIntensityCorrector.java
@Override public IntensityMatrix doCorrection(IntensityMatrix original) { updateBadInjections(original);/*from www. j a va2s . c om*/ List<Injection> normalSamples = original.getNormalInjections(); List<Sample> globalQCSamples = original.getGlobalQCSamples(); if (globalQCSamples.size() == 0) throw new UnsupportedOperationException("No global QC"); Sample selectedGlobalQC = globalQCSamples.get(0); // Calculate SQC median Map<Compound, Double> compoundIntensityBase = GlobalQCMedianCalculator.calcGlobalQCMedian(original, badInjections); // Main Correction IntensityMatrix corrected = new IntensityMatrixImpl(original.getSize()[0], normalSamples.size()); corrected.setRowKeys(original.getRowKeys()); corrected.setColumnKeys(normalSamples); //corrected.getAttributes().putAll(original.getAttributes()); LoessInterpolator loessInterpolator = new LoessInterpolator(bandwidth, robustnessIters, accuracy); for (Compound oneCompound : corrected.getRowKeys()) { double base = compoundIntensityBase.get(oneCompound); for (Map.Entry<Plate, List<Injection>> plateInjection : original.getInjectionsByPlate().entrySet()) { List<Double> xlist = new ArrayList<>(); List<Double> ylist = new ArrayList<>(); for (Injection injection : plateInjection.getValue()) { //log.info("injection: {}", injection); if (!injection.getSample().equals(selectedGlobalQC)) continue; if (injection.isIgnored()) continue; if (badInjections != null && badInjections.contains(injection)) continue; xlist.add((double) injection.getRunIndex()); ylist.add(original.get(oneCompound, injection)); } //log.info("X : {}", xlist.size()); PolynomialSplineFunction fn = loessInterpolator.interpolate( xlist.stream().mapToDouble(x -> x).toArray(), ylist.stream().mapToDouble(x -> x).toArray()); for (Injection injection : plateInjection.getValue()) { if (!normalSamples.contains(injection)) continue; corrected.put(oneCompound, injection, original.get(oneCompound, injection) - base + fn.value(injection.getRunIndex())); } } } return corrected; }