Esempio n. 1
0
  public void setXY(double x, double y) {
    // not validated
    // x and y between -1 and 1
    double sigmoidSteepness, sigmoidZero, baseLength;
    double sensitivity =
        1.1; // evaluated with set to 1.1: a sensitivity of 1 means the complete space of the button
             // is used. 2 means only the middle part is used, making it more sensitive and more
             // easy to get to extreme arousal (from a CHI perspective).
    if (!down) {
      p = x * sensitivity;
      d = y * sensitivity;
      baseLength = Math.max(Math.abs(p), Math.abs(d)); // MAX (P, D) base
      // baseLength=Math.sqrt(Math.pow(p,2)+Math.pow(d,2))/Math.sqrt(2.0); //euclid P,D base

      // now do the mapping to arousal.
      // Arousal is controlled simple by using a Sigmoid function based on length of PD vector
      sigmoidSteepness = 11;
      sigmoidZero = 8;
      a = 2 / (1 + Math.exp(-(sigmoidSteepness * baseLength - sigmoidZero))) - 1;
      a_base = a;
      // Arousal is controlled simply by using a quadratic function that has 0,0,0 as middle point,
      // then drops to -1, then to 1 based MIN (P,D) length (mimics better original linear)
      // sigmoidSteepness=6;
      // sigmoidZero=0.35;
      // a=sigmoidSteepness*Math.pow(Math.max(Math.abs(p),Math.abs(d))-sigmoidZero, 2)-1;

      p = (p > 1 ? 1 : (p < -1 ? -1 : p));
      d = (d > 1 ? 1 : (d < -1 ? -1 : d));
      a = (a > 1 ? 1 : (a < -1 ? -1 : a));

    } else {
      double tmp_p, tmp_d;
      tmp_p = x * sensitivity;
      tmp_d = y * sensitivity;
      baseLength = Math.max(Math.abs(tmp_p), Math.abs(tmp_d)); // MAX (P, D) base
      // baseLength=Math.sqrt(Math.pow(p,2)+Math.pow(d,2))/Math.sqrt(2.0); //euclid P,D base

      // now do the mapping to arousal.
      // Arousal is controlled simple by using a Sigmoid function based on length of PD vector
      sigmoidSteepness = 11;
      sigmoidZero = 8;
      // a=a_base-(d-tmp_d)+2/(1+Math.exp(-(sigmoidSteepness*baseLength-sigmoidZero)))-1;
      a = tmp_d;
      // Arousal is controlled simply by using a quadratic function that has 0,0,0 as middle point,
      // then drops to -1, then to 1 based MIN (P,D) length (mimics better original linear)
      // sigmoidSteepness=6;
      // sigmoidZero=0.35;
      // a=sigmoidSteepness*Math.pow(Math.max(Math.abs(p),Math.abs(d))-sigmoidZero, 2)-1;

      // p=(p>1?1:(p<-1?-1:p));
      // d=(d>1?1:(d<-1?-1:d));
      a = (a > 1 ? 1 : (a < -1 ? -1 : a));
    }
  }
Esempio n. 2
0
 protected void plotScatterDiagram() {
   // plot sample as one dimensional scatter plot and Gaussian
   double xmax = 5.;
   double xmin = -5.;
   DatanGraphics.openWorkstation(getClass().getName(), "E3Min_1.ps");
   DatanGraphics.setFormat(0., 0.);
   DatanGraphics.setWindowInComputingCoordinates(xmin, xmax, 0., .5);
   DatanGraphics.setViewportInWorldCoordinates(-.15, .9, .16, .86);
   DatanGraphics.setWindowInWorldCoordinates(-.414, 1., 0., 1.);
   DatanGraphics.setBigClippingWindow();
   DatanGraphics.chooseColor(2);
   DatanGraphics.drawFrame();
   DatanGraphics.drawScaleX("y");
   DatanGraphics.drawScaleY("f(y)");
   DatanGraphics.drawBoundary();
   double xpl[] = new double[2];
   double ypl[] = new double[2];
   // plot scatter diagram
   DatanGraphics.chooseColor(1);
   for (int i = 0; i < y.length; i++) {
     xpl[0] = y[i];
     xpl[1] = y[i];
     ypl[0] = 0.;
     ypl[0] = .1;
     DatanGraphics.drawPolyline(xpl, ypl);
   }
   // draw Gaussian corresponding to solution
   int npl = 100;
   xpl = new double[npl];
   ypl = new double[npl];
   double fact = 1. / (Math.sqrt(2. * Math.PI) * x.getElement(1));
   double dpl = (xmax - xmin) / (double) (npl - 1);
   for (int i = 0; i < npl; i++) {
     xpl[i] = xmin + (double) i * dpl;
     ypl[i] = fact * Math.exp(-.5 * Math.pow((xpl[i] - x.getElement(0)) / x.getElement(1), 2.));
   }
   DatanGraphics.chooseColor(5);
   DatanGraphics.drawPolyline(xpl, ypl);
   // draw caption
   String sn = "N = " + nny;
   numForm.setMaximumFractionDigits(3);
   numForm.setMinimumFractionDigits(3);
   String sx1 = ", x_1# = " + numForm.format(x.getElement(0));
   String sx2 = ", x_2# = " + numForm.format(x.getElement(1));
   String sdx1 = ", &D@x_1# = " + numForm.format(Math.sqrt(cx.getElement(0, 0)));
   String sdx2 = ", &D@x_2# = " + numForm.format(Math.sqrt(cx.getElement(1, 1)));
   caption = sn + sx1 + sx2 + sdx1 + sdx2;
   DatanGraphics.setBigClippingWindow();
   DatanGraphics.chooseColor(2);
   DatanGraphics.drawCaption(1., caption);
   DatanGraphics.closeWorkstation();
 }
  public IntensityFeatureScaleSpacePyramidApp(Class<T> imageType, Class<D> derivType) {
    super(1);
    this.imageType = imageType;

    addAlgorithm(
        0,
        "Hessian Det",
        new WrapperHessianBlobIntensity<T, D>(HessianBlobIntensity.Type.DETERMINANT, derivType));
    addAlgorithm(
        0,
        "Laplacian",
        new WrapperHessianBlobIntensity<T, D>(HessianBlobIntensity.Type.TRACE, derivType));
    addAlgorithm(
        0,
        "Harris",
        new WrapperGradientCornerIntensity<T, D>(
            FactoryIntensityPointAlg.harris(2, 0.4f, false, derivType)));
    addAlgorithm(
        0,
        "Shi Tomasi",
        new WrapperGradientCornerIntensity<T, D>(
            FactoryIntensityPointAlg.shiTomasi(2, false, derivType)));
    addAlgorithm(
        0,
        "FAST 12",
        new WrapperFastCornerIntensity<T, D>(FactoryIntensityPointAlg.fast12(5, 11, imageType)));
    addAlgorithm(0, "KitRos", new WrapperKitRosCornerIntensity<T, D>(derivType));
    addAlgorithm(
        0,
        "Median",
        new WrapperMedianCornerIntensity<T, D>(FactoryBlurFilter.median(imageType, 2), imageType));

    setMainGUI(gui);

    double scales[] = new double[25];
    for (int i = 0; i < scales.length; i++) {
      scales[i] = Math.exp(i * 0.15);
    }
    pyramid = new ScaleSpacePyramid<T>(imageType, scales);

    anyDerivative =
        GImageDerivativeOps.createDerivatives(imageType, FactoryImageGenerator.create(derivType));
  }
