@Override public double quantile(double p) { if (components.isEmpty()) { throw new IllegalStateException("Mixture is empty!"); } if (p < 0.0 || p > 1.0) { throw new IllegalArgumentException("Invalid p: " + p); } // Starting guess near peak of density. // Expand interval until we bracket. int xl, xu, inc = 1; int x = (int) mean(); if (p < cdf(x)) { do { x -= inc; inc *= 2; } while (p < cdf(x)); xl = x; xu = x + inc / 2; } else { do { x += inc; inc *= 2; } while (p > cdf(x)); xu = x; xl = x - inc / 2; } return quantile(p, xl, xu); }
@Override public double logp(int x) { if (components.isEmpty()) { throw new IllegalStateException("Mixture is empty!"); } return Math.log(p(x)); }
/** * BIC score of the mixture for given data. */ public double bic(double[] data) { if (components.isEmpty()) { throw new IllegalStateException("Mixture is empty!"); } int n = data.length; double logLikelihood = 0.0; for (double x : data) { double p = p(x); if (p > 0) { logLikelihood += Math.log(p); } } return logLikelihood - 0.5 * npara() * Math.log(n); }
@Override public double sd() { return Math.sqrt(var()); }