Package com.nr.ran

Examples of com.nr.ran.Normaldev


   

    // Test Gaumixmod
    System.out.println("Testing Gaumixmod");

    Normaldev ndev=new Normaldev(0.0,1.0,17);

    // Generate four groups of data
    k=0;
    for (i=0;i<4;i++) {
      for (j=0;j<(int)(NPT*frac[i]);j++) {
        d0=sigma[i][0]*ndev.dev();
        d1=sigma[i][1]*ndev.dev();
        x[k][0]=means[i][0]+d0*vec1[i][0]+d1*vec2[i][0];
        x[k][1]=means[i][1]+d0*vec1[i][1]+d1*vec2[i][1];
        k++;
      }
    }
View Full Code Here


   

    // Test Kmeans
    System.out.println("Testing Kmeans");

    Normaldev ndev = new Normaldev(0.0,1.0,17);

    // Generate four groups of data
    k=0;
    for (i=0;i<4;i++) {
      count[i]=(int)(NPT*frac[i]);
      for (j=0;j<count[i];j++) {
        d0=sigma[i][0]*ndev.dev();
        d1=sigma[i][1]*ndev.dev();
        x[k][0]=means[i][0]+d0*vec1[i][0]+d1*vec2[i][0];
        x[k][1]=means[i][1]+d0*vec1[i][1]+d1*vec2[i][1];
        k++;
      }
    }
View Full Code Here

    // Test period
    System.out.println("Testing period");

    j=0;
    Normaldev mynorm = new Normaldev(0.0,1.0,17);
    for (i=0;i<NP+10;i++) {
      if (i != 2 && i != 3 && i != 5 && i != 20 &&
        i != 37 && i != 50 && i != 66 && i != 67 &&
        i != 82 && i != 92) {
        x[j]=i+1.0;
        y[j]=0.75*cos(0.6*x[j])+mynorm.dev();
        j++;
      }
    }
   
    Period period = new Period(px,py);