Esempio n. 4
0
 public void gradedResponsePersonParameter() {
   double[] a = new double[NITEM]; // read canned data
   a[0] = 0.85;
   a[1] = 1.00;
   a[2] = 0.90;
   a[3] = 1.10;
   a[4] = 1.40;
   double[][] cpt = {
     {1.72, 0.00, -1.72},
     {1.20, 0.20, -1.50},
     {2.10, 1.10, -0.70},
     {-0.60, -0.80, -1.20},
     {1.40, 0.70, -1.70}
   };
   double[] u = {3.0, 2.0, 3.0, 4.0, 3.0};
   double theta = 0.4; // initial value of theta
   int trall = -1; // set traces
   int trmle = -1;
   String yn = JOptionPane.showInputDialog("Trace all? Y/N");
   if (yn.equalsIgnoreCase("y")) {
     trall = 0;
     trmle = 0;
   } else {
     String ynmle = JOptionPane.showInputDialog("Trace MLE? Y/N");
     if (ynmle.equalsIgnoreCase("y")) {
       trmle = 0;
     } else {
       // normal processing
     } // end if (ynmle ...
   } // end if (yn ... else
   System.out.println("All= " + trall + "  MLE= " + trmle + "  Max Cycles= " + MAXIT);
   double fds = 0.0; // first derivative sum
   double sds = 0.0; // second derivative sum
   System.out.println("Initial Theta= " + theta);
   for (int nit = 1; nit <= MAXIT; nit++) {
     System.out.println("MLE Iteration= " + nit);
     for (int i = 0; i <= NITEM - 1; i++) {
       double term4 = 0.0;
       for (int k = 0; k <= MRC - 1; k++) {
         double k1 = k + 1.0; // casting
         if (u[i] == k1) {
           char ptsflg = 'n';
           // calc p's and w's
           int km1 = k - 1;
           double pstrkm1 = 1.0;
           double wkm1 = 0.0;
           double devkm1 = 0.0; // initialize
           if (km1 != -1) {
             devkm1 = cpt[i][km1] + a[i] * theta;
             pstrkm1 = 1.0 / (1.0 + Math.exp(-devkm1));
             wkm1 = pstrkm1 * (1.0 - pstrkm1);
           } else {
             // normal processing
           } // end if (km1 ...
           double pstrk = 0.0;
           double wk = 0.0;
           double dev = 0.0; // initialize
           if (k != MRC - 1) {
             dev = cpt[i][k] + a[i] * theta;
             pstrk = 1.0 / (1.0 + Math.exp(-dev));
             wk = pstrk * (1.0 - pstrk);
           } else {
             // normal processing
           } // end if (k ...
           double pk = pstrkm1 - pstrk;
           if (trall == 0) {
             System.out.println("Item(" + (i + 1) + ")" + "  U(I)= " + u[i]);
             System.out.println(
                 "K-1="
                     + k
                     + "  Dev(K-1)= "
                     + devkm1
                     + "  Pstar(K-1)= "
                     + pstrkm1
                     + "  W(K-1)= "
                     + wkm1);
             System.out.println(
                 "K=" + (k + 1) + "  Dev(K)= " + dev + "  Pstar(K)= " + pstrk + "  W(K)= " + wk);
           } else {
             // normal processing
           } // end if (trall ...
           if (pk < 0.0001 || pk > 0.9999) {
             ptsflg = 'y';
             break; // exit for (int k ...
           } else {
             // normal processing
           } // end if (pk ...
           // calc first and second derivative terms
           // first derivative
           double fterm = (wkm1 - wk) / pk;
           fds += fterm;
           if (trall == 0) {
             System.out.println("Fterm= " + fterm + "  First Derivative Sum= " + fds);
           } else {
             // normal processing
           } // end if (trall ...
           // second derivative
           double term1 = -wk * (1.0 - 2.0 * pstrk) / pk;
           double term2 = wkm1 * (1.0 - 2.0 * pstrkm1) / pk;
           double term3 = -(wkm1 - wk) * (wkm1 - wk) / (pk * pk);
           term4 += term1 + term2 + term3;
           sds += a[i] * a[i] * term4;
           if (trall == 0) {
             System.out.println("Term1= " + term1 + "  Term2= " + term2 + "  Term3= " + term3);
             System.out.println("Term4= " + term4 + "  Second Derivative Sum= " + sds);
           } else {
             // normal processing
           } // end if (trall ...
         } else {
           // normal processing
         } // end if (u[i] ...
       } // end for (int k ... (BASIC 230)
     } // end for (int i ... (BASIC 240)
     double delta = fds / sds;
     theta -= delta;
     if (trall == 0 || trmle == 0) {
       System.out.println("Theta= " + theta + "  Delta= " + delta);
     } else {
       // normal processing
     } // end if (trall ...
     if (Math.abs(delta) < 0.05) {
       break; // exit for (nit ...
     } else {
       // normal processing
     } // end if (Math.abs ...
     if (nit == MAXIT) {
       System.out.println("Maximum Cycles Reached");
     } else {
       // normal processing
     } // end if (nit ...
   } // end for (int nit ... (BASIC 280)
   System.out.println("Theta Estimate= " + theta);
   System.exit(0); // last line
 } // end public static ...
