/** * Compute the scale (value range) * * @param order Cluster order to process * @return Scale for value range of cluster order */ protected LinearScale computeScale(ClusterOrder order) { DoubleMinMax range = new DoubleMinMax(); // calculate range for(DBIDIter it = order.iter(); it.valid(); it.advance()) { final double reach = co.getReachability(it); if(reach < Double.POSITIVE_INFINITY) { range.put(reach); } } // Ensure we have a valid range if(!range.isValid()) { range.put(0.0); range.put(1.0); } return new LinearScale(range.getMin(), range.getMax()); }
/** * Compute the scale (value range) * * @param order Cluster order to process * @return Scale for value range of cluster order */ protected LinearScale computeScale(ClusterOrder order) { DoubleMinMax range = new DoubleMinMax(); // calculate range for(DBIDIter it = order.iter(); it.valid(); it.advance()) { final double reach = co.getReachability(it); if(reach < Double.POSITIVE_INFINITY) { range.put(reach); } } // Ensure we have a valid range if(!range.isValid()) { range.put(0.0); range.put(1.0); } return new LinearScale(range.getMin(), range.getMax()); }
/** * Note: this test tests an earlier bug with tiny arrays. Keep. */ @Test public void basic() { DoubleMinMax m = new DoubleMinMax(); m.put(0); m.put(new double[] {}); m.put(new double[] { 0 }); m.put(new double[] { -1, +2 }); m.put(new double[] { 0, 0, 0 }); assertEquals("Min wrong.", -1, m.getMin(), 0.); assertEquals("Max wrong.", +2, m.getMax(), 0.); assertEquals("Diff wrong.", 3, m.getDiff(), 0.); m.reset(); assertFalse(m.isValid()); m.put(0.); m.put(new DoubleMinMax(-1, 2)); assertEquals("Min wrong.", -1, m.getMin(), 0.); assertEquals("Max wrong.", +2, m.getMax(), 0.); m.put(new DoubleMinMax(-.5, 1)); assertEquals("Min wrong.", -1, m.getMin(), 0.); assertEquals("Max wrong.", +2, m.getMax(), 0.); double[] a = m.asDoubleArray(); assertEquals("Min wrong.", -1, a[0], 0.); assertEquals("Max wrong.", +2, a[1], 0.); } }