public KDTreeKNN(DenseMatrix matrix) throws IOException { this.matrix = matrix; this.allIds = matrix.getRowIds(); this.dimensions = matrix.getRow(allIds[0]).getNumCols(); }
public RandomProjectionKNNFinder(DenseMatrix matrix) throws IOException { this.matrix = matrix; this.ids = matrix.getRowIds(); this.dimensions = matrix.getRow(ids[0]).getNumCols(); }
public RandomProjectionKNNFinder(DenseMatrix matrix) throws IOException { this.matrix = matrix; this.ids = matrix.getRowIds(); this.dimensions = matrix.getRow(ids[0]).getNumCols(); }
public KDTreeKNN(DenseMatrix matrix) throws IOException { this.matrix = matrix; this.allIds = matrix.getRowIds(); this.dimensions = matrix.getRow(allIds[0]).getNumCols(); }
public LSHForestKNNFinder(DenseMatrix matrix) throws IOException { this.matrix = matrix; this.ids = matrix.getRowIds(); this.dimensions = matrix.getRow(ids[0]).getNumCols(); }
public LSHForestKNNFinder(DenseMatrix matrix) throws IOException { this.matrix = matrix; this.ids = matrix.getRowIds(); this.dimensions = matrix.getRow(ids[0]).getNumCols(); }
private double updateCenter() { if (members.isEmpty()) { delegate = null; return 0.0; } // Calculate a new centroid double center [] = new double[members.get(0).getNumCols()]; for (DenseMatrixRow m : members) { for (int i = 0; i < center.length; i++) { center[i] += m.getColValue(i); } } for (int i = 0; i < center.length; i++) { center[i] /= members.size(); } // Pick the best delegate. double compactness = 0.0; double mostSimilar = -10; for (DenseMatrixRow m : members) { double s = cosine(center, m); compactness += s; if (s > mostSimilar) { mostSimilar = s; delegate = m; } } return compactness / members.size(); }
static double cosine(DenseMatrixRow X, DenseMatrixRow Y) { if (X == null || Y == null) { return 0; } double xDotX = 0.0; double yDotY = 0.0; double xDotY = 0.0; for (int i = 0; i < X.getNumCols(); i++) { double x = X.getColValue(i); double y = Y.getColValue(i); xDotX += x * x; yDotY += y * y; xDotY += x * y; } if (xDotX * yDotY == 0) { return 0.0; } return xDotY / Math.sqrt(xDotX * yDotY); }
private double updateCenter() { if (members.isEmpty()) { delegate = null; return 0.0; } // Calculate a new centroid double center [] = new double[members.get(0).getNumCols()]; for (DenseMatrixRow m : members) { for (int i = 0; i < center.length; i++) { center[i] += m.getColValue(i); } } for (int i = 0; i < center.length; i++) { center[i] /= members.size(); } // Pick the best delegate. double compactness = 0.0; double mostSimilar = -10; for (DenseMatrixRow m : members) { double s = cosine(center, m); compactness += s; if (s > mostSimilar) { mostSimilar = s; delegate = m; } } return compactness / members.size(); }
static double cosine(DenseMatrixRow X, DenseMatrixRow Y) { if (X == null || Y == null) { return 0; } double xDotX = 0.0; double yDotY = 0.0; double xDotY = 0.0; for (int i = 0; i < X.getNumCols(); i++) { double x = X.getColValue(i); double y = Y.getColValue(i); xDotX += x * x; yDotY += y * y; xDotY += x * y; } if (xDotX * yDotY == 0) { return 0.0; } return xDotY / Math.sqrt(xDotX * yDotY); }