Esempio n. 5
0
 public void gradedResponseItemParameters() {
   double[] pstr = new double[MRC + 1]; // for BASIC 1200
   double[] w = new double[MRC + 1]; // for BASIC 1200
   double[] pk = new double[MRC];
   double[] pobs = new double[MRC];
   double[] sfd = new double[MRC];
   double[] t = new double[MRC];
   double[] pdelta = new double[MRC];
   double[] b = new double[MBC];
   double[] bk = new double[MRC];
   double[][] mtrx = new double[MRC][MRC];
   double[][] tk = new double[MRC][MRC];
   // read canned data
   double a = 1.0; // initial value of common slope
   double[] theta = new double[MAXGPS];
   theta[0] = -3.0;
   theta[1] = -2.0;
   theta[2] = -1.0;
   theta[3] = 0.0;
   theta[4] = 1.0;
   theta[5] = 2.0;
   theta[6] = 3.0;
   double[] f = {1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0};
   double[][] r = {
     {691.0, 242.0, 61.0, 6.0},
     {500.0, 341.0, 136.0, 23.0},
     {309.0, 382.0, 242.0, 67.0},
     {159.0, 341.0, 341.0, 159.0},
     {67.0, 242.0, 382.0, 309.0},
     {23.0, 136.0, 341.0, 500.0},
     {6.0, 61.0, 242.0, 691.0},
   };
   double[] cpt = new double[MBC];
   cpt[0] = 1.8;
   cpt[1] = 0.0;
   cpt[2] = -1.8;
   int trall = -1; // establish trace of program
   int trmle = -1;
   String yn = JOptionPane.showInputDialog("Trace all? Y/N");
   if (yn.equalsIgnoreCase("y")) {
     trall = 0;
     trmle = 0;
   } else {
     String ynmle = JOptionPane.showInputDialog("Trace MLE terms? Y/N");
     if (ynmle.equalsIgnoreCase("y")) {
       trmle = 0;
     } else {
       // normal processing
     } // end if (ynmle ...
   } // end if (yn ... else
   System.out.println("All= " + trall + "  MLE= " + trmle + "  Max Cycles= " + MAXIT);
   int iflag = -1;
   for (int nit = 1; nit <= MAXIT; nit++) {
     // clear sums, vectors, and matrix
     for (int rr = 0; rr <= MRC - 1; rr++) { // rr for r
       sfd[rr] = 0.0;
       for (int c = 0; c <= MRC - 1; c++) {
         mtrx[rr][c] = 0.0;
       } // end for (int c ...
     } // end for (int rr ...
     System.out.println("MLE Iteration= " + nit);
     for (int g = 0; g <= MAXGPS - 1; g++) {
       System.out.println("Ability Level= " + (g + 1));
       // calc p star
       pstr[0] = 1.0;
       w[0] = 0.0;
       pstr[MRC] = 0.0;
       w[MRC] = 0.0;
       if (trall == 0) {
         System.out.println("Boundard Curve Pstar's");
       } else {
         // normal processing
       } // end if (trall ...
       for (int y = 0; y <= MBC - 1; y++) {
         double dev = cpt[y] + a * theta[g];
         pstr[y + 1] = 1.0 / (1.0 + Math.exp(-dev));
         w[y + 1] = pstr[y + 1] * (1.0 - pstr[y + 1]);
         if (trall == 0) {
           System.out.println(
               "Intercept("
                   + (y + 1)
                   + ")= "
                   + cpt[y]
                   + "  A= "
                   + a
                   + "  Theta("
                   + (g + 1)
                   + ")= "
                   + theta[g]);
           System.out.println(
               "Dev= "
                   + dev
                   + "  Pstar("
                   + (y + 1)
                   + ")= "
                   + pstr[y + 1]
                   + "  W("
                   + (y + 1)
                   + ")= "
                   + w[y + 1]);
         } else {
           // normal processing
         } // end if (trall ...
       } // end for (int y ... (BASIC 1280)
       // calc p observed
       if (trall == 0) {
         System.out.println("Pk and P observed");
       } else {
         // normal processing
       }
       for (int k = 0; k <= MRC - 1; k++) {
         if (k == 0) {
           pk[k] = 1.0 - pstr[k + 1];
         } else if (k == MRC - 1) {
           pk[MRC - 1] = pstr[MRC - 1];
         } else {
           pk[k] = pstr[k] - pstr[k + 1];
         } // end if (k ...
         pobs[k] = r[g][k] / f[g];
         if (trall == 0) {
           System.out.println("K= " + (k + 1) + "  PK= " + pk[k] + "  PObs= " + pobs[k]);
         } else {
           // normal processing
         } // end if (trall ...
       } // end for (int k ... (BASIC 1360)
       // calculate first derivative terms for intercepts
       if (trall == 0) {
         System.out.println("Intercept Terms");
       } else {
         // normal processing
       } // end if (trall ...
       for (int y = 0; y <= MBC - 1; y++) {
         double term1 = -pobs[y] / pk[y] + pobs[y + 1] / pk[y + 1];
         double term2 = f[g] * w[y + 1] * term1;
         sfd[y] += term2;
         if (trall == 0) {
           System.out.println(
               "Y= "
                   + (y + 1)
                   + "  Term1= "
                   + term1
                   + "  Term2= "
                   + term2
                   + "  First Derivative= "
                   + sfd[y]);
         } else {
           // normal processing
         } // end if (trall ...
       } // end for (int y ... (BASIC 1460)
       // calculate first derivative terms for slope
       double sumls = 0.0;
       if (trall == 0) {
         System.out.println("Common Slope Terms");
       } else {
         // normal processing
       } // end if (trall ...
       for (int k = 0; k <= MRC - 1; k++) {
         double term1 = w[k] - w[k + 1];
         double term2 = (pobs[k] / pk[k]) * term1;
         sumls += term2;
         if (trall == 0) {
           System.out.println(
               "K= " + (k + 1) + "  Term1= " + term1 + "  Term2= " + term2 + "  SumLS= " + sumls);
         } else {
           // normal processing
         } // end if (trall ...
       } // end for (int k ... (BASIC 1560)
       double term3 = f[g] * theta[g] * sumls;
       sfd[MRC - 1] = sfd[MRC - 1] + term3;
       if (trall == 0) {
         System.out.println("Term3= " + term3 + "  First Derivative Term= " + sfd[MRC - 1]);
       } else {
         // normal processing
       } // end if (trall ...
       // calculate intercept terms for information matrix
       if (trall == 0) {
         System.out.println("Intercept Terms in Information Matrix");
       } else {
         // normal processing
       } // end if (trall ...
       for (int rr = 0; rr <= MBC - 1; rr++) { // rr for r
         for (int c = 0; c <= MBC - 1; c++) {
           if (rr == c) { // diagonal intercept term
             double term1 = 1 / pk[c] + 1 / pk[c + 1];
             double term2 = f[g] * w[c + 1] * w[c + 1] * term1;
             mtrx[rr][c] += term2;
             if (trall == 0) {
               System.out.println(
                   "R= "
                       + (rr + 1)
                       + "  C= "
                       + (c + 1)
                       + "  Term1= "
                       + term1
                       + "  Term2= "
                       + term2);
               System.out.println("Matrix Element= " + mtrx[rr][c]);
             } else {
               // normal processing
             } // end if (trall ...
           } else {
             double term1 = f[g] * w[rr + 1] * w[c + 1];
             double term2 = -term1 * (1.0 / pk[c]); // switched
             if (rr > c) {
               term2 = -term1 * (1.0 / pk[rr]);
             } else {
               // normal processing
             } // end if (rr ...
             mtrx[rr][c] += term2;
             if (Math.abs(rr - c) > 1) {
               mtrx[rr][c] = 0.0;
             } else {
               // normal processing
             } // end if (Math.abs ...
             if (trall == 0) {
               System.out.println(
                   "R= "
                       + (rr + 1)
                       + "  C= "
                       + (c + 1)
                       + "  Term1= "
                       + term1
                       + "  Term2= "
                       + term2);
               System.out.println("Matrix Element= " + mtrx[rr][c]);
             } else {
               // normal processing
             } // end if (trall ...
           } // end if (rr ...
         } // end for (int c ... (BASIC 1730)
       } // end for (int rr ... (BASIC 1730)
       // calculate slope terms for information matrix
       if (trall == 0) {
         System.out.println("Slope Terms in Information Matrix");
       } else {
         // normal processing
       } // end if (trall ...
       int rr = MRC - 1; // rr for r
       for (int c = 0; c <= MRC - 1; c++) {
         if (trall == 0) {
           System.out.println("R= " + (rr + 1) + "  C= " + (c + 1));
         } else {
           // normal processing
         } // end if (trall ...
         double term1 = 0.0; // initialize
         double term2 = 0.0;
         if (c != MRC - 1) {
           term1 = (w[c] - w[c + 1]) / pk[c] - (w[c + 1] - w[c + 2]) / pk[c + 1];
           term2 = -f[g] * w[c + 1] * theta[g] * term1;
         } else {
           term2 = 0.0;
           for (int k = 0; k <= MRC - 1; k++) {
             term1 = (w[k] - w[k + 1]) * (w[k] - w[k + 1]) * 1.0 / pk[k];
             term2 += term1;
             if (trall == 0) {
               System.out.println("K= " + (k + 1) + "  Term1= " + term1 + "  Term2= " + term2);
             } else {
               // normal processing
             } // end if (trall ...
           } // end for (int k ...
           term2 = term2 * f[g] * theta[g] * theta[g];
         } // end if (c ...
         mtrx[rr][c] += term2;
         if (trall == 0) {
           System.out.println(
               "Term1= " + term1 + "  Term2= " + term2 + "  Matrix Element= " + mtrx[rr][c]);
         } else {
           // normal processing
         } // end if (trall ...
       } // end for (int c ... (BASIC 1930)
       // put slope row derivatives in last column
       for (int c = 0; c <= MRC - 1; c++) {
         mtrx[c][rr] = mtrx[rr][c];
       } // end for (int c ...
       if (trall == 0) {
         System.out.println("Information Matrix");
       } else {
         // normal processing
       } // end if (trall ...
       for (int row = 0; row <= MRC - 1; row++) { // row for r
         for (int c = 0; c <= MRC - 1; c++) {
           if (trall == 0) {
             System.out.println(
                 "R= " + (row + 1) + "  C= " + (c + 1) + "  Matrix Element= " + mtrx[row][c]);
           } else {
             // normal processing
           } // end if (trall ...
         } // end for (int c ...
       } // end for (int r ...
     } // end for (int g ... (BASIC 270)
     // invert information matrix
     for (int kk = 0; kk <= MRC - 1; kk++) {
       if (mtrx[0][0] <= 0.000001) {
         System.out.println("The matrix is singular, " + "very near singular, or indefinite");
         iflag = 0;
         break; // exit for (int kk ...
       } else {
         double sr = Math.sqrt(mtrx[0][0]); // sr for r
         for (int ik = 0; ik <= MBC - 1; ik++) {
           t[ik] = mtrx[ik + 1][0] / sr;
         } // end for (ik ...
         t[MRC - 1] = 1.0 / sr;
         for (int jk = 0; jk <= MBC - 1; jk++) {
           for (int ik = 0; ik <= MBC - 1; ik++) {
             mtrx[ik][jk] = mtrx[ik + 1][jk + 1] - t[ik] * t[jk];
           } // end for (ik ...
         } // end for (jk ... (BASIC 2170)
         for (int ik = 0; ik <= MRC - 1; ik++) {
           mtrx[ik][MRC - 1] = -t[ik] * t[MRC - 1];
         } // end for (ik ...
         for (int jk = 0; jk <= MBC - 1; jk++) {
           mtrx[MRC - 1][jk] = mtrx[jk][MRC - 1];
         } // end for (jk ...
       } // end if (mtrx ...
     } // end for (int kk ... (BASIC 2195)
     for (int jk = 0; jk <= MRC - 1; jk++) {
       for (int ik = 0; ik <= MRC - 1; ik++) {
         mtrx[ik][jk] = -mtrx[ik][jk];
       } // end for (ik ...
     } // end for (jk ...
     if (trall == 0) {
       for (int jk = 0; jk <= MRC - 1; jk++) {
         for (int ik = 0; ik <= MRC - 1; ik++) {
           System.out.println(
               "Row= "
                   + (jk + 1)
                   + "  Col= "
                   + (ik + 1)
                   + "  Inversion Elementmt= "
                   + mtrx[jk][ik]);
         } // end for (ik ...
       } // end for (jk ...
     } else {
       // normal processing
     } // end if (trall ...
     // BASIC 290
     char converg = 'y';
     if (iflag == 0) {
       break; // exit for (int nit ...
     } else {
       // calculate change vector and obtain new estimates
       for (int jk = 0; jk <= MRC - 1; jk++) {
         pdelta[jk] = 0.0;
       } // end for (jk ...
       for (int jk = 0; jk <= MRC - 1; jk++) {
         for (int ik = 0; ik <= MRC - 1; ik++) {
           pdelta[jk] += mtrx[jk][ik] * sfd[ik];
         } // end for (ik ...
         if (trall == 0 || trmle == 0) {
           System.out.println("Delta Parameter(" + (jk + 1) + ")= " + pdelta[jk]);
         } else {
           // normal processing
         } // end if (trall ...
       } // end for (jk ...
       // may need big delta protection here
       // obtain new item parameter vlaues
       for (int ik = 0; ik <= MBC - 1; ik++) {
         cpt[ik] += pdelta[ik];
         if (trall == 0 || trmle == 0) {
           System.out.println("Intercept(" + (ik + 1) + ")= " + cpt[ik]);
         } else {
           // normal processing
         } // end if (trall ...
       } // end for (ik ...
       a += pdelta[MRC - 1];
       if (trall == 0 || trmle == 0) {
         System.out.println("Common Slope= " + a);
       } else {
         // normal processing
       } // end if (trall ...
       // calculate convergence criterion
       for (int k = 0; k <= MRC - 1; k++) {
         if (Math.abs(pdelta[k]) > 0.05) {
           converg = 'n';
           break; // exit for (k ...
         } else {
           // normal processing
         } // end if (Math.abs ...
       } // end for (k ...
     } // end if (iflag ...
     if (converg == 'y') {
       System.out.println("Converg=y"); // new line
       break; // exit for (nit ...
     } else {
       // normal processing
     } // end if (converg ...
     if (nit == MAXIT) {
       System.out.println("Reached Maximum Cycles");
     } else {
       // normal processing
     } // end if (nit ...
   } // end for (int nit ... (BASIC 330)
   if (iflag != 0) {
     // print item parameter estimates
     for (int y = 0; y <= MBC - 1; y++) {
       b[y] = -cpt[y] / a;
       System.out.println(
           "Intercept(" + (y + 1) + ")= " + cpt[y] + "Boundary Curve B(" + (y + 1) + ")= " + b[y]);
     } // end for (int y ...
     System.out.println("Common Slope= " + a);
     for (int k = 0; k <= MRC - 1; k++) {
       if (k == 0) {
         bk[k] = b[0];
       } else if (k == MRC - 1) {
         bk[k] = b[MBC - 1];
       } else {
         bk[k] = (b[k] + b[k - 1]) / 2.0;
       }
       System.out.println("Response Category(" + (k + 1) + ") Difficulty= " + bk[k]);
     } // end for (k ...
     System.out.println("Item Discrimination= " + a);
   } else {
     // normal processing
   } // end if (iflag ...
   System.exit(0); // last line
 } // end public static ...
