//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** @author John Miller * @version 1.6 * @date Tue Jul 16 12:14:21 EDT 2019 * @see LICENSE (MIT style license file). * * @title Model Support: Quality of Fit (QoF) */ package scalation.analytics import scala.collection.mutable.{LinkedHashMap, Map} import scalation.linalgebra.{VectoD, VectorD} import scalation.math.noDouble //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** The `QoF` trait defines methods to determine basic Quality of Fit 'QoF' measures. */ trait QoF { //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** Diagnose the health of the model by computing the Quality of Fit (QoF) measures, * from the error/residual vector and the predicted & actual responses. * For some models the instances may be weighted. * @see `Regression_WLS` * @param e the m-dimensional error/residual vector (yy - yp) * @param yy the actual response vector to use (test/full) * @param yp the predicted response vector (test/full) * @param w the weights on the instances (defaults to null) * @param ym the mean of the actual response vector to use (train/full) */ def diagnose (e: VectoD, yy: VectoD, yp: VectoD, w: VectoD = null, ym: Double = noDouble): Unit //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** Return the Quality of Fit (QoF) measures corresponding to the labels given * above in the 'fitLabel' method. * Note, if 'sse > sst', the model introduces errors and the 'rSq' may be negative, * otherwise, R^2 ('rSq') ranges from 0 (weak) to 1 (strong). * Override to add more quality of fit measures. */ def fit: VectoD //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** Return the labels for the Quality of Fit (QoF) measures. * Override to add more Quality of Fit measures. */ def fitLabel: Seq [String] //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** Return the help string that describes the Quality of Fit (QoF) measures * provided by implementing classes. Override to correspond to 'fitLabel'. */ def help: String //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** Format a double value. * @param z the double value to format */ def f_ (z: Double): String = "%.6f".format (z) //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** Build a map of quality of fit measures (use of `LinkedHashMap` makes it ordered). */ def fitMap: Map [String, String] = { val lm = LinkedHashMap [String, String] () // empty list map val fl = fitLabel // fit labels val fv = fit // fit values for (i <- fl.indices) lm += fl(i) -> f_(fv(i)) lm } // fitMap } // QoF trait