Package com.nr.model

Examples of com.nr.model.Fitab


      y[i]=sqrt(2.0)+pi*x[i];
      sig[i]=1.0;
      sumx2 += SQR(x[i]);
    }

    Fitab fit1 = new Fitab(x,y,sig);    // Perfect fit, no noise
    sbeps=1.e-12;
    localflag = abs(fit1.a-sqrt(2.0)) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Fitab: Fitted constant term a has incorrect value");
     
    }

    localflag = abs(fit1.b-pi) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Fitab: Fitted slope b has incorrect value");
     
    }

    localflag = fit1.chi2 > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Fitab: Chi^2 not zero for perfect linear data");
     
    }

    localflag = abs(fit1.q-1.0) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Fitab: Probability not 1.0 for perfect linear data");
     
    }

    localflag = abs(fit1.siga/fit1.sigb - sqrt(sumx2/N)) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Fitab: Ratio of siga/sigb incorrect for special case");
     
    }

    // Test 2
    for (j=0;j<M;j++) {
      for (i=0;i<N;i++) {
        sig[i]=0.1*(j+1); //0.1*(j+1)*sqrt(y[i]);
      }
      Fitab fit = new Fitab(x,y,sig);

      localflag = abs(fit.a-sqrt(2.0)) > sbeps;
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** Fitab,Test2: Fitted constant term a has incorrect value");
       
      }

      localflag = abs(fit.b-pi) > sbeps;
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** Fitab,Test2: Fitted slope b has incorrect value");
       
      }

      localflag = fit.chi2 > sbeps;
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** Fitab,Test2: Chi^2 not zero for perfect linear data");
       
      }

      localflag = abs(fit.q-1.0) > sbeps;
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** Fitab,Test2: Probability not 1.0 for perfect linear data");
       
      }

      if (j == 0) {
        sa=fit.siga;
        sb=fit.sigb;
      } else {
        localflag = (fit.siga/sa - (j+1)) > sbeps;
        globalflag = globalflag || localflag;
        if (localflag) {
          fail("*** Fitab,Test2: siga did not scale properly with data errors");
         
        }

        localflag = (fit.sigb/sb - (j+1)) > sbeps;
        globalflag = globalflag || localflag;
        if (localflag) {
          fail("*** Fitab,Test2: sigb did not scale properly with data errors");
         
        }
      }
    }

    // Test 3
    Normaldev ndev=new Normaldev(0.0,1.0,17);
    for (j=0;j<M;j++) {
      for (i=0;i<N;i++) {
        yy[i] = y[i]+ndev.dev();
        sig[i]=1.0;
      }
      Fitab fit3 = new Fitab(x,yy,sig);

//      System.out.printf(fit3.a << " %f\n", fit3.b);
//      System.out.printf(fit3.siga << " %f\n", fit3.sigb);
//      System.out.printf(fit3.chi2 << " %f\n", fit3.q << endl);

View Full Code Here

TOP

Related Classes of com.nr.model.Fitab

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.