Esempio n. 6
0
  /** Translation durchfuehren */
  public void process() {
    int i, j, k;
    int ch, len;
    float f1;
    double d1, d2, d3, d4, d5;
    long progOff, progLen, lo;

    // io
    AudioFile reInF = null;
    AudioFile imInF = null;
    AudioFile reOutF = null;
    AudioFile imOutF = null;
    AudioFileDescr reInStream = null;
    AudioFileDescr imInStream = null;
    AudioFileDescr reOutStream = null;
    AudioFileDescr imOutStream = null;
    FloatFile reFloatF[] = null;
    FloatFile imFloatF[] = null;
    File reTempFile[] = null;
    File imTempFile[] = null;
    int outChanNum;

    float[][] reInBuf; // [ch][i]
    float[][] imInBuf; // [ch][i]
    float[][] reOutBuf = null; // [ch][i]
    float[][] imOutBuf = null; // [ch][i]
    float[] convBuf1, convBuf2;
    boolean complex;

    PathField ggOutput;

    // Synthesize
    Param ampRef = new Param(1.0, Param.ABS_AMP); // transform-Referenz
    float gain; // gain abs amp
    float dryGain, wetGain;
    float inGain;
    float maxAmp = 0.0f;
    Param peakGain;

    int inLength, inOff;
    int pre;
    int post;
    int length;
    int framesRead, framesWritten, outLength;
    boolean polarIn, polarOut;

    // phase unwrapping
    double[] phi;
    int[] wrap;
    double[] carry;

    Param lenRef;

    topLevel:
    try {

      complex = pr.bool[PR_HASIMINPUT] || pr.bool[PR_HASIMOUTPUT];
      polarIn = pr.intg[PR_OPERATOR] == OP_POLAR2RECT;
      polarOut = pr.intg[PR_OPERATOR] == OP_RECT2POLAR;
      if ((polarIn || polarOut) && !complex) throw new IOException(ERR_NOTCOMPLEX);

      // ---- open input ----

      reInF = AudioFile.openAsRead(new File(pr.text[PR_REINPUTFILE]));
      reInStream = reInF.getDescr();
      inLength = (int) reInStream.length;
      reInBuf = new float[reInStream.channels][8192];
      imInBuf = new float[reInStream.channels][8192];

      if (pr.bool[PR_HASIMINPUT]) {
        imInF = AudioFile.openAsRead(new File(pr.text[PR_IMINPUTFILE]));
        imInStream = imInF.getDescr();
        if (imInStream.channels != reInStream.channels) throw new IOException(ERR_COMPLEX);
        inLength = (int) Math.min(inLength, imInStream.length);
      }

      lenRef = new Param(AudioFileDescr.samplesToMillis(reInStream, inLength), Param.ABS_MS);
      d1 =
          AudioFileDescr.millisToSamples(
              reInStream, (Param.transform(pr.para[PR_OFFSET], Param.ABS_MS, lenRef, null).value));
      j = (int) (d1 >= 0.0 ? (d1 + 0.5) : (d1 - 0.5)); // correct rounding for negative values!
      length =
          (int)
              (AudioFileDescr.millisToSamples(
                      reInStream,
                      (Param.transform(pr.para[PR_LENGTH], Param.ABS_MS, lenRef, null)).value)
                  + 0.5);

      // System.err.println( "offset = "+j );

      if (j >= 0) {
        inOff = Math.min(j, inLength);
        if (!pr.bool[PR_REVERSE]) {
          reInF.seekFrame(inOff);
          if (pr.bool[PR_HASIMINPUT]) {
            imInF.seekFrame(inOff);
          }
        }
        inLength -= inOff;
        pre = 0;
      } else {
        inOff = 0;
        pre = Math.min(-j, length);
      }
      inLength = Math.min(inLength, length - pre);
      post = length - pre - inLength;

      if (pr.bool[PR_REVERSE]) {
        i = pre;
        pre = post;
        post = i;
        inOff += inLength;
      }

      // .... check running ....
      if (!threadRunning) break topLevel;

      // for( op = 0; op < 2; op++ ) {
      // 	System.out.println( op +": pre "+pre[op]+" / len "+inLength[op]+" / post "+post[op] );
      // }
      // System.out.println( "tot "+length[0]);

      outLength = length;
      outChanNum = reInStream.channels;

      // ---- open output ----

      ggOutput = (PathField) gui.getItemObj(GG_REOUTPUTFILE);
      if (ggOutput == null) throw new IOException(ERR_MISSINGPROP);
      reOutStream = new AudioFileDescr(reInStream);
      ggOutput.fillStream(reOutStream);
      reOutStream.channels = outChanNum;
      // well, more sophisticated code would
      // move and truncate the markers...
      if ((pre == 0) /* && (post == 0) */) {
        reInF.readMarkers();
        reOutStream.setProperty(
            AudioFileDescr.KEY_MARKERS, reInStream.getProperty(AudioFileDescr.KEY_MARKERS));
      }
      reOutF = AudioFile.openAsWrite(reOutStream);
      reOutBuf = new float[outChanNum][8192];
      imOutBuf = new float[outChanNum][8192];

      if (pr.bool[PR_HASIMOUTPUT]) {
        imOutStream = new AudioFileDescr(reInStream);
        ggOutput.fillStream(imOutStream);
        imOutStream.channels = outChanNum;
        imOutStream.file = new File(pr.text[PR_IMOUTPUTFILE]);
        imOutF = AudioFile.openAsWrite(imOutStream);
      }
      // .... check running ....
      if (!threadRunning) break topLevel;

      // ---- Further inits ----

      phi = new double[outChanNum];
      wrap = new int[outChanNum];
      carry = new double[outChanNum];
      for (ch = 0; ch < outChanNum; ch++) {
        phi[ch] = 0.0;
        wrap[ch] = 0;
        carry[ch] = Double.NEGATIVE_INFINITY;
      }

      progOff = 0; // read, transform, write
      progLen = (long) outLength * 3;

      wetGain = (float) (Param.transform(pr.para[PR_WETMIX], Param.ABS_AMP, ampRef, null)).value;
      dryGain = (float) (Param.transform(pr.para[PR_DRYMIX], Param.ABS_AMP, ampRef, null)).value;
      if (pr.bool[PR_DRYINVERT]) {
        dryGain = -dryGain;
      }
      inGain = (float) (Param.transform(pr.para[PR_INPUTGAIN], Param.ABS_AMP, ampRef, null)).value;
      if (pr.bool[PR_INVERT]) {
        inGain = -inGain;
      }

      // normalization requires temp files
      if (pr.intg[PR_GAINTYPE] == GAIN_UNITY) {
        reTempFile = new File[outChanNum];
        reFloatF = new FloatFile[outChanNum];
        for (ch = 0;
            ch < outChanNum;
            ch++) { // first zero them because an exception might be thrown
          reTempFile[ch] = null;
          reFloatF[ch] = null;
        }
        for (ch = 0; ch < outChanNum; ch++) {
          reTempFile[ch] = IOUtil.createTempFile();
          reFloatF[ch] = new FloatFile(reTempFile[ch], GenericFile.MODE_OUTPUT);
        }
        if (pr.bool[PR_HASIMOUTPUT]) {
          imTempFile = new File[outChanNum];
          imFloatF = new FloatFile[outChanNum];
          for (ch = 0;
              ch < outChanNum;
              ch++) { // first zero them because an exception might be thrown
            imTempFile[ch] = null;
            imFloatF[ch] = null;
          }
          for (ch = 0; ch < outChanNum; ch++) {
            imTempFile[ch] = IOUtil.createTempFile();
            imFloatF[ch] = new FloatFile(imTempFile[ch], GenericFile.MODE_OUTPUT);
          }
        }
        progLen += outLength;
      } else {
        gain = (float) (Param.transform(pr.para[PR_GAIN], Param.ABS_AMP, ampRef, null)).value;
        wetGain *= gain;
        dryGain *= gain;
      }
      // .... check running ....
      if (!threadRunning) break topLevel;

      // ----==================== the real stuff ====================----

      framesRead = 0;
      framesWritten = 0;

      while (threadRunning && (framesWritten < outLength)) {
        // ---- choose chunk len ----
        len = Math.min(8192, outLength - framesWritten);
        if (pre > 0) {
          len = Math.min(len, pre);
        } else if (inLength > 0) {
          len = Math.min(len, inLength);
        } else {
          len = Math.min(len, post);
        }

        // ---- read input chunks ----
        if (pre > 0) {
          Util.clear(reInBuf);
          if (complex) {
            Util.clear(imInBuf);
          }
          pre -= len;
        } else if (inLength > 0) {
          if (pr.bool[PR_REVERSE]) { // ---- read reversed ----
            reInF.seekFrame(inOff - framesRead - len);
            reInF.readFrames(reInBuf, 0, len);
            for (ch = 0; ch < reInStream.channels; ch++) {
              convBuf1 = reInBuf[ch];
              for (i = 0, j = len - 1; i < j; i++, j--) {
                f1 = convBuf1[j];
                convBuf1[j] = convBuf1[i];
                convBuf1[i] = f1;
              }
            }
            if (pr.bool[PR_HASIMINPUT]) {
              imInF.seekFrame(inOff - framesRead - len);
              imInF.readFrames(imInBuf, 0, len);
              for (ch = 0; ch < imInStream.channels; ch++) {
                convBuf1 = imInBuf[ch];
                for (i = 0, j = len - 1; i < j; i++, j--) {
                  f1 = convBuf1[j];
                  convBuf1[j] = convBuf1[i];
                  convBuf1[i] = f1;
                }
              }
            } else if (complex) {
              Util.clear(imInBuf);
            }
          } else { // ---- read normal ----
            reInF.readFrames(reInBuf, 0, len);
            if (pr.bool[PR_HASIMINPUT]) {
              imInF.readFrames(imInBuf, 0, len);
            } else if (complex) {
              Util.clear(imInBuf);
            }
          }
          inLength -= len;
          framesRead += len;
        } else {
          Util.clear(reInBuf);
          if (complex) {
            Util.clear(imInBuf);
          }
          post -= len;
        }
        progOff += len;
        // .... progress ....
        setProgression((float) progOff / (float) progLen);
        // .... check running ....
        if (!threadRunning) break topLevel;

        // ---- save dry signal ----
        for (ch = 0; ch < outChanNum; ch++) {
          convBuf1 = reInBuf[ch];
          convBuf2 = reOutBuf[ch];
          for (i = 0; i < len; i++) {
            convBuf2[i] = convBuf1[i] * dryGain;
          }
          if (complex) {
            convBuf1 = imInBuf[ch];
            convBuf2 = imOutBuf[ch];
            for (i = 0; i < len; i++) {
              convBuf2[i] = convBuf1[i] * dryGain;
            }
          }
        }

        // ---- rectify + apply input gain ----
        for (ch = 0; ch < reInStream.channels; ch++) {
          convBuf1 = reInBuf[ch];
          convBuf2 = imInBuf[ch];
          // ---- rectify ----
          if (pr.bool[PR_RECTIFY]) {
            if (complex) {
              if (polarIn) {
                for (i = 0; i < len; i++) {
                  convBuf2[i] = 0.0f;
                }
              } else {
                for (i = 0; i < len; i++) {
                  d1 = convBuf1[i];
                  d2 = convBuf2[i];
                  convBuf1[i] = (float) Math.sqrt(d1 * d1 + d2 * d2);
                  convBuf2[i] = 0.0f;
                }
              }
            } else {
              for (i = 0; i < len; i++) {
                convBuf1[i] = Math.abs(convBuf1[i]);
              }
            }
          }
          // ---- apply input gain ----
          Util.mult(convBuf1, 0, len, inGain);
          if (complex & !polarIn) {
            Util.mult(convBuf2, 0, len, inGain);
          }
        }

        // ---- heart of the dragon ----
        for (ch = 0; ch < outChanNum; ch++) {
          convBuf1 = reInBuf[ch];
          convBuf2 = imInBuf[ch];

          switch (pr.intg[PR_OPERATOR]) {
            case OP_NONE: // ================ None ================
              for (i = 0; i < len; i++) {
                reOutBuf[ch][i] += wetGain * convBuf1[i];
              }
              if (complex) {
                for (i = 0; i < len; i++) {
                  imOutBuf[ch][i] += wetGain * convBuf2[i];
                }
              }
              break;

            case OP_SIN: // ================ Cosinus ================
              if (complex) {
                for (i = 0; i < len; i++) {
                  reOutBuf[ch][i] += wetGain * (float) Math.sin(convBuf1[i] * Math.PI);
                  imOutBuf[ch][i] += wetGain * (float) Math.sin(convBuf2[i] * Math.PI);
                }
              } else {
                for (i = 0; i < len; i++) {
                  reOutBuf[ch][i] += wetGain * (float) Math.sin(convBuf1[i] * Math.PI);
                }
              }
              break;

            case OP_SQR: // ================ Square ================
              if (complex) {
                for (i = 0; i < len; i++) {
                  reOutBuf[ch][i] +=
                      wetGain * (convBuf1[i] * convBuf1[i] - convBuf2[i] * convBuf2[i]);
                  imOutBuf[ch][i] -= wetGain * (convBuf1[i] * convBuf2[i] * 2);
                }
              } else {
                for (i = 0; i < len; i++) {
                  reOutBuf[ch][i] += wetGain * (convBuf1[i] * convBuf1[i]);
                }
              }
              break;

            case OP_SQRT: // ================ Square root ================
              if (complex) {
                d3 = phi[ch];
                k = wrap[ch];
                d4 = k * Constants.PI2;
                for (i = 0; i < len; i++) {
                  d1 =
                      wetGain
                          * Math.pow(convBuf1[i] * convBuf1[i] + convBuf2[i] * convBuf2[i], 0.25);
                  d2 = Math.atan2(convBuf2[i], convBuf1[i]);
                  if (d2 - d3 > Math.PI) {
                    k--;
                    d4 = k * Constants.PI2;
                  } else if (d3 - d2 > Math.PI) {
                    k++;
                    d4 = k * Constants.PI2;
                  }
                  d2 += d4;
                  d3 = d2;
                  d2 /= 2;
                  reOutBuf[ch][i] += (float) (d1 * Math.cos(d2));
                  imOutBuf[ch][i] += (float) (d1 * Math.sin(d2));
                }
                phi[ch] = d3;
                wrap[ch] = k;

              } else {
                for (i = 0; i < len; i++) {
                  f1 = convBuf1[i];
                  if (f1 > 0) {
                    reOutBuf[ch][i] += wetGain * (float) Math.sqrt(f1);
                  } // else undefiniert
                }
              }
              break;

            case OP_RECT2POLARW: // ================ Rect->Polar (wrapped) ================
              for (i = 0; i < len; i++) {
                d1 = wetGain * Math.sqrt(convBuf1[i] * convBuf1[i] + convBuf2[i] * convBuf2[i]);
                d2 = Math.atan2(convBuf2[i], convBuf1[i]);
                reOutBuf[ch][i] += (float) d1;
                imOutBuf[ch][i] += (float) d2;
              }
              break;

            case OP_RECT2POLAR: // ================ Rect->Polar ================
              d3 = phi[ch];
              k = wrap[ch];
              d4 = k * Constants.PI2;
              for (i = 0; i < len; i++) {
                d1 = wetGain * Math.sqrt(convBuf1[i] * convBuf1[i] + convBuf2[i] * convBuf2[i]);
                d2 = Math.atan2(convBuf2[i], convBuf1[i]);
                if (d2 - d3 > Math.PI) {
                  k--;
                  d4 = k * Constants.PI2;
                } else if (d3 - d2 > Math.PI) {
                  k++;
                  d4 = k * Constants.PI2;
                }
                d2 += d4;
                reOutBuf[ch][i] += (float) d1;
                imOutBuf[ch][i] += (float) d2;
                d3 = d2;
              }
              phi[ch] = d3;
              wrap[ch] = k;
              break;

            case OP_POLAR2RECT: // ================ Polar->Rect ================
              for (i = 0; i < len; i++) {
                f1 = wetGain * convBuf1[i];
                reOutBuf[ch][i] += f1 * (float) Math.cos(convBuf2[i]);
                imOutBuf[ch][i] += f1 * (float) Math.sin(convBuf2[i]);
              }
              break;

            case OP_LOG: // ================ Log ================
              if (complex) {
                d3 = phi[ch];
                k = wrap[ch];
                d4 = k * Constants.PI2;
                d5 = carry[ch];
                for (i = 0; i < len; i++) {
                  d1 = Math.sqrt(convBuf1[i] * convBuf1[i] + convBuf2[i] * convBuf2[i]);
                  d2 = Math.atan2(convBuf2[i], convBuf1[i]);
                  if (d2 - d3 > Math.PI) {
                    k--;
                    d4 = k * Constants.PI2;
                  } else if (d3 - d2 > Math.PI) {
                    k++;
                    d4 = k * Constants.PI2;
                  }
                  if (d1 > 0.0) {
                    d5 = Math.log(d1);
                  }
                  d2 += d4;
                  reOutBuf[ch][i] += (float) d5;
                  imOutBuf[ch][i] += (float) d2;
                  d3 = d2;
                }
                phi[ch] = d3;
                wrap[ch] = k;
                carry[ch] = d5;

              } else {
                for (i = 0; i < len; i++) {
                  f1 = convBuf1[i];
                  if (f1 > 0) {
                    reOutBuf[ch][i] += wetGain * (float) Math.log(f1);
                  } // else undefiniert
                }
              }
              break;

            case OP_EXP: // ================ Exp ================
              if (complex) {
                for (i = 0; i < len; i++) {
                  d1 = wetGain * Math.exp(convBuf1[i]);
                  reOutBuf[ch][i] += (float) (d1 * Math.cos(convBuf2[i]));
                  imOutBuf[ch][i] += (float) (d1 * Math.sin(convBuf2[i]));
                }
              } else {
                for (i = 0; i < len; i++) {
                  reOutBuf[ch][i] += wetGain * (float) Math.exp(convBuf1[i]);
                }
              }
              break;

            case OP_NOT: // ================ NOT ================
              for (i = 0; i < len; i++) {
                lo = ~((long) (convBuf1[i] * 2147483647.0));
                reOutBuf[ch][i] += wetGain * (float) ((lo & 0xFFFFFFFFL) / 2147483647.0);
              }
              if (complex) {
                for (i = 0; i < len; i++) {
                  lo = ~((long) (convBuf2[i] * 2147483647.0));
                  imOutBuf[ch][i] += wetGain * (float) ((lo & 0xFFFFFFFFL) / 2147483647.0);
                }
              }
              break;
          }
        } // for outChan
        progOff += len;
        // .... progress ....
        setProgression((float) progOff / (float) progLen);
        // .... check running ....
        if (!threadRunning) break topLevel;

        // ---- write output chunk ----
        if (reFloatF != null) {
          for (ch = 0; ch < outChanNum; ch++) {
            reFloatF[ch].writeFloats(reOutBuf[ch], 0, len);
            if (pr.bool[PR_HASIMOUTPUT]) {
              imFloatF[ch].writeFloats(imOutBuf[ch], 0, len);
            }
          }
        } else {
          reOutF.writeFrames(reOutBuf, 0, len);
          if (pr.bool[PR_HASIMOUTPUT]) {
            imOutF.writeFrames(imOutBuf, 0, len);
          }
        }
        // check max amp
        for (ch = 0; ch < outChanNum; ch++) {
          convBuf1 = reOutBuf[ch];
          for (i = 0; i < len; i++) {
            f1 = Math.abs(convBuf1[i]);
            if (f1 > maxAmp) {
              maxAmp = f1;
            }
          }
          if (pr.bool[PR_HASIMOUTPUT]) {
            convBuf1 = imOutBuf[ch];
            for (i = 0; i < len; i++) {
              f1 = Math.abs(convBuf1[i]);
              if (f1 > maxAmp) {
                maxAmp = f1;
              }
            }
          }
        }

        progOff += len;
        framesWritten += len;
        // .... progress ....
        setProgression((float) progOff / (float) progLen);
      } // while not framesWritten

      // ----==================== normalize output ====================----

      if (pr.intg[PR_GAINTYPE] == GAIN_UNITY) {
        peakGain = new Param(maxAmp, Param.ABS_AMP);
        gain =
            (float)
                (Param.transform(
                        pr.para[PR_GAIN],
                        Param.ABS_AMP,
                        new Param(1.0 / peakGain.value, peakGain.unit),
                        null))
                    .value;
        f1 = pr.bool[PR_HASIMOUTPUT] ? ((1.0f + getProgression()) / 2) : 1.0f;
        normalizeAudioFile(reFloatF, reOutF, reOutBuf, gain, f1);
        if (pr.bool[PR_HASIMOUTPUT]) {
          normalizeAudioFile(imFloatF, imOutF, imOutBuf, gain, 1.0f);
        }
        maxAmp *= gain;

        for (ch = 0; ch < outChanNum; ch++) {
          reFloatF[ch].cleanUp();
          reFloatF[ch] = null;
          reTempFile[ch].delete();
          reTempFile[ch] = null;
          if (pr.bool[PR_HASIMOUTPUT]) {
            imFloatF[ch].cleanUp();
            imFloatF[ch] = null;
            imTempFile[ch].delete();
            imTempFile[ch] = null;
          }
        }
      }
      // .... check running ....
      if (!threadRunning) break topLevel;

      // ---- Finish ----

      reOutF.close();
      reOutF = null;
      reOutStream = null;
      if (imOutF != null) {
        imOutF.close();
        imOutF = null;
        imOutStream = null;
      }
      reInF.close();
      reInF = null;
      reInStream = null;
      if (pr.bool[PR_HASIMINPUT]) {
        imInF.close();
        imInF = null;
        imInStream = null;
      }
      reOutBuf = null;
      imOutBuf = null;
      reInBuf = null;
      imInBuf = null;

      // inform about clipping/ low level
      handleClipping(maxAmp);
    } catch (IOException e1) {
      setError(e1);
    } catch (OutOfMemoryError e2) {
      reOutBuf = null;
      imOutBuf = null;
      reInBuf = null;
      imInBuf = null;
      convBuf1 = null;
      convBuf2 = null;
      System.gc();

      setError(new Exception(ERR_MEMORY));
    }

    // ---- cleanup (topLevel) ----
    convBuf1 = null;
    convBuf2 = null;

    if (reInF != null) {
      reInF.cleanUp();
      reInF = null;
    }
    if (imInF != null) {
      imInF.cleanUp();
      imInF = null;
    }
    if (reOutF != null) {
      reOutF.cleanUp();
      reOutF = null;
    }
    if (imOutF != null) {
      imOutF.cleanUp();
      imOutF = null;
    }
    if (reFloatF != null) {
      for (ch = 0; ch < reFloatF.length; ch++) {
        if (reFloatF[ch] != null) {
          reFloatF[ch].cleanUp();
          reFloatF[ch] = null;
        }
        if (reTempFile[ch] != null) {
          reTempFile[ch].delete();
          reTempFile[ch] = null;
        }
      }
    }
    if (imFloatF != null) {
      for (ch = 0; ch < imFloatF.length; ch++) {
        if (imFloatF[ch] != null) {
          imFloatF[ch].cleanUp();
          imFloatF[ch] = null;
        }
        if (imTempFile[ch] != null) {
          imTempFile[ch].delete();
          imTempFile[ch] = null;
        }
      }
    }
  } // process()
