Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/Fitting.java @ 9348:a3f318347707
Show wq outliers within same thems with different symbol: not ready yet
author | gernotbelger |
---|---|
date | Tue, 31 Jul 2018 11:25:38 +0200 |
parents | 83bb52fa0c32 |
children | ddcd52d239cd |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/Fitting.java Mon Jul 30 16:43:44 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/fixings/Fitting.java Tue Jul 31 11:25:38 2018 +0200 @@ -22,54 +22,33 @@ import org.dive4elements.river.artifacts.math.GrubbsOutlier; import org.dive4elements.river.artifacts.math.fitting.Function; -public class Fitting -{ +public class Fitting { private static Logger log = Logger.getLogger(Fitting.class); /** Use instance of this factory to find meta infos for outliers. */ public interface QWDFactory { - - QWD create(double q, double w); - - } // interface QWFactory - - public static final QWDFactory QWD_FACTORY = new QWDFactory() { - @Override - public QWD create(double q, double w) { - return new QWD(q, w); - } - }; - - protected boolean checkOutliers; - protected Function function; - protected QWDFactory qwdFactory; - protected double chiSqr; - protected double [] parameters; - protected ArrayList<QWI> removed; - protected QWD [] referenced; - protected double standardDeviation; - - - public Fitting() { - removed = new ArrayList<QWI>(); + QWD create(double q, double w, boolean isOutlier); } - public Fitting(Function function) { - this(function, QWD_FACTORY); - } - - public Fitting(Function function, QWDFactory qwdFactory) { - this(function, qwdFactory, false); - } + private final boolean checkOutliers; + + private final Function function; + + private final QWDFactory qwdFactory; + + private double chiSqr; + + private double[] parameters; + + private final List<QWD> removed = new ArrayList<>(); + + private QWD[] referenced; + + private double standardDeviation; - public Fitting( - Function function, - QWDFactory qwdFactory, - boolean checkOutliers - ) { - this(); - this.function = function; - this.qwdFactory = qwdFactory; + public Fitting(Function function, QWDFactory qwdFactory, boolean checkOutliers) { + this.function = function; + this.qwdFactory = qwdFactory; this.checkOutliers = checkOutliers; } @@ -77,24 +56,16 @@ return function; } - public void setFunction(Function function) { - this.function = function; - } - public boolean getCheckOutliers() { return checkOutliers; } - public void setCheckOutliers(boolean checkOutliers) { - this.checkOutliers = checkOutliers; - } - public double getChiSquare() { return chiSqr; } public void reset() { - chiSqr = 0.0; + chiSqr = 0.0; parameters = null; removed.clear(); referenced = null; @@ -105,22 +76,18 @@ return !removed.isEmpty(); } - public List<QWI> getOutliers() { - return removed; + public QWD[] outliersToArray() { + return removed.toArray(new QWD[removed.size()]); } - public QWI [] outliersToArray() { - return removed.toArray(new QWI[removed.size()]); - } - - public QWD [] referencedToArray() { - return referenced != null ? (QWD [])referenced.clone() : null; + public QWD[] referencedToArray() { + return referenced != null ? (QWD[]) referenced.clone() : null; } public double getMaxQ() { double maxQ = -Double.MAX_VALUE; if (referenced != null) { - for (QWI qw: referenced) { + for (QWI qw : referenced) { double q = qw.getQ(); if (q > maxQ) { maxQ = q; @@ -130,7 +97,7 @@ return maxQ; } - public double [] getParameters() { + public double[] getParameters() { return parameters; } @@ -138,7 +105,7 @@ return standardDeviation; } - public boolean fit(double [] qs, double [] ws) { + public boolean fit(double[] qs, double[] ws) { TDoubleArrayList xs = new TDoubleArrayList(qs.length); TDoubleArrayList ys = new TDoubleArrayList(ws.length); @@ -188,10 +155,11 @@ } if (parameters == null) { /* - log.debug("Parameters is null"); - for (int i = 0, N = xs.size(); i < N; ++i) { - log.debug("DATA: " + xs.getQuick(i) + " " + ys.getQuick(i)); - }*/ + * log.debug("Parameters is null"); + * for (int i = 0, N = xs.size(); i < N; ++i) { + * log.debug("DATA: " + xs.getQuick(i) + " " + ys.getQuick(i)); + * } + */ return false; } @@ -219,9 +187,7 @@ } int idx = outlier.intValue(); - removed.add( - qwdFactory.create( - xs.getQuick(idx), ys.getQuick(idx))); + removed.add(qwdFactory.create(xs.getQuick(idx), ys.getQuick(idx), true)); xs.remove(idx); ys.remove(idx); } @@ -230,14 +196,13 @@ referenced = new QWD[xs.size()]; for (int i = 0; i < referenced.length; ++i) { - QWD qwd = qwdFactory.create(xs.getQuick(i), ys.getQuick(i)); + QWD qwd = qwdFactory.create(xs.getQuick(i), ys.getQuick(i), false); if (qwd == null) { log.warn("QW creation failed!"); - } - else { + } else { referenced[i] = qwd; - double dw = (qwd.getW() - instance.value(qwd.getQ()))*100.0; + double dw = (qwd.getW() - instance.value(qwd.getQ())) * 100.0; qwd.setDeltaW(dw); stdDev.increment(dw); } @@ -249,5 +214,4 @@ return true; } -} -// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : +} \ No newline at end of file