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; }
List<?> children = treeMatrix.getChildren(s.getObject()); for (Object child : children) { long count = treeMatrix.getChildCountRecursive(child); paintTreeRect(g, subChildCounts, x, y, width, height); } else { g.setColor(ColorUtil.fromObject(s.getObject())); g.fillRect(x + 1, y + 1, width - 1, height - 1); List<?> children = treeMatrix.getChildren(s.getObject()); for (Object child : children) { long count = treeMatrix.getChildCountRecursive(child); paintTreeRect(g, subChildCounts, x, y, w, height); } else { g.setColor(ColorUtil.fromObject(s.getObject())); g.fillRect(x + 1, y + 1, w - 1, height - 1); List<?> children = treeMatrix.getChildren(s.getObject()); for (Object child : children) { long count = treeMatrix.getChildCountRecursive(child); paintTreeRect(g, subChildCounts, x, y, width, h); } else { g.setColor(ColorUtil.fromObject(s.getObject())); g.fillRect(x + 1, y + 1, width - 1, h - 1);
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; } }
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; } }