Esempio n. 7
0
 protected void compute() {
   n = (int) ni[0].parseInput();
   t0 = ni[1].parseInput();
   deltat = ni[2].parseInput();
   x1 = ni[3].parseInput();
   x2 = ni[4].parseInput();
   sigma = ni[5].parseInput();
   // generate data points
   t = new DatanVector(n);
   y = new DatanVector(n);
   dy = new DatanVector(n);
   rand = DatanRandom.standardNormal(n);
   for (int i = 0; i < n; i++) {
     t.setElement(i, t0 + (double) i * deltat);
     y.setElement(i, x1 * Math.pow(t.getElement(i), x2) + sigma * rand[i]);
     dy.setElement(i, sigma);
   }
   // find 1st approximation of unknowns by method of log-log plot
   tlog = new double[n];
   ylog = new double[n];
   dellog = new double[n];
   int npos = 0;
   for (int i = 0; i < n; i++) {
     if (t.getElement(i) > 0. && y.getElement(i) > 0.) {
       tlog[npos] = Math.log(t.getElement(i));
       ylog[npos] = Math.log(y.getElement(i));
       dellog[npos] = 1.;
       npos++;
     }
   }
   DatanVector vtlog = new DatanVector(npos);
   DatanVector vylog = new DatanVector(npos);
   DatanVector vdellog = new DatanVector(npos);
   for (int j = 0; j < npos; j++) {
     vtlog.setElement(j, tlog[j]);
     vylog.setElement(j, ylog[j]);
     vdellog.setElement(j, dellog[j]);
   }
   LsqPol lp = new LsqPol(vtlog, vylog, vdellog, 2);
   x = lp.getResult();
   x.setElement(0, Math.exp(x.getElement(0)));
   df.writeLine(" x = " + x.toString());
   // perform fit
   int[] list = {1, 1};
   powerlaw = new Powerlaw();
   LsqNon ln = new LsqNon(t, y, dy, x, list, powerlaw);
   x = ln.getResult();
   x1 = x.getElement(0);
   x2 = x.getElement(1);
   cov = ln.getCovarianceMatrix();
   delx1 = Math.sqrt(cov.getElement(0, 0));
   delx2 = Math.sqrt(cov.getElement(1, 1));
   rho = cov.getElement(1, 0) / (delx1 * delx2);
   m = ln.getChiSquare();
   p = 1. - StatFunct.cumulativeChiSquared(m, n - 1);
   // curve of fitted exponential
   xpl = new double[1001];
   ypl = new double[1001];
   dpl = (double) (n - 1) * deltat / 1000.;
   for (int i = 0; i < 1001; i++) {
     xpl[i] = t0 + (double) i * dpl;
     ypl[i] = x1 * Math.pow(xpl[i], x2);
   }
   // prepare data points for plotting
   datx = new double[n];
   daty = new double[n];
   datsx = new double[n];
   datsy = new double[n];
   datrho = new double[n];
   for (int i = 0; i < n; i++) {
     datx[i] = t.getElement(i);
     daty[i] = y.getElement(i);
     datsx[i] = 0.;
     datsy[i] = dy.getElement(i);
     datrho[i] = 0.;
   }
   // display data and fitted curve
   caption =
       "x_1#="
           + String.format(Locale.US, "%5.2f", x1)
           + ", x_2#="
           + String.format(Locale.US, "%5.2f", x2)
           + ", &D@x_1#="
           + String.format(Locale.US, "%5.2f", delx1)
           + ", &D@x_2#="
           + String.format(Locale.US, "%5.2f", delx2)
           + ", &r@="
           + String.format(Locale.US, "%5.2f", rho)
           + ", M="
           + String.format(Locale.US, "%5.2f", m)
           + ", P="
           + String.format(Locale.US, "%6.4f", p);
   new GraphicsWithDataPointsAndPolyline(
       getClass().getName(),
       "",
       xpl,
       ypl,
       1,
       .3,
       datx,
       daty,
       datsx,
       datsy,
       datrho,
       "t",
       "y",
       caption);
 }
 public double evaluate_1(double x) {
   return (2 * x / x * x + 1)
       - 0.4 * Math.exp(0.4 * x) * Math.cos(Math.PI * x)
       + Math.PI * Math.exp(0.4 * x) * Math.sin(Math.PI * x);
 }
 public double evaluate(double x) {
   return Math.log(x * x + 1) - Math.exp(0.4 * x) * Math.cos(Math.PI * x);
 }
Esempio n. 10
0
 public static double exp10(double val) {
   return Math.exp(val / LOG10SCALE);
 }