if (s.getComparable() > 1) { List<Sortable<Long, Object>> subChildCounts = new ArrayList<Sortable<Long, Object>>(); List<?> children = treeMatrix.getChildren(s.getObject()); for (Object child : children) { long count = treeMatrix.getChildCountRecursive(child); s = new Sortable<Long, Object>(1 + count, child); subChildCounts.add(s); paintTreeRect(g, subChildCounts, x, y, width, height); } else { g.setColor(ColorUtil.fromObject(s.getObject())); g.fillRect(x + 1, y + 1, width - 1, height - 1); long sum = 0; for (Sortable<Long, Object> s : childCounts) { sum += s.getComparable(); double factor = (double) s.getComparable() / (double) sum; if (width > height) { int w = (int) ((double) width * factor); if (s.getComparable() > 1) { List<Sortable<Long, Object>> subChildCounts = new ArrayList<Sortable<Long, Object>>(); List<?> children = treeMatrix.getChildren(s.getObject()); for (Object child : children) { long count = treeMatrix.getChildCountRecursive(child); s = new Sortable<Long, Object>(1 + count, child); subChildCounts.add(s);
public boolean equals(Object obj) { if (obj instanceof Sortable) { Sortable<?, ?> s = (Sortable<?, ?>) obj; Comparable<?> c = s.getComparable(); Object o = s.getObject(); if (comparable == null && c != null) { return false; } if (comparable.equals(c)) { return false; } if (object == null && o != null) { return false; } if (object.equals(o)) { return false; } return true; } return false; }
for (long r = 0; r < rowCount; r++) { BigDecimal c = m.getAsBigDecimal(r, column); rows.add(new Sortable<BigDecimal, Long>(c, r, true)); for (long r = 0; r < rowCount; r++) { BigInteger c = m.getAsBigInteger(r, column); rows.add(new Sortable<BigInteger, Long>(c, r, true)); for (long r = 0; r < rowCount; r++) { Double c = m.getAsDouble(r, column); rows.add(new Sortable<Double, Long>(c, r, true)); for (long r = 0; r < rowCount; r++) { Integer c = m.getAsInt(r, column); rows.add(new Sortable<Integer, Long>(c, r, true)); for (long r = 0; r < rowCount; r++) { Float c = m.getAsFloat(r, column); rows.add(new Sortable<Float, Long>(c, r, true)); for (long r = 0; r < rowCount; r++) { Character c = m.getAsChar(r, column); rows.add(new Sortable<Character, Long>(c, r, true)); for (long r = 0; r < rowCount; r++) { Byte c = m.getAsByte(r, column); rows.add(new Sortable<Byte, Long>(c, r, true)); for (long r = 0; r < rowCount; r++) {
private List<Sortable<Double, Matrix>> getSortedNeighbors(long... coordinates) { List<Sortable<Double, Matrix>> neighbors = new ArrayList<Sortable<Double, Matrix>>(); List<Integer> candidates = getCandidates(coordinates); for (int candidateRow : candidates) { double dist = distanceMatrix.getAsDouble(coordinates[ROW], candidateRow); Matrix candidate = getSource().selectRows(Ret.LINK, candidateRow); neighbors.add(new Sortable<Double, Matrix>(dist, candidate)); } Collections.sort(neighbors); return neighbors; }
public double getDouble(long... coordinates) { if (distanceMatrix == null) { distanceMatrix = getDistanceMatrix(); } double value = getSource().getAsDouble(coordinates); if (MathUtil.isNaNOrInfinite(value)) { List<Sortable<Double, Matrix>> sortedNeighbors = getSortedNeighbors(coordinates); double sum = 0; int count = 0; for (Sortable<Double, Matrix> s : sortedNeighbors) { sum += s.getObject().getAsDouble(0, coordinates[COLUMN]); if (++count == k) { break; } } return sum / count; } else { return value; } }
public void paintComponent(Graphics g) { Object root = treeMatrix.getRoot(); List<?> children = treeMatrix.getChildren(root); List<Sortable<Long, Object>> childCounts = new ArrayList<Sortable<Long, Object>>(); for (Object child : children) { long count = treeMatrix.getChildCountRecursive(child); Sortable<Long, Object> s = new Sortable<Long, Object>(1 + count, child); childCounts.add(s); } Collections.sort(childCounts); g.setColor(Color.black); g.fillRect(0, 0, getWidth(), getHeight()); paintTreeRect(g, childCounts, 0, 0, getWidth(), getHeight()); }
public Matrix predictOne(Matrix input) { List<Sortable<Double, Matrix>> bestResults = new FastArrayList<Sortable<Double, Matrix>>(); for (Sample s : dataSet) { Matrix reference = s.getAsMatrix(getInputLabel()); double distance = input.euklideanDistanceTo(reference, true); if (bestResults.size() < k) { bestResults.add(new Sortable<Double, Matrix>(distance, s .getAsMatrix(getTargetLabel()))); Collections.sort(bestResults); } else if (distance < bestResults.get(k - 1).getComparable()) { bestResults.remove(k - 1); bestResults.add(new Sortable<Double, Matrix>(distance, s .getAsMatrix(getTargetLabel()))); Collections.sort(bestResults); } } List<Matrix> results = new FastArrayList<Matrix>(); for (Sortable<Double, Matrix> s : bestResults) { results.add(s.getObject().toColumnVector(Ret.LINK)); } Matrix resultMatrix = Matrix.Factory.vertCat(results); Matrix mean = resultMatrix.mean(Ret.NEW, Matrix.ROW, true); return mean; } }