Skip to content

Commit

Permalink
More JavaDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
kno10 committed Sep 19, 2023
1 parent b2d34fd commit d449ee1
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ public void processNewResult(Object newResult) {
}
}

/**
* Process one visualization item
*
* @param item Item
*/
private void processItem(PlotItem item) {
// Descend into subitems
for(Iterator<PlotItem> iter = item.subitems.iterator(); iter.hasNext();) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,11 @@ public double[] get(T object) {
return v.clone();
}

/**
* Assert that the layout is consistent.
*
* @return true when consistent, assertion failure otherwise.
*/
private boolean assertConsistent() {
final int cols = widths.size(), rows = heights.size();
double wsum = 0.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class WeightedCanberraDistance extends AbstractNumberVectorDistance imple

/**
* Constructor.
*
* @param weights Weight array
*/
public WeightedCanberraDistance(double[] weights) {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@
* @since 0.5.0
*/
// TODO: implement SpatialDistance
public class SparseLPNormDistance implements PrimitiveDistance<SparseNumberVector>, Norm<SparseNumberVector> {
public class SparseLPNormDistance implements Norm<SparseNumberVector> {
/**
* Parameter and its inverse.
*/
private double p, invp;

/**
* Constructor.
*
* @param p Power parameter
*/
public SparseLPNormDistance(double p) {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class SubspaceLPNormDistance extends AbstractDimensionsSelectingDistance<
* Constructor.
*
* @param dimensions Selected dimensions
* @param p p value
* @param p power parameter
*/
public SubspaceLPNormDistance(double p, long[] dimensions) {
super(dimensions);
Expand All @@ -80,6 +80,13 @@ public double distance(NumberVector v1, NumberVector v2) {
return FastMath.pow(sqrDist, 1. / p);
}

/**
* Min distance to a bounding box
*
* @param mbr Bounding box
* @param v Vector
* @return lower bound of distance
*/
protected double minDistObject(SpatialComparable mbr, NumberVector v) {
double sqrDist = 0;
for(int d = BitsUtil.nextSetBit(dimensions, 0); d >= 0; d = BitsUtil.nextSetBit(dimensions, d + 1)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ else if(ks == p - 1) {
}
}

/**
* Generate U
*
* @param nu limit
* @param nct start
*/
private void generateU(int nu, int nct) {
for(int j = nct; j < nu; j++) {
for(int i = 0; i < m; i++) {
Expand All @@ -254,13 +260,14 @@ private void generateU(int nu, int nct) {
}
for(int k = nct - 1; k >= 0; k--) {
if(s[k] != 0.0) {
final double[] U_k = U[k];
for(int j = k + 1; j < nu; j++) {
double t = 0;
for(int i = k; i < m; i++) {
final double[] Ui = U[i];
t += Ui[k] * Ui[j];
}
t /= -U[k][k];
t /= -U_k[k];
for(int i = k; i < m; i++) {
final double[] Ui = U[i];
Ui[j] += t * Ui[k];
Expand All @@ -270,7 +277,7 @@ private void generateU(int nu, int nct) {
final double[] Ui = U[i];
Ui[k] = -Ui[k];
}
U[k][k] = 1.0 + U[k][k];
U_k[k] = 1.0 + U_k[k];
for(int i = 0; i < k - 1; i++) {
U[i][k] = 0.0;
}
Expand All @@ -284,6 +291,13 @@ private void generateU(int nu, int nct) {
}
}

/**
* Generate V
*
* @param nu limit
* @param e Vector
* @param nrt limit
*/
private void generateV(int nu, double[] e, int nrt) {
for(int k = n - 1; k >= 0; k--) {
if((k < nrt) && (e[k] != 0.0)) {
Expand All @@ -307,6 +321,14 @@ private void generateV(int nu, double[] e, int nrt) {
}
}

/**
* Deflate
*
* @param e Vector
* @param p Index
* @param k Index
* @param wantv Update V
*/
private void deflate(double[] e, int p, int k, boolean wantv) {
double f = e[p - 2];
e[p - 2] = 0.0;
Expand All @@ -329,6 +351,14 @@ private void deflate(double[] e, int p, int k, boolean wantv) {
}
}

/**
* Split
*
* @param e Vector
* @param p Index
* @param k Index
* @param wantu Update U
*/
private void split(double[] e, int p, int k, boolean wantu) {
double f = e[k - 1];
e[k - 1] = 0.0;
Expand All @@ -349,6 +379,15 @@ private void split(double[] e, int p, int k, boolean wantu) {
}
}

/**
* Perform a Q-R-Step
*
* @param e Vector
* @param p index
* @param k index
* @param wantu Update U
* @param wantv Update V
*/
private void qrStep(double[] e, int p, int k, boolean wantu, boolean wantv) {
// Calculate the shift.
double scale = Math.max(Math.max(Math.max(Math.max(Math.abs(s[p - 1]), Math.abs(s[p - 2])), Math.abs(e[p - 2])), Math.abs(s[k])), Math.abs(e[k]));
Expand Down Expand Up @@ -406,6 +445,15 @@ private void qrStep(double[] e, int p, int k, boolean wantu, boolean wantv) {
e[p - 2] = f;
}

/**
* Convergence step for a subproblem
*
* @param k Current vector
* @param pp Remaining
* @param wantu Update U
* @param wantv Update V
* @return Number of values
*/
private int convergence(int k, int pp, boolean wantu, boolean wantv) {
// Make the singular values positive.
if(s[k] <= 0.0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,16 @@ private void adjustApproximatedKNNDistances(MkCoPEntry entry, Map<DBID, KNNList>
entry.setConservativeKnnDistanceApproximation(approx);
}

/*
/**
* auxiliary function for approxKdist methods.
*
* @param k0 Starting k
* @param kmax Maximum k
* @param logk log of ks
* @param log_kDist log of distances to k nearest neighbors
* @param m slope
* @param t intercept
* @return deviation
*/
private double ssqerr(int k0, int kmax, double[] logk, double[] log_kDist, double m, double t) {
int k = kmax - k0;
Expand All @@ -324,8 +332,18 @@ private double ssqerr(int k0, int kmax, double[] logk, double[] log_kDist, doubl
return result;
}

/*
* auxiliary function for approxKdist methods.
/**
* Auxiliary function for approxKdist methods.
*
* @param k0 Starting k
* @param kmax Maximum k
* @param sumx linear sum
* @param sumx2 sum of squares
* @param xp x power
* @param yp y power
* @param sumxy sum of x times y
* @param sumy linear sum of y
* @return slope
*/
private double optimize(int k0, int kmax, double sumx, double sumx2, double xp, double yp, double sumxy, double sumy) {
int k = kmax - k0 + 1;
Expand Down Expand Up @@ -443,10 +461,14 @@ private void approximateKnnDistances(MkCoPLeafEntry entry, KNNList knnDistances)
/**
* Approximates the lower hull.
*
* @param convexHull
* @param log_kDist
* @param sum_log_kDist
* @param sum_log_k_kDist
* @param convexHull Convex hull
* @param log_k logs of the k values
* @param sum_log_k sum of the logs of the k values
* @param sum_log_k2 sum of the log(k)²
* @param log_kDist logs of the distances to the knn
* @param sum_log_kDist sum of the log distances
* @param sum_log_k_kDist sum of log(k) * log(d)
* @return Approximation line
*/
private ApproximationLine approximateLowerHull(ConvexHull convexHull, double[] log_k, double sum_log_k, double sum_log_k2, double[] log_kDist, double sum_log_kDist, double sum_log_k_kDist) {
// StringBuilder msg = new StringBuilder(1000);
Expand Down Expand Up @@ -500,6 +522,14 @@ private ApproximationLine approximateLowerHull(ConvexHull convexHull, double[] l
return new ApproximationLine(k_0, low_m, low_t);
}

/**
* Approximate the upper hull
*
* @param convexHull convex hull
* @param log_k log of k
* @param log_kDist log of kdist
* @return Approximation line
*/
private ApproximationLine approximateUpperHull(ConvexHull convexHull, double[] log_k, double[] log_kDist) {
StringBuilder msg = LOG.isDebugging() ? new StringBuilder(1000) : null;

Expand Down Expand Up @@ -548,6 +578,18 @@ private ApproximationLine approximateUpperHull(ConvexHull convexHull, double[] l
return approx;
}

/**
* Approximate the upper hull, as in the paper
*
* @param convexHull Convex hull
* @param log_k logs of the k values
* @param sum_log_k sum of the logs of the k values
* @param sum_log_k2 sum of the log(k)²
* @param log_kDist logs of the distances to the knn
* @param sum_log_kDist sum of the log distances
* @param sum_log_k_kDist sum of log(k) * log(d)
* @return Approximation line
*/
private ApproximationLine approximateUpperHullPaper(ConvexHull convexHull, double[] log_k, double sum_log_k, double sum_log_k2, double[] log_kDist, double sum_log_kDist, double sum_log_k_kDist) {
StringBuilder msg = LOG.isDebugging() ? new StringBuilder(1000) : null;

Expand Down Expand Up @@ -635,6 +677,18 @@ else if(!lessThanPre) {
return null;
}

/**
* Approximate the upper hull
*
* @param convexHull Convex hull
* @param log_k logs of the k values
* @param sum_log_k sum of the logs of the k values
* @param sum_log_k2 sum of the log(k)²
* @param log_kDist logs of the distances to the knn
* @param sum_log_kDist sum of the log distances
* @param sum_log_k_kDist sum of log(k) * log(d)
* @return Approximation line
*/
// TODO: cleanup.
@SuppressWarnings("unused")
private ApproximationLine approximateUpperHullOld(ConvexHull convexHull, double[] log_k, double sum_log_k, double sum_log_k2, double[] log_kDist, double sum_log_kDist, double sum_log_k_kDist) {
Expand Down Expand Up @@ -684,45 +738,22 @@ private ApproximationLine approximateUpperHullOld(ConvexHull convexHull, double[
return new ApproximationLine(k_0, upp_m, upp_t);
}

/**
* Creates a new leaf node with the specified capacity.
*
* @return a new leaf node
*/
@Override
protected MkCoPTreeNode<O> createNewLeafNode() {
return new MkCoPTreeNode<>(leafCapacity, true);
}

/**
* Creates a new directory node with the specified capacity.
*
* @return a new directory node
*/
@Override
protected MkCoPTreeNode<O> createNewDirectoryNode() {
return new MkCoPTreeNode<>(dirCapacity, false);
}

/**
* Creates a new directory entry representing the specified node.
*
* @param node the node to be represented by the new entry
* @param routingObjectID the id of the routing object of the node
* @param parentDistance the distance from the routing object of the node to
* the routing object of the parent node
*/
@Override
protected MkCoPEntry createNewDirectoryEntry(MkCoPTreeNode<O> node, DBID routingObjectID, double parentDistance) {
return new MkCoPDirectoryEntry(routingObjectID, parentDistance, node.getPageID(), node.coveringRadiusFromEntries(routingObjectID, this), null);
// node.conservativeKnnDistanceApproximation(k_max));
}

/**
* Creates an entry representing the root node.
*
* @return an entry representing the root node
*/
@Override
protected MkCoPEntry createRootEntry() {
return new MkCoPDirectoryEntry(null, 0., 0, 0., null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,15 @@ protected void bulkLoad(List<RdKNNEntry> entries) {
doExtraIntegrityChecks();
}

public DoubleDBIDList reverseKNNQuery(DBID oid, int k, SpatialPrimitiveDistance<? super O> distance) {
/**
* Reverse k nearest neighbor query.
*
* @param oid Query object
* @param k Number of forward neighbors
* @param distance Distance function
* @return Reverse k nearest neighbors
*/
public DoubleDBIDList reverseKNNQuery(DBIDRef oid, int k, SpatialPrimitiveDistance<? super O> distance) {
checkDistance(distance);
if(k > settings.k_max) {
throw new IllegalArgumentException("Parameter k is not supported, k > k_max: " + k + " > " + settings.k_max);
Expand Down Expand Up @@ -327,7 +335,7 @@ private void preInsert(RdKNNEntry q, RdKNNEntry nodeEntry, KNNHeap knns_q) {
* @param oid the id of the object for which the rknn query is performed
* @param result the list containing the query results
*/
private void doReverseKNN(RdKNNNode node, DBID oid, ModifiableDoubleDBIDList result) {
private void doReverseKNN(RdKNNNode node, DBIDRef oid, ModifiableDoubleDBIDList result) {
if(node.isLeaf()) {
for(int i = 0; i < node.getNumEntries(); i++) {
RdKNNLeafEntry entry = (RdKNNLeafEntry) node.getEntry(i);
Expand Down Expand Up @@ -424,7 +432,6 @@ protected RdKNNEntry createRootEntry() {
* Throws an IllegalArgumentException if the specified distance function is
* not an instance of the distance function used by this index.
*
* @throws IllegalArgumentException
* @param distance the distance function to be checked
*/
private void checkDistance(SpatialPrimitiveDistance<? super O> distance) {
Expand All @@ -433,6 +440,12 @@ private void checkDistance(SpatialPrimitiveDistance<? super O> distance) {
}
}

/**
* Create a new leaf node.
*
* @param id Object id
* @return new leaf node
*/
protected RdKNNLeafEntry createNewLeafEntry(DBID id) {
return new RdKNNLeafEntry(id, relation.get(id), Double.NaN);
}
Expand Down
Loading

0 comments on commit d449ee1

Please sign in to comment.