Samples the 4 grid points around v and performs bilinear interpolation

@param v_x Grid coordinate x-axis, undistorted
@param v_y Grid coordinate y-axis, undistorted
@param deformed Distorted grid coordinate in image pixels
762642
void interpolateDeformedPoint(float v_x , float v_y , Point2D_F32 deformed ) {

		// sample the closest point and x+1,y+1
		int x0 = (int)v_x;
		int y0 = (int)v_y;
		int x1 = x0+1;
		int y1 = y0+1;

		// make sure the 4 sample points are in bounds
		if( x1 >= gridCols )
			x1 = gridCols-1;
		if( y1 >= gridRows )
			y1 = gridRows-1;

		// weight along each axis
		float ax = v_x - x0;
		float ay = v_y - y0;

		// bilinear weight for each sample point
		float w00 = (1.0f - ax) * (1.0f - ay);
		float w01 = ax * (1.0f - ay);
		float w11 = ax * ay;
		float w10 = (1.0f - ax) * ay;

		// apply weights to each sample point
		Point2D_F32 d00 = getGrid(y0,x0).deformed;
		Point2D_F32 d01 = getGrid(y0,x1).deformed;
		Point2D_F32 d10 = getGrid(y1,x0).deformed;
		Point2D_F32 d11 = getGrid(y1,x1).deformed;

		deformed.set(0,0);
		deformed.x += w00 * d00.x;
		deformed.x += w01 * d01.x;
		deformed.x += w11 * d11.x;
		deformed.x += w10 * d10.x;

		deformed.y += w00 * d00.y;
		deformed.y += w01 * d01.y;
		deformed.y += w11 * d11.y;
		deformed.y += w10 * d10.y;
	}
749481
public int[] gridAt( double x, double y ) {
        if (isInRaster(x, y)) {
            GridGeometry2D gridGeometry = getGridGeometry();
            int[] colRowFromCoordinate = CoverageUtilities.colRowFromCoordinate(new Coordinate(x, y), gridGeometry, null);
            return colRowFromCoordinate;
        }
        return null;
    }
1166529
function pixelToTileCoords(x, y, v) {
         var ret = v || new me.Vector2d();
         return ret.set(x / this.tilewidth, y / this.tileheight);
       }
910250
function tileToPixelCoords(q, r, v) {
         var x, y;
         var ret = v || new me.Vector2d();

         if (this.staggeraxis === "x") {
           //flat top
           x = q * this.columnwidth;

           if (this.staggerindex === "odd") {
             y = r * (this.tileheight + this.sidelengthy);
             y = y + this.rowheight * (q & 1);
           } else {
             y = r * (this.tileheight + this.sidelengthy);
             y = y + this.rowheight * (1 - (q & 1));
           }
         } else {
           //pointy top
           y = r * this.rowheight;

           if (this.staggerindex === "odd") {
             x = q * (this.tilewidth + this.sidelengthx);
             x = x + this.columnwidth * (r & 1);
           } else {
             x = q * (this.tilewidth + this.sidelengthx);
             x = x + this.columnwidth * (1 - (r & 1));
           }
         }

         return ret.set(x, y);
       }
