Example #1
0
  public static void main(String args[]) {
    Bandwidth np;
    boolean sending = false;
    if (args.length != 4) usage();

    if (args[0].equals("send")) sending = true;
    MSG_SIZE = Integer.decode(args[2]).intValue();
    WINDOW_SIZE = Integer.decode(args[3]).intValue();

    try {
      SandstormConfig cfg = new SandstormConfig();
      if (USE_NIO) cfg.putString("global.aSocket.provider", "NIO");
      Sandstorm ss = new Sandstorm(cfg);

      System.err.println(
          "Bandwidth: message size="
              + MSG_SIZE
              + ", burst size="
              + WINDOW_SIZE
              + ", rx block="
              + BLOCKING_DEQUEUE);

      np = new Bandwidth(args[1], sending);
      np.setup();
      np.doIt();
      System.exit(0);

    } catch (Exception e) {
      if (VERBOSE) System.err.println("Bandwidth.main() got exception: " + e);
      if (VERBOSE) e.printStackTrace();
    }
  }
Example #2
0
  public boolean estimateDensity(
      double a[], int n, Kernel k, int ngrid, double h, double ax, double bx, double weight[]) {
    /*
       var P, r : integer;
           xa : TDoubleVector;        // size of ngrid
           c  : PBuffer;        // size of ngrid
           deltax : double;
           binx : TIntegerVector;  // size of n
           L : integer;
           kw,temp : PBuffer;    //size of 2*ngrid
           i : integer;
           tmpGrid : PBuffer;
           err : ext}ed;
           minErr : ext}ed;
    */
    FStep = 0;
    if (ax == bx) {
      return false;
    }
    Fmin = ax;
    Fmax = bx;
    Resolution = ngrid;
    FStep = (Fmax - Fmin) / ngrid;

    int ngrid2 = 2 * ngrid;
    if (h == 0) {
      h = Bandwidth.hns(a, n, k);
      if (h == 0) {
        return false;
      }
    }
    kernelH = h;
    double xa[] = new double[ngrid];
    Misc m = new Misc();
    m.linspace(ax, bx, ngrid, xa);

    FGrid = new double[ngrid];
    for (int i = 0; i < ngrid; i++) {
      FGrid[i] = 0.0;
    }
    double deltax = (bx - ax) / (ngrid - 1);
    int binx[] = new int[n];

    for (int i = 0; i < n; i++) {
      binx[i] = (int) Math.floor((a[i] - ax) / deltax);
      //              if (binx[i] >= ngrid) binx[i] = ngrid-1;

    }
    ;
    /*
           if weight <> nil then
             for i :=0 to n-1 do { // Loop over data points in x direction.
        c[binx[i]-1] := c[binx[i]-1] + weight[i]*(xa[binx[i]]-AD[i])/deltax;
        c[binx[i]] := c[binx[i]]+ weight[i]*(AD[i]-xa[binx[i]-1])/deltax;
             }
           else
    */
    for (int i = 0; i < n; i++) { // Loop over data points in x direction.
      if ((binx[i] + 1) < ngrid) {
        FGrid[binx[i]] = FGrid[binx[i]] + (xa[binx[i] + 1] - a[i]) / deltax;
        FGrid[binx[i] + 1] = FGrid[binx[i] + 1] + (a[i] - xa[binx[i]]) / deltax;
      }
    }
    ;

    binx = null;

    int L = Math.min((int) Math.floor(k.R * h * (ngrid - 1) / (bx - ax)), ngrid);

    double kw[] = new double[ngrid2];
    for (int i = 0; i < ngrid2; i++) {
      kw[i] = 0;
    }
    double temp[] = new double[L];
    for (int i = 0; i < L; i++) {
      temp[i] = k.getAmplitude((bx - ax) * i / ((ngrid - 1) * h)) / (n * h);
    }
    for (int i = ngrid; i < ngrid + L; i++) {
      kw[i] = temp[i - ngrid];
    }
    for (int i = ngrid - L; i < ngrid; i++) {
      kw[i] = temp[ngrid - i - 1];
    }
    temp = null;
    m.fftshift(kw, ngrid2);
    m = null;

    double tmpGrid[] = new double[ngrid2];
    for (int i = 0; i < ngrid; i++) {
      tmpGrid[i] = FGrid[i];
    }
    for (int i = ngrid; i < ngrid2; i++) {
      tmpGrid[i] = 0;
    }
    FFT fft = new FFT();
    fft.convolution(tmpGrid, ngrid2, kw, ngrid2);
    fft = null;

    for (int i = 0; i < ngrid; i++) {
      if (tmpGrid[i] < 0) {
        FGrid[i] = 0;
      } else {
        FGrid[i] = tmpGrid[i];
        /*
            for (int i = 0; i < ngrid2; i++) if (FGrid[i] < 0) FGrid[i] = 0;
                double err = 0;
                for (int i = 0; i < ngrid; i++)
                    err += Math.sqrt(tmpGrid[i]) + Math.sqrt(FGrid[i]);
                err *= FStep;
                double Ferr = 0;
                for (int i = 0; i < ngrid; i++)
                    Ferr += (tmpGrid[i] - FGrid[i])*(tmpGrid[i] - FGrid[i]);
                Ferr /= ngrid;
                Ferr += err;
        */
      }
    }
    tmpGrid = null;
    xa = null;
    kw = null;

    normalize();
    return true;
  }