/** * Predict the log-posterior for the given sample; this is the * log-probability of the sample point belonging to each of the gaussians in * the mixture. * * @param sample * the sample * @return the log-probability for each gaussian */ public double[] predictLogPosterior(double[] sample) { return predictLogPosterior(new double[][] { sample })[0]; }
/** * Construct with the given number of bins per dimension * * @param nbins * the number of bins in each dimension for the histograms */ public HistogramModel(int... nbins) { super(nbins.length); assert (nbins.length > 0); histogram = new MultidimensionalHistogram(nbins); }
@Override protected MultivariateGaussian[] createGaussians(int ngauss, int ndims) { final MultivariateGaussian[] arr = new MultivariateGaussian[ngauss]; for (int i = 0; i < ngauss; i++) { arr[i] = new FullMultivariateGaussian(ndims); } return arr; }
@Override protected MultivariateGaussian[] createGaussians(int ngauss, int ndims) { final MultivariateGaussian[] arr = new MultivariateGaussian[ngauss]; for (int i = 0; i < ngauss; i++) { arr[i] = new DiagonalMultivariateGaussian(ndims); } return arr; }
@Override public String toString() { String s = "LocalHistogram[\n"; for (int y=0; y<blocks_y; y++) for (int x=0; x<blocks_x; x++) s += "\t(" + x + ", " + y + ") = " + histograms[y][x].toString() + "\n"; s += "]\n"; return s; }
@Override final void normalise(Histogram h, int blockArea) { h.normaliseL1(); } },
@Override protected float classifyPixel(Float[] pix) { return (float) gauss.estimateProbability(pix); }
@Override public double[] estimateLogProbability(double[][] x) { final double[] lps = new double[x.length]; for (int i = 0; i < x.length; i++) lps[i] = estimateLogProbability(x[i]); return lps; } }
@Override public double[][] sample(int count, Random rng) { final double[][] samples = new double[count][]; for (int i = 0; i < count; i++) samples[i] = sample(rng); return samples; }
@Override protected MultivariateGaussian[] createGaussians(int ngauss, int ndims) { final MultivariateGaussian[] arr = new MultivariateGaussian[ngauss]; for (int i = 0; i < ngauss; i++) { arr[i] = new SphericalMultivariateGaussian(ndims); } return arr; }
@Override public double[][] sample(int count, Random rng) { final double[][] samples = new double[count][]; for (int i = 0; i < count; i++) samples[i] = sample(rng); return samples; }
@Override public double[] estimateLogProbability(double[][] x) { final double[] lps = new double[x.length]; for (int i = 0; i < x.length; i++) lps[i] = estimateLogProbability(x[i]); return lps; } }
@Override public double estimateLogProbability(double[] sample) { return estimateLogProbability(new double[][] { sample })[0]; }
@Override public double[] sample(Random rng) { return sample(1, rng)[0]; }
@Override public String toString() { String s = "LocalHistogram[\n"; for (int y=0; y<blocks_y; y++) for (int x=0; x<blocks_x; x++) s += "\t(" + x + ", " + y + ") = " + histograms[y][x].toString() + "\n"; s += "]\n"; return s; }
/** * Construct with the given number of bins per dimension * * @param nbins * the number of bins in each dimension for the histograms */ public HistogramModel(int... nbins) { super(nbins.length); assert (nbins.length > 0); histogram = new MultidimensionalHistogram(nbins); }
@Override final void normalise(Histogram h, int blockArea) { h.normaliseL1(); } },
@Override protected float classifyPixel(Float[] pix) { return (float) gauss.estimateProbability(pix); }
@Override public String toString() { return histogram.toString(); }
@Override public String toString() { return histogram.toString(); }