AbstractVector.minus has a bug in the first if clause. Don't know if my fix or this one would do what is intended by the optimization:

   if (x instanceof RandomAccessSparseVector || x instanceof DenseVector) {
// TODO: if both are RandomAccess check the numNonDefault to determine which to iterate
     Vector result = x.clone();
     Iterator<Element> iter = iterateNonZero();
     while (iter.hasNext()) {
       Element e = iter.next();
       result.setQuick(e.index(), e.get() - result.getQuick(e.index()));
     }
     return result;




--- Begin Message ---
I think this is backwards:

   if (x instanceof RandomAccessSparseVector || x instanceof DenseVector) {
// TODO: if both are RandomAccess check the numNonDefault to determine which to iterate
     Vector result = x.clone();
     Iterator<Element> iter = iterateNonZero();
     while (iter.hasNext()) {
       Element e = iter.next();
       result.setQuick(e.index(), result.getQuick(e.index()) - e.get());
     }
     return result;

... indeed, if I reverse the subtraction then all is well in the display routines

   if (x instanceof RandomAccessSparseVector || x instanceof DenseVector) {
// TODO: if both are RandomAccess check the numNonDefault to determine which to iterate
     Vector result = this.clone();
     Iterator<Element> iter = x.iterateNonZero();
     while (iter.hasNext()) {
       Element e = iter.next();
       result.setQuick(e.index(), result.getQuick(e.index()) - e.get());
     }
     return result;






Robin Anil wrote:
Hi Jeff, Here is the display code for all the algorithmn. I was not getting concentric circles for Canopy clustering. I was wondering if you could take me through the code

I assume v is centre and dv is radius

so v - dv/2 is the x,y coordinates
and dv*2 is the width and height of the bounding box. ds is the scale.


Robin


public static void plotRectangle(Graphics2D g2, Vector v, Vector dv) {
    double[] flip = {1, -1};
Vector v2 = v.clone().assign(new DenseVector(flip), new TimesFunction());
    v2 = v2.minus(dv.divide(2));
    int h = size / 2;
    double x = v2.get(0) + h;
    double y = v2.get(1) + h;
    g2.draw(new Rectangle2D.Double(x * ds, y * ds, dv.get(0)
* ds,
        dv.get(1) * ds));
  }
/**
   * Draw an ellipse on the graphics context
* * @param g2
   *          a Graphics2D context
   * @param v
   *          a Vector of ellipse center
   * @param dv
   *          a Vector of ellipse dimensions
   */
  public static void plotEllipse(Graphics2D g2, Vector v, Vector dv) {
    double[] flip = {1, -1};
Vector v2 = v.clone().assign(new DenseVector(flip), new TimesFunction());
    v2 = v2.minus(dv.divide(2));
    int h = size / 2;
    double x = v2.get(0) + h;
    double y = v2.get(1) + h;
g2.draw(new Ellipse2D.Double(x * ds, y * ds, dv.get(0) * ds, dv.get(1) * ds));
  }

<<attachment: jeastman.vcf>>


--- End Message ---

Reply via email to