@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 111972721: // value return ((QuantileResult) bean).getValue(); case 1943391143: // indices return ((QuantileResult) bean).getIndices(); case 1230441723: // weights return ((QuantileResult) bean).getWeights(); } return super.propertyGet(bean, propertyName, quiet); }
public void es_details() { double[] level = {0.98, 0.981, 0.9811, 0.97}; for (int i = 0; i < level.length; i++) { double es = METHOD.expectedShortfallFromUnsorted(level[i], DATA_123); QuantileResult r = METHOD.expectedShortfallDetailsFromUnsorted(level[i], DATA_123); assertEquals(r.getValue(), es, TOLERANCE_QUANTILE); assertEquals(r.getIndices().length, r.getWeights().size()); double qExpected = 0.0; for (int j = 0; j < r.getIndices().length; j++) { // Recompute ES from details qExpected += DATA_123.get(r.getIndices()[j]) * r.getWeights().get(j); } assertEquals(qExpected, es, TOLERANCE_QUANTILE); } }
public void quantile_details() { double[] level = {0.98, 0.981, 0.9811, 0.97}; for (int i = 0; i < level.length; i++) { double q = METHOD.quantileFromUnsorted(level[i], DATA_123); QuantileResult r = METHOD.quantileDetailsFromUnsorted(level[i], DATA_123); assertEquals(r.getValue(), q, TOLERANCE_QUANTILE); assertEquals(r.getIndices().length, r.getWeights().size()); double qExpected = 0.0; for (int j = 0; j < r.getIndices().length; j++) { // Recompute quantile from details qExpected += DATA_123.get(r.getIndices()[j]) * r.getWeights().get(j); } assertEquals(qExpected, q, TOLERANCE_QUANTILE); } }
double expectedValueAbove = 0d; double sumWeightsAbove = 0d; for (int i = 0; i < quantileAbove.getIndices().length; i++) { expectedValueAbove += UNSORTED_100.get(quantileAbove.getIndices()[i]) * quantileAbove.getWeights().get(i); sumWeightsAbove += quantileAbove.getWeights().get(i); assertEquals(quantileAbove.getIndices().length, quantileAbove.getWeights().size()); assertEquals(sumWeightsAbove, 1d, TOL); assertEquals(quantileAbove.getValue(), expectedValueAbove, TOL); double expectedValueNearest = 0d; double sumWeightsNearest = 0d; for (int i = 0; i < quantileNearest.getIndices().length; i++) { expectedValueNearest += UNSORTED_100.get(quantileNearest.getIndices()[i]) * quantileNearest.getWeights().get(i); sumWeightsNearest += quantileNearest.getWeights().get(i); assertEquals(quantileNearest.getIndices().length, quantileNearest.getWeights().size()); assertEquals(sumWeightsNearest, 1d, TOL); assertEquals(quantileNearest.getValue(), expectedValueNearest, TOL); double expectedValueSample = 0d; double sumWeightsSample = 0d; for (int i = 0; i < quantileSample.getIndices().length; i++) { expectedValueSample += UNSORTED_100.get(quantileSample.getIndices()[i]) * quantileSample.getWeights().get(i); sumWeightsSample += quantileSample.getWeights().get(i); assertEquals(quantileSample.getIndices().length, quantileSample.getWeights().size()); assertEquals(sumWeightsSample, 1d, TOL); assertEquals(quantileSample.getValue(), expectedValueSample, TOL);
double expectedValueAbove = 0d; double sumWeightsAbove = 0d; for (int i = 0; i < esAbove.getIndices().length; i++) { expectedValueAbove += UNSORTED_100.get(esAbove.getIndices()[i]) * esAbove.getWeights().get(i); sumWeightsAbove += esAbove.getWeights().get(i); assertEquals(esAbove.getIndices().length, esAbove.getWeights().size()); assertEquals(sumWeightsAbove, 1d, TOL); assertEquals(esAbove.getValue(), expectedValueAbove, TOL); double expectedValueNearest = 0d; double sumWeightsNearest = 0d; for (int i = 0; i < esNearest.getIndices().length; i++) { expectedValueNearest += UNSORTED_100.get(esNearest.getIndices()[i]) * esNearest.getWeights().get(i); sumWeightsNearest += esNearest.getWeights().get(i); assertEquals(esNearest.getIndices().length, esNearest.getWeights().size()); assertEquals(sumWeightsNearest, 1d, TOL); assertEquals(esNearest.getValue(), expectedValueNearest, TOL); double expectedValueSample = 0d; double sumWeightsSample = 0d; for (int i = 0; i < esSample.getIndices().length; i++) { expectedValueSample += UNSORTED_100.get(esSample.getIndices()[i]) * esSample.getWeights().get(i); sumWeightsSample += esSample.getWeights().get(i); assertEquals(esSample.getIndices().length, esSample.getWeights().size()); assertEquals(sumWeightsSample, 1d, TOL); assertEquals(esSample.getValue(), expectedValueSample, TOL);