[BACK]Return to mh.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / hgm / mh / src

Diff for /OpenXM/src/hgm/mh/src/mh.c between version 1.12 and 1.13

version 1.12, 2013/03/08 04:54:01 version 1.13, 2014/03/16 03:11:07
Line 1 
Line 1 
 /* $OpenXM: OpenXM/src/hgm/mh/src/mh.c,v 1.11 2013/03/07 07:02:18 takayama Exp $ */  /* $OpenXM: OpenXM/src/hgm/mh/src/mh.c,v 1.12 2013/03/08 04:54:01 takayama Exp $ */
 #include <stdio.h>  #include <stdio.h>
 #include "sfile.h"  #include "sfile.h"
 #include "mh.h"  #include "mh.h"
 #define WSIZE 1024  #define WSIZE 1024
 extern int MH_DEBUG;  extern int MH_DEBUG;
   extern int M_show_autosteps;
 static int imypower(int x,int n) {  static int imypower(int x,int n) {
   int a,i;    int a,i;
   a = 1;    a = 1;
Line 22  struct cWishart *new_cWishart(int rank) {
Line 23  struct cWishart *new_cWishart(int rank) {
 }  }
   
 struct cWishart *mh_cwishart_gen(int m,int n,double beta[],double x0,  struct cWishart *mh_cwishart_gen(int m,int n,double beta[],double x0,
                               int approxDeg,double h, int dp, double x,int modep[]) {                                   int approxDeg,double h, int dp, double x,int modep[],
                                  int automatic,double assigned_series_error,
                                  int verbose)
   {
   /*    /*
      modep[0]. Do Koev-Edelman (ignored for now).       modep[0]. Do Koev-Edelman (ignored for now).
      modep[1]. Do the HGM       modep[1]. Do the HGM
Line 31  struct cWishart *mh_cwishart_gen(int m,int n,double be
Line 35  struct cWishart *mh_cwishart_gen(int m,int n,double be
   struct SFILE *fp;    struct SFILE *fp;
   char swork[WSIZE];    char swork[WSIZE];
   char *argv[WSIZE];    char *argv[WSIZE];
     int argc;
   int i,rank;    int i,rank;
   char *comm;    char *comm;
   struct MH_RESULT *rp;    struct MH_RESULT *rp;
Line 64  struct cWishart *mh_cwishart_gen(int m,int n,double be
Line 69  struct cWishart *mh_cwishart_gen(int m,int n,double be
   mh_fputs("%%Xng=\n",fp);    mh_fputs("%%Xng=\n",fp);
   sprintf(swork,"%lf\n",x); mh_fputs(swork,fp);    sprintf(swork,"%lf\n",x); mh_fputs(swork,fp);
   
     sprintf(swork,"%%automatic=%d\n",automatic); mh_fputs(swork,fp);
     sprintf(swork,"%%assigned_series_error=%lg\n",assigned_series_error); mh_fputs(swork,fp);
     sprintf(swork,"%%show_autosteps=%d\n",verbose); mh_fputs(swork,fp);
   
   comm = (char *)mh_malloc(fp->len +1);    comm = (char *)mh_malloc(fp->len +1);
   mh_outstr(comm,fp->len+1,fp);    mh_outstr(comm,fp->len+1,fp);
   mh_fclose(fp);    mh_fclose(fp);
Line 99  struct cWishart *mh_cwishart_gen(int m,int n,double be
Line 108  struct cWishart *mh_cwishart_gen(int m,int n,double be
   argv[3] = (char *)cw->aux;    argv[3] = (char *)cw->aux;
   argv[4] = "--dataf";    argv[4] = "--dataf";
   argv[5] = "dummy-dataf";    argv[5] = "dummy-dataf";
   rp = mh_main(6,argv);    argc=6;
     if (verbose) {
       argv[6] = "--verbose"; ++argc;
     }
     rp = mh_main(argc,argv);
   if (rp == NULL) {    if (rp == NULL) {
     fprintf(stderr,"rp is NULL in the second step.\n"); return(NULL);      fprintf(stderr,"rp is NULL in the second step.\n"); return(NULL);
   }    }
Line 125  struct cWishart *mh_cwishart_gen(int m,int n,double be
Line 138  struct cWishart *mh_cwishart_gen(int m,int n,double be
 /* Cumulative probability distribution function of the first eigenvalue of  /* Cumulative probability distribution function of the first eigenvalue of
    Wishart matrix by Series */     Wishart matrix by Series */
 struct cWishart *mh_cwishart_s(int m,int n,double beta[],double x0,  struct cWishart *mh_cwishart_s(int m,int n,double beta[],double x0,
                                int approxDeg,double h, int dp, double x) {                                 int approxDeg,double h, int dp, double x,
                                  int automatic,double assigned_series_error,
                                  int verbose)
   {
   int modep[]={1,0,0};    int modep[]={1,0,0};
   return(mh_cwishart_gen(m,n,beta,x0,approxDeg,h,dp,x,modep));    return(mh_cwishart_gen(m,n,beta,x0,approxDeg,h,dp,x,modep,automatic,assigned_series_error,verbose));
 }  }
   
 /* Cumulative probability distribution function of the first eigenvalue of  /* Cumulative probability distribution function of the first eigenvalue of
    Wishart matrix by HGM */     Wishart matrix by HGM */
 struct cWishart *mh_cwishart_hgm(int m,int n,double beta[],double x0,  struct cWishart *mh_cwishart_hgm(int m,int n,double beta[],double x0,
                                  int approxDeg, double h, int dp , double x)                                   int approxDeg, double h, int dp , double x,
                                  int automatic,double assigned_series_error,
                                  int verbose)
 {  {
   int modep[]={1,1,0};    int modep[]={1,1,0};
   return(mh_cwishart_gen(m,n,beta,x0,approxDeg,h,dp,x,modep));    return(mh_cwishart_gen(m,n,beta,x0,approxDeg,h,dp,x,modep,automatic,assigned_series_error,verbose));
 }  }
   
 #ifdef STANDALONE  #ifdef STANDALONE
Line 148  main(int argc,char *argv[]) {
Line 166  main(int argc,char *argv[]) {
   char str[1024];    char str[1024];
   double x;    double x;
   int i,show;    int i,show;
   int strategy=0;    int strategy=1;
   double err[2]={-1.0,-1.0};    double err[2]={-1.0,-1.0};
     int verbose=0;
   show=1;    show=1;
   for (i=1; i<argc; i++) {    for (i=1; i<argc; i++) {
         if (strcmp(argv[i],"--strategy")==0) {          if (strcmp(argv[i],"--strategy")==0) {
Line 160  main(int argc,char *argv[]) {
Line 179  main(int argc,char *argv[]) {
           i++; sscanf(argv[i],"%lg",&(err[1]));            i++; sscanf(argv[i],"%lg",&(err[1]));
         }else if (strcmp(argv[i],"--quiet")==0) {          }else if (strcmp(argv[i],"--quiet")==0) {
           show=0;            show=0;
           }else if (strcmp(argv[i],"--verbose")==0) {
             verbose=1;
         }else{          }else{
           fprintf(stderr,"Unknown option.\n");            fprintf(stderr,"Unknown option.\n");
         }          }
   }    }
   mh_set_strategy(strategy,err);    mh_set_strategy(strategy,err);
   cw=mh_cwishart_hgm(3,5,beta,0.3,7,  0.01,1,10);    cw=mh_cwishart_hgm(3,5,beta,0.3,7,  0.01,1,10, 1,1e-7,verbose);
   if (cw != NULL) {    if (cw != NULL) {
     printf("x=%lf, y=%lf\n",cw->x,(cw->f)[0]);      printf("x=%lf, y=%lf\n",cw->x,(cw->f)[0]);
     /* printf("%s",(char *)cw->aux); */      /* printf("%s",(char *)cw->aux); */
   }    }
   cw=mh_cwishart_hgm(4,5,beta,0.3,7,  0.01,1,10);    cw=mh_cwishart_hgm(4,5,beta,0.3,7,  0.01,1,10, 1,1e-7,verbose);
   if (cw != NULL) {    if (cw != NULL) {
     printf("x=%lf, y=%lf\n",cw->x,(cw->f)[0]);      printf("x=%lf, y=%lf\n",cw->x,(cw->f)[0]);
     s = (char *)cw->aux;      s = (char *)cw->aux;
Line 187  main(int argc,char *argv[]) {
Line 208  main(int argc,char *argv[]) {
 main1() {  main1() {
   double beta[5]={1.0,2.0,3.0,4.0,5.0};    double beta[5]={1.0,2.0,3.0,4.0,5.0};
   struct cWishart *cw;    struct cWishart *cw;
   cw=mh_cwishart_s(3,5,beta,0.3,7,  0,0,0);    int verbose=1;
     cw=mh_cwishart_s(3,5,beta,0.3,7,  0,0,0, 1,1e-7,verbose);
   if (cw != NULL) {    if (cw != NULL) {
     printf("%s",(char *)cw->aux);      printf("%s",(char *)cw->aux);
   }    }
   cw=mh_cwishart_s(4,5,beta,0.3,7,  0,0,0);    cw=mh_cwishart_s(4,5,beta,0.3,7,  0,0,0, 1,1e-7,verbose);
   if (cw != NULL) {    if (cw != NULL) {
     printf("%s",(char *)cw->aux);      printf("%s",(char *)cw->aux);
   }    }
   cw=mh_cwishart_s(5,5,beta,0.3,7,  0,0,0);    cw=mh_cwishart_s(5,5,beta,0.3,7,  0,0,0, 1,1e-7,verbose);
   if (cw != NULL) {    if (cw != NULL) {
     printf("%s",(char *)cw->aux);      printf("%s",(char *)cw->aux);
   }    }

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>