HistogramVisual: add support for quantiles

This commit is contained in:
Nelson Ray 2012-11-05 14:33:15 -08:00
parent 88a3fb842c
commit 0a42f18cc3
3 changed files with 9 additions and 1 deletions

View File

@ -135,7 +135,7 @@ public class Histogram
public HistogramVisual asVisual() { public HistogramVisual asVisual() {
float[] visualCounts = new float[bins.length - 2]; float[] visualCounts = new float[bins.length - 2];
for(int i = 0; i < visualCounts.length; ++i) visualCounts[i] = (float)bins[i + 1]; for(int i = 0; i < visualCounts.length; ++i) visualCounts[i] = (float)bins[i + 1];
return new HistogramVisual(breaks, visualCounts, min, max); return new HistogramVisual(breaks, visualCounts, new float[]{}, min, max);
} }
public static Histogram fromBytes(byte[] bytes) { public static Histogram fromBytes(byte[] bytes) {

View File

@ -29,6 +29,7 @@ public class HistogramVisual
{ {
@JsonProperty final public double[] breaks; @JsonProperty final public double[] breaks;
@JsonProperty final public double[] counts; @JsonProperty final public double[] counts;
@JsonProperty final public double[] quantiles;
@JsonProperty final double min; @JsonProperty final double min;
@JsonProperty final double max; @JsonProperty final double max;
@ -36,6 +37,7 @@ public class HistogramVisual
public HistogramVisual( public HistogramVisual(
@JsonProperty double[] breaks, @JsonProperty double[] breaks,
@JsonProperty double[] counts, @JsonProperty double[] counts,
@JsonProperty double[] quantiles,
@JsonProperty double min, @JsonProperty double min,
@JsonProperty double max @JsonProperty double max
) )
@ -46,6 +48,7 @@ public class HistogramVisual
this.breaks = breaks; this.breaks = breaks;
this.counts = counts; this.counts = counts;
this.quantiles = quantiles;
this.min = min; this.min = min;
this.max = max; this.max = max;
} }
@ -53,6 +56,7 @@ public class HistogramVisual
public HistogramVisual( public HistogramVisual(
float[] breaks, float[] breaks,
float[] counts, float[] counts,
float[] quantiles,
float min, float min,
float max float max
) )
@ -63,8 +67,10 @@ public class HistogramVisual
this.breaks = new double[breaks.length]; this.breaks = new double[breaks.length];
this.counts = new double[counts.length]; this.counts = new double[counts.length];
this.quantiles = new double[quantiles.length];
for(int i = 0; i < breaks.length; ++i) this.breaks[i] = breaks[i]; for(int i = 0; i < breaks.length; ++i) this.breaks[i] = breaks[i];
for(int i = 0; i < counts.length; ++i) this.counts[i] = counts[i]; for(int i = 0; i < counts.length; ++i) this.counts[i] = counts[i];
for(int i = 0; i < quantiles.length; ++i) this.quantiles[i] = quantiles[i];
this.min = min; this.min = min;
this.max = max; this.max = max;
} }
@ -76,6 +82,7 @@ public class HistogramVisual
"counts=" + Arrays.toString(counts) + "counts=" + Arrays.toString(counts) +
", breaks=" + Arrays.toString(breaks) + ", breaks=" + Arrays.toString(breaks) +
", min=" + min + ", min=" + min +
", quantiles=" + Arrays.toString(quantiles) +
", max=" + max + ", max=" + max +
'}'; '}';
} }

View File

@ -68,6 +68,7 @@ public class HistogramTest
Map<String,Object> expectedObj = Maps.newLinkedHashMap(); Map<String,Object> expectedObj = Maps.newLinkedHashMap();
expectedObj.put("breaks", Arrays.asList(visualBreaks)); expectedObj.put("breaks", Arrays.asList(visualBreaks));
expectedObj.put("counts", Arrays.asList(visualCounts)); expectedObj.put("counts", Arrays.asList(visualCounts));
expectedObj.put("quantiles", Arrays.asList(new Double[]{}));
expectedObj.put("min", -1.0); expectedObj.put("min", -1.0);
expectedObj.put("max", 1.0); expectedObj.put("max", 1.0);