View Full Code Here

   
    // Need to add tests for harder test case and resolve issue that the two
    // support vectors give an erroneous indication for two of the kernels above

    // Example similar to the book
    Normaldev ndev=new Normaldev(0.0,0.5,17);
    for (j=0;j<4;j++) {   // Four quadrants
      for (i=0;i<M/4;i++) {
        k=(M/4)*j+i;
        if (j == 0) {
          y[k]=1.0;
          data[k][0]=1.0+ndev.dev();
          data[k][1]=1.0+ndev.dev();
        } else if (j == 1) {
          y[k]=-1.0;
          data[k][0]=-1.0+ndev.dev();
          data[k][1]=1.0+ndev.dev();
        } else if (j == 2) {
          y[k]=1.0;
          data[k][0]=-1.0+ndev.dev();
          data[k][1]=-1.0+ndev.dev();
        } else {
          y[k]=-1.0;
          data[k][0]=1.0+ndev.dev();
          data[k][1]=-1.0+ndev.dev();
        }
      }
    }
       
    // Linear kernel
    Svmlinkernel linkernel2=new Svmlinkernel(data,y);
    Svm linsvm2=new Svm(linkernel2);
    System.out.printf("Errors: ");
    for (lambda=0.001;lambda<10000;lambda *= 10) {
      k=0;
      do {
        test=linsvm2.relax(lambda,omega);
//        System.out.printf(test);
        k++;
      } while (test > 1.e-3 && k < 100);
      nerror=0;
      for (i=0;i<M;i++) {
        nerror += ((y[i]==1.0) != (linsvm2.predict(i) >= 0.0) ? 1 : 0);
      }
      System.out.printf("%d ",nerror);
      // Test new data
      nerror=0;
      for (j=0;j<4;j++) {   // Four quadrants
        for (i=0;i<M/4;i++) {
          if (j == 0) {
            yy=1.0;
            x[0]=1.0+ndev.dev();
            x[1]=1.0+ndev.dev();
          } else if (j == 1) {
            yy=-1.0;
            x[0]=-1.0+ndev.dev();
            x[1]=1.0+ndev.dev();
          } else if (j == 2) {
            yy=1.0;
            x[0]=-1.0+ndev.dev();
            x[1]=-1.0+ndev.dev();
          } else {
            yy=-1.0;
            x[0]=1.0+ndev.dev();
            x[1]=-1.0+ndev.dev();
          }
          nerror += ((yy==1.0) != (linsvm2.predict(x) >= 0.0) ? 1 : 0);
        }
      }
      System.out.printf("%d    ",nerror);
    }
    System.out.println();

    // Polynomial kernel
    Svmpolykernel polykernel2 = new Svmpolykernel(data,y,1.0,1.0,4.0);
    Svm polysvm2=new Svm(polykernel2);
    System.out.printf("Errors: ");
    for (lambda=0.001;lambda<10000;lambda *= 10) {
      k=0;
      do {
        test=polysvm2.relax(lambda,omega);
//        System.out.printf(test);
        k++;
      } while (test > 1.e-3 && k < 100);
      // Test training set
      nerror=0;
      for (i=0;i<M;i++) {
        nerror += ((y[i]==1.0) != (polysvm2.predict(i) >= 0.0) ? 1 : 0);
      }
      System.out.printf("%d ",nerror);
      // Test new data
      nerror=0;
      for (j=0;j<4;j++) {   // Four quadrants
        for (i=0;i<M/4;i++) {
          if (j == 0) {
            yy=1.0;
            x[0]=1.0+ndev.dev();
            x[1]=1.0+ndev.dev();
          } else if (j == 1) {
            yy=-1.0;
            x[0]=-1.0+ndev.dev();
            x[1]=1.0+ndev.dev();
          } else if (j == 2) {
            yy=1.0;
            x[0]=-1.0+ndev.dev();
            x[1]=-1.0+ndev.dev();
          } else {
            yy=-1.0;
            x[0]=1.0+ndev.dev();
            x[1]=-1.0+ndev.dev();
          }
          nerror += ((yy==1.0) != (polysvm2.predict(x) >= 0.0) ? 1 : 0);
        }
      }
      System.out.printf("%d    ",nerror);
    }
    System.out.println();

    // Gaussian kernel
    Svmgausskernel gausskernel2=new Svmgausskernel(data,y,1.0);
    Svm gausssvm2=new Svm(gausskernel2);
    System.out.printf("Errors: ");
    for (lambda=0.001;lambda<10000;lambda *= 10) {
      k=0;
      do {
        test=gausssvm2.relax(lambda,omega);
//        System.out.printf(test);
        k++;
      } while (test > 1.e-3 && k < 100);
      nerror=0;
      for (i=0;i<M;i++) {
        nerror += ((y[i]==1.0) != (gausssvm2.predict(i) >= 0.0) ? 1 : 0);
      }
      System.out.printf("%d ",nerror);
      // Test new data
      nerror=0;
      for (j=0;j<4;j++) {   // Four quadrants
        for (i=0;i<M/4;i++) {
          if (j == 0) {
            yy=1.0;
            x[0]=1.0+ndev.dev();
            x[1]=1.0+ndev.dev();
          } else if (j == 1) {
            yy=-1.0;
            x[0]=-1.0+ndev.dev();
            x[1]=1.0+ndev.dev();
          } else if (j == 2) {
            yy=1.0;
            x[0]=-1.0+ndev.dev();
            x[1]=-1.0+ndev.dev();
          } else {
            yy=-1.0;
            x[0]=1.0+ndev.dev();
            x[1]=-1.0+ndev.dev();
          }
          nerror += ((yy==1.0) != (gausssvm2.predict(x) >= 0.0) ? 1 : 0);
        }
      }
      System.out.printf("%d    ",nerror);
View Full Code Here

    // Test fasper
    System.out.println("Testing fasper");

    j=0;
    Normaldev mynorm = new Normaldev(0.0,1.0,17);
    for (i=0;i<NP+10;i++) {
      if (i != 2 && i != 3 && i != 5 && i != 20 &&
        i != 37 && i != 50 && i != 66 && i != 67 &&
        i != 82 && i != 92) {
        x[j]=i+1;
        y[j]=0.75*cos(0.6*x[j])+mynorm.dev();
        j++;
      }
    }
    Fasper fasper = new Fasper(px1,py1);
    fasper.fasper(x,y,4.0,1.0);
View Full Code Here

    System.out.println("Testing Normaldev");

    // Check fingerprint of doub()
    mu=0.0;
    sig=1.0;
    Normaldev myran = new Normaldev(mu,sig,17);
    localflag=false;
    for (i=0;i<10;i++)
//      System.out.printf(setw(25) << setprecision(20) << myran.dev());
      localflag=localflag || abs(myran.dev()-fingerprint[i])>sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Normaldev: dev() does not match fingerprint");
     
    }

    // Check statistics
    Normaldist expect = new Normaldist(mu,sig);
    xl=mu-range/2.0;
    xu=mu+range/2.0;
    binsize=range/M;
    for (i=0;i<M;i++) {
      x[i]=xl+binsize*i;
      ebins[i]=N*binsize*expect.p(x[i]+0.5*binsize);
      bins[i]=0;
    }
    for (i=0;i<N;i++) {
      nbin=(int)(floor((0.5*range+myran.dev())/binsize));
      if ((nbin >= 0) && (nbin < M)) bins[nbin] += 1;
    }
    chsone(bins,ebins,df,chisq,prob);
    System.out.printf("     chisq,dev(): %f  prob: %f\n", chisq.val, prob.val);
    localflag = (prob.val < 0.05);
View Full Code Here

public class Proposal {
  Normaldev gau;
  double logstep;

  public Proposal(final int ranseed, final double lstep) {
    gau = new Normaldev(0., 1., ranseed);
    logstep = lstep;
  }
View Full Code Here

TOP

Related Classes of com.nr.ran.Normaldev

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.