### Question:
KernelDensity implements UnivariateDistribution { public double pdf(double x){ if(x<quadPoints[0]-3*h) return 0; if(x>quadPoints[nPoints-1]+3*h) return 0; return densityFunction.value(x); } KernelDensity(double[] x);  KernelDensity(double[] x, double adjust);  KernelDensity(double[] x, double adjust, int nPoints);  KernelDensity(double[] x, KernelType kernelType, double adjust, int nPoints);  KernelDensity(double[] x, KernelType kernelType, BandwidthType bandwidthType, double adjust, int nPoints);  KernelDensity(double[] x, KernelType kernelType, BandwidthType bandwidthType, double adjust, int nPoints, int maxEvaluations);  KernelDensity(double[] x, double[] w, KernelType kernelType, BandwidthType bandwidthType, double adjust, int nPoints, int maxEvaluations); int numberOfParameters(); double bandwidth(); double mean(); double variance(); double sd(); double pdf(double x); double cdf(double x); double idf(final double p); double rand(); double logp(double x); double getSupportLowerBound(); double getSupportUpperBound(); double likelihood(double[] x); double loglikelihood(double[] x); double[] getPoints(); double[] getDensity(); @Override String toString(); public int maxEvaluations; }### Answer:
@Test public void densityTest3(){ System.out.println("Kernel density test 3"); try{ File f = FileUtils.toFile(this.getClass().getResource("/testdata/density-test-data.csv")); BufferedReader br = new BufferedReader(new FileReader(f)); String line = ""; String[] s = null; double[] x = new double[1000]; int row = 0; br.readLine(); while((line=br.readLine())!=null){ s = line.split(","); x[row] = Double.parseDouble(s[2]); row++; } br.close(); f = FileUtils.toFile(this.getClass().getResource("/testdata/density-test-results.csv")); br = new BufferedReader(new FileReader(f)); double[] p1 = new double[512]; double[] d1 = new double[512]; row = 0; br.readLine(); while((line=br.readLine())!=null){ s = line.split(","); p1[row] = Double.parseDouble(s[4]); d1[row] = Double.parseDouble(s[5]); row++; } br.close(); KernelDensity density = new KernelDensity(x); for(int i=0;i<512;i++){ Assert.assertEquals(" Density at point " + (i+1), d1[i], density.pdf(p1[i]), 1e-7); } }catch(IOException ex){ ex.printStackTrace(); } }