261661
function draw(){
    
    ctx.clearRect(0,0,WIDTH,HEIGHT);
    
    var netx = new convnetjs.Vol(1,1,2);
    // draw decisions in the grid
    var density= 5.0;
    var gridstep = 2;
    var gridx = [];
    var gridy = [];
    var gridl = []; 
    for(var x=0.0, cx=0; x<=WIDTH; x+= density, cx++) {
      for(var y=0.0, cy=0; y<=HEIGHT; y+= density, cy++) {
        //var dec= svm.marginOne([(x-WIDTH/2)/ss, (y-HEIGHT/2)/ss]);
        netx.w[0] = (x-WIDTH/2)/ss;
        netx.w[1] = (y-HEIGHT/2)/ss;
        var a = net.forward(netx, false);
        
        if(a.w[0] > a.w[1]) ctx.fillStyle = 'rgb(250, 150, 150)';
        else ctx.fillStyle = 'rgb(150, 250, 150)';

        //ctx.fillStyle = 'rgb(150,' + Math.floor(a.w[0]*105)+150 + ',150)';
        //ctx.fillStyle = 'rgb(' + Math.floor(a.w[0]*255) + ',' + Math.floor(a.w[1]*255) + ', 0)';
        ctx.fillRect(x-density/2-1, y-density/2-1, density+2, density+2);

        if(cx%gridstep === 0 && cy%gridstep===0) {
          // record the transformation information
          var xt = net.layers[lix].out_act.w[d0]; // in screen coords
          var yt = net.layers[lix].out_act.w[d1]; // in screen coords
          gridx.push(xt);
          gridy.push(yt);
          gridl.push(a.w[0] > a.w[1]); // remember final label as well
        }
      }
    }

    // draw axes
    ctx.beginPath();
    ctx.strokeStyle = 'rgb(50,50,50)';
    ctx.lineWidth = 1;
    ctx.moveTo(0, HEIGHT/2);
    ctx.lineTo(WIDTH, HEIGHT/2);
    ctx.moveTo(WIDTH/2, 0);
    ctx.lineTo(WIDTH/2, HEIGHT);
    ctx.stroke();

    // draw representation transformation axes for two neurons at some layer
    var mmx = cnnutil.maxmin(gridx);
    var mmy = cnnutil.maxmin(gridy);
    visctx.clearRect(0,0,visWIDTH,visHEIGHT);
    visctx.strokeStyle = 'rgb(0, 0, 0)';
    var n = Math.floor(Math.sqrt(gridx.length)); // size of grid. Should be fine?
    var ng = gridx.length;
    var c = 0; // counter
    visctx.beginPath() 
    for(var x=0;x<n;x++) {
      for(var y=0;y<n;y++) {

        // down
        var ix1 = x*n+y;
        var ix2 = x*n+y+1;
        if(ix1 >= 0 && ix2 >= 0 && ix1 < ng && ix2 < ng && y<n-1) { // check oob
          var xraw = gridx[ix1];
          xraw1 = visWIDTH*(gridx[ix1] - mmx.minv)/mmx.dv;
          yraw1 = visHEIGHT*(gridy[ix1] - mmy.minv)/mmy.dv;
          xraw2 = visWIDTH*(gridx[ix2] - mmx.minv)/mmx.dv;
          yraw2 = visHEIGHT*(gridy[ix2] - mmy.minv)/mmy.dv;
          visctx.moveTo(xraw1, yraw1);
          visctx.lineTo(xraw2, yraw2);
        }

        // and draw its color
        if(gridl[ix1]) visctx.fillStyle = 'rgb(250, 150, 150)';
        else visctx.fillStyle = 'rgb(150, 250, 150)';
        var sz = density * gridstep;
        visctx.fillRect(xraw1-sz/2-1, yraw1-sz/2-1, sz+2, sz+2);

        // right
        var ix1 = (x+1)*n+y;
        var ix2 = x*n+y;
        if(ix1 >= 0 && ix2 >= 0 && ix1 < ng && ix2 < ng && x <n-1) { // check oob
          var xraw = gridx[ix1];
          xraw1 = visWIDTH*(gridx[ix1] - mmx.minv)/mmx.dv;
          yraw1 = visHEIGHT*(gridy[ix1] - mmy.minv)/mmy.dv;
          xraw2 = visWIDTH*(gridx[ix2] - mmx.minv)/mmx.dv;
          yraw2 = visHEIGHT*(gridy[ix2] - mmy.minv)/mmy.dv;
          visctx.moveTo(xraw1, yraw1);
          visctx.lineTo(xraw2, yraw2);
        }
 
      }
    }
    visctx.stroke();

    // draw datapoints.
    ctx.strokeStyle = 'rgb(0,0,0)';
    ctx.lineWidth = 1;
    for(var i=0;i<N;i++) {
      
      if(labels[i]==1) ctx.fillStyle = 'rgb(100,200,100)';
      else ctx.fillStyle = 'rgb(200,100,100)';
      
      drawCircle(data[i][0]*ss+WIDTH/2, data[i][1]*ss+HEIGHT/2, 5.0);

      // also draw transformed data points while we're at it
      netx.w[0] = data[i][0];
      netx.w[1] = data[i][1]
      var a = net.forward(netx, false);
      var xt = visWIDTH * (net.layers[lix].out_act.w[d0] - mmx.minv) / mmx.dv; // in screen coords
      var yt = visHEIGHT * (net.layers[lix].out_act.w[d1] - mmy.minv) / mmy.dv; // in screen coords
      if(labels[i]==1) visctx.fillStyle = 'rgb(100,200,100)';
      else visctx.fillStyle = 'rgb(200,100,100)';
      visctx.beginPath();
      visctx.arc(xt, yt, 5.0, 0, Math.PI*2, true); 
      visctx.closePath();
      visctx.stroke();
      visctx.fill();
    }
}
1045411
public double interpolate(double... x) {
        if (x.length != this.x[0].length) {
            throw new IllegalArgumentException(String.format("Invalid input vector size: %d, expected: %d", x.length, this.x[0].length));
        }

        int n = this.x.length;
        for (int i = 0; i < n; i++) {
            vstar[i] = variogram.f(rdist(x, this.x[i]));
        }
        vstar[n] = 1.0;

        double y = 0.0;
        for (int i = 0; i <= n; i++) {
            y += yvi[i] * vstar[i];
        }
        return y;
    }
123708
@Override
    public void learn(double[] x, double y) {
        if (x.length != p) {
            throw new IllegalArgumentException(String.format("Invalid input vector size: %d, expected: %d", x.length, p));
        }

        System.arraycopy(x, 0, x1, 0, p);
        double v = 1 + V.xax(x1);
        // If 1/v is NaN, then the update to V will no longer be invertible.
        // See https://en.wikipedia.org/wiki/Sherman%E2%80%93Morrison_formula#Statement
        if (Double.isNaN(1/v)){
            throw new IllegalStateException("The updated V matrix is no longer invertible.");
        }

        V.ax(x1, Vx);
        for (int j = 0; j <= p; j++) {
            for (int i = 0; i <= p; i++) {
                double tmp = V.get(i, j) - ((Vx[i] * Vx[j])/v);
                V.set(i, j, tmp/lambda);
            }
        }

        // V has been updated. Compute Vx again.
        V.ax(x1, Vx);
        
        double err = y - predict(x);
        for (int i = 0; i <= p; i++){
            w[i] += Vx[i] * err;
        }
    }
1160956
function(a,b,d){
	var o, dir;
	if(arguments.length == 3){
		Vec2D.apply(this,[a,b]);
		this.dir = d.getNormalized();
	} else if(arguments.length == 2){
		Vec2D.apply(this,[a]);
		this.dir = b.getNormalized();
	} else if(arguments.length === 0){
		Vec2D.apply(this);
		this.dir = Vec2D.Y_AXIS.copy();
	}
}
15253
public static void scale(GVRMesh mesh, float x, float y, float z) {
        final float [] vertices = mesh.getVertices();
        final int vsize = vertices.length;

        for (int i = 0; i < vsize; i += 3) {
            vertices[i]     *= x;
            vertices[i + 1] *= y;
            vertices[i + 2] *= z;
        }

        mesh.setVertices(vertices);
    }
1131446
private int pointToGridIdx(Grid grid, float x, float y, float z) {
        Vec3f size = grid.getSize();

        int idx = calcIndex(x, size.getX(), grid.getMin().getX(), grid.getDivision().getX());
        int idy = calcIndex(y, size.getY(), grid.getMin().getY(), grid.getDivision().getY());
        int idz = calcIndex(z, size.getZ(), grid.getMin().getZ(), grid.getDivision().getZ());

        return idx + grid.getDivision().getX() * (idy + grid.getDivision().getY() * idz);
    }
1307094
private void set(Point3d[] x, Point3d[] y) {
		this.x = x;
		this.y = y;
		rmsdCalculated = false;
		transformationCalculated = false;
	}
231929
public void render (Graphics2D gfx, float x, float y)
    {
        // nothing to do if we haven't been laid out
        if (_layouts == null) {
            log.warning(hashCode() + " Unlaid-out label asked to render", "text", _text
                        /*, "last", _invalidator */);
            return;
        }

        Color old = gfx.getColor();
        if (_textColor != null) {
            gfx.setColor(_textColor);
        }

        // We're going to do a couple things differently if we're antialiased
        RenderingHints hints = gfx.getRenderingHints();
        boolean antialiased = hints.containsKey(RenderingHints.KEY_ANTIALIASING) ||
            hints.containsKey(RenderingHints.KEY_TEXT_ANTIALIASING);

        // render our text
        for (int i = 0; i < _layouts.length; i++) {
            TextLayout layout = _layouts[i];
            Rectangle2D lbounds = _lbounds[i];
            y += layout.getAscent();

            float extra = (float)Math.floor(_size.width - getWidth(lbounds));
            float rx;
            switch (_align) {
            case -1: rx = x + (layout.isLeftToRight() ? 0 : extra); break;
            default:
            case LEFT: rx = x; break;
            case RIGHT: rx = x + extra; break;
            case CENTER: rx = x + extra/2; break;
            }

            // shift over any lines that start with a font that extends into negative x-land
            rx += _leaders[i];

//             System.out.println(i + " x: " + x + " y: " + y + " rx: " + rx + " a: " + _align +
//                                " width: " + _size.width + " lx: " + lbounds.getX() +
//                                " lwidth: " + getWidth(lbounds) + " extra: " + extra);

            Color textColor;

            if ((_style & OUTLINE) != 0) {
                // render the outline using the hacky, but much nicer than using "real" outlines
                // (via TextLayout.getOutline), method
                textColor = gfx.getColor();
                gfx.setColor(_alternateColor);
                _mainDraw = false;
                if (antialiased) {
                    // We need to fill in the actual spot we'll be drawing on top of if antialiased
                    layout.draw(gfx, rx + 1, y + 1);
                }
                layout.draw(gfx, rx, y);
                layout.draw(gfx, rx, y + 1);
                layout.draw(gfx, rx, y + 2);
                layout.draw(gfx, rx + 1, y);
                layout.draw(gfx, rx + 1, y + 2);
                layout.draw(gfx, rx + 2, y);
                layout.draw(gfx, rx + 2, y + 1);
                layout.draw(gfx, rx + 2, y + 2);
                _mainDraw = true;
                gfx.setColor(textColor);
                layout.draw(gfx, rx + 1, y + 1);
                if (antialiased) {
                    // If antialiased, draw a second time to make sure our letters are nice and
                    // solid looking on top of the outline
                    layout.draw(gfx, rx + 1, y + 1);
                }

            } else if ((_style & SHADOW) != 0) {
                textColor = gfx.getColor();
                gfx.setColor(_alternateColor);
                _mainDraw = false;
                layout.draw(gfx, rx, y + 1);
                _mainDraw = true;
                gfx.setColor(textColor);
                layout.draw(gfx, rx + 1, y);

            } else if ((_style & BOLD) != 0) {
                _mainDraw = false;
                layout.draw(gfx, rx, y);
                _mainDraw = true;
                layout.draw(gfx, rx + 1, y);

            } else {
                layout.draw(gfx, rx, y);
            }

            y += layout.getDescent() + layout.getLeading();
        }

        gfx.setColor(old);
    }
445743
private static void convolve(double[] xreal, double[] ximag, double[] yreal, double[] yimag, double[] outreal, double[] outimag) {
//        if (xreal.length != ximag.length || xreal.length != yreal.length || yreal.length != yimag.length || xreal.length != outreal.length || outreal.length != outimag.length)
//            throw new IllegalArgumentException("Mismatched lengths");

        int n = xreal.length;

        FFT(xreal, ximag);
        FFT(yreal, yimag);
        for (int i = 0; i < n; i++) {
            double temp = xreal[i] * yreal[i] - ximag[i] * yimag[i];
            ximag[i] = ximag[i] * yreal[i] + xreal[i] * yimag[i];
            xreal[i] = temp;
        }
        inverseTransform(xreal, ximag);

        // Scaling (because this FFT implementation omits it)
        for (int i = 0; i < n; i++) {
            outreal[i] = xreal[i] / n;
            outimag[i] = ximag[i] / n;
        }
    }
1295840
function(v) {

      // [0, v'] = Q * [0, v] * Q'

      // Q
      var w1 = this['w'];
      var x1 = this['x'];
      var y1 = this['y'];
      var z1 = this['z'];

      // [0, v]
      var w2 = 0;
      var x2 = v[0];
      var y2 = v[1];
      var z2 = v[2];

      // Q * [0, v]
      var w3 = /*w1 * w2*/ -x1 * x2 - y1 * y2 - z1 * z2;
      var x3 = w1 * x2 + /*x1 * w2 +*/ y1 * z2 - z1 * y2;
      var y3 = w1 * y2 + /*y1 * w2 +*/ z1 * x2 - x1 * z2;
      var z3 = w1 * z2 + /*z1 * w2 +*/ x1 * y2 - y1 * x2;

      var w4 = w3 * w1 + x3 * x1 + y3 * y1 + z3 * z1;
      var x4 = x3 * w1 - w3 * x1 - y3 * z1 + z3 * y1;
      var y4 = y3 * w1 - w3 * y1 - z3 * x1 + x3 * z1;
      var z4 = z3 * w1 - w3 * z1 - x3 * y1 + y3 * x1;

      return [x4, y4, z4];
    }
1068663
function (x, y) {
            if (this.indices.length === 0) {
                var points = this.points;
                var data = [];

                // flatten the points vector array
                for (var i = 0; i < points.length; i++) {
                    // XXX Optimize me
                    data.push(points[i].x);
                    data.push(points[i].y);
                }
                this.indices = earcut(data);
            }
            return this.indices;
        }
1296201
public Matrix4d getRepeatTransform(int x, int y){

		Matrix4d transform = new Matrix4d();
		transform.setIdentity();

		int[] iCounts = getAxisCounts(x);
		int[] jCounts = getAxisCounts(y);

		int[] counts = new int[iCounts.length];
		for (int k = 0; k < iCounts.length; k++)
			counts[k] = iCounts[k] - jCounts[k];

		for(int t = counts.length-1; t>=0; t--) {
			if(counts[t] == 0)
				continue;
			if (counts[t] > 0) {
				Matrix4d axis = new Matrix4d(axes.get(t).getOperator());
				for(int i=0;i<counts[t];i++)
					transform.mul(axis);
			} else if (counts[t] < 0) {
				Matrix4d axis = new Matrix4d(axes.get(t).getOperator());
				axis.invert();
				for(int i=0;i<counts[t];i++)
					transform.mul(axis);
			}
		}
		return transform;
	}
1139026
function (v) {
            var _vz = v.z || 0;
            return this._set((this.x < v.x) ? this.x : v.x, (this.y < v.y) ? this.y : v.y, (this.z < _vz) ? this.z : _vz);
        }