[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.4 and 1.9

version 1.4, 2013/02/24 21:36:49 version 1.9, 2013/03/07 03:00:43
Line 1 
Line 1 
 /* $OpenXM: OpenXM/src/hgm/mh/src/mh.c,v 1.3 2013/02/23 07:00:21 takayama Exp $ */  /* $OpenXM: OpenXM/src/hgm/mh/src/mh.c,v 1.8 2013/03/05 07:03:37 takayama Exp $ */
 #include <stdio.h>  #include <stdio.h>
 #include "sfile.h"  #include "sfile.h"
 #include "mh.h"  #include "mh.h"
Line 22  struct cWishart *new_cWishart(int rank) {
Line 22  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 mode) {                                int approxDeg,double h, int dp, double x,int modep[]) {
     /*
        modep[0]. Do Koev-Edelman (ignored for now).
        modep[1]. Do the HGM
        modep[2]. Return modep[2] intermediate data.
      */
   struct SFILE *fp;    struct SFILE *fp;
   char swork[WSIZE];    char swork[WSIZE];
   char *argv[WSIZE];    char *argv[WSIZE];
Line 75  struct cWishart *mh_cwishart_gen(int m,int n,double be
Line 80  struct cWishart *mh_cwishart_gen(int m,int n,double be
   cw = new_cWishart(rank);    cw = new_cWishart(rank);
   cw->x = rp->x;    cw->x = rp->x;
   cw->rank = rp->rank;    cw->rank = rp->rank;
   /* todo, the following line seems to cause seg fault. */    if (rank !=  cw->rank) {
       fprintf(stderr,"Rank error.\n"); return(NULL);
     }
   for (i=0; i<cw->rank; i++) (cw->f)[i] = (rp->y)[i];    for (i=0; i<cw->rank; i++) (cw->f)[i] = (rp->y)[i];
   sfp = (rp->sfpp)[0];    sfp = (rp->sfpp)[0];
   cw->aux = (char *) mh_malloc(sfp->len+1);    cw->aux = (char *) mh_malloc((sfp->len)+1);
   mh_outstr((char *)cw->aux,sfp->len+1,sfp);    mh_outstr((char *)(cw->aux),(sfp->len)+1,sfp);
     /* todo, the following line seems to cause seg fault. */
   /* deallocate the memory */    /* deallocate the memory */
   for (i=0; i<rp->size; i++) mh_fclose((rp->sfpp)[i]);    for (i=0; i<rp->size; i++) mh_fclose((rp->sfpp)[i]);
   /* todo, mh_free_??(rp);  free Iv's */    /* todo, mh_free_??(rp);  free Iv's */
   if (mode == 0) return(cw);    if (!modep[1]) return(cw);
   
     if (MH_DEBUG) printf("\n\n%s\n",(char *)cw->aux);
     /* This output is strange. */
   /* Starting HGM */    /* Starting HGM */
   argv[3] = (char *)cw->aux;    argv[3] = (char *)cw->aux;
   argv[4] = "--dataf";    argv[4] = "--dataf";
Line 102  struct cWishart *mh_cwishart_gen(int m,int n,double be
Line 112  struct cWishart *mh_cwishart_gen(int m,int n,double be
     cw->aux = (char *) mh_malloc(sfp->len+1);      cw->aux = (char *) mh_malloc(sfp->len+1);
     mh_outstr((char *)cw->aux,sfp->len+1,sfp);      mh_outstr((char *)cw->aux,sfp->len+1,sfp);
   }    }
   
   sfp = (rp->sfpp)[1];    sfp = (rp->sfpp)[1];
   if (sfp) {    if (sfp) {
     cw->aux2 = (char *) mh_malloc(sfp->len+1);      cw->aux2 = (char *) mh_malloc(sfp->len+1);
Line 116  struct cWishart *mh_cwishart_gen(int m,int n,double be
Line 125  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) {
   return(mh_cwishart_gen(m,n,beta,x0,approxDeg,h,dp,x,0));    int modep[]={1,0,0};
     return(mh_cwishart_gen(m,n,beta,x0,approxDeg,h,dp,x,modep));
 }  }
   
 /* 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)
 {  {
   return(mh_cwishart_gen(m,n,beta,x0,approxDeg,h,dp,x,1));    int modep[]={1,1,0};
     return(mh_cwishart_gen(m,n,beta,x0,approxDeg,h,dp,x,modep));
 }  }
   
 #ifdef STANDALONE  #ifdef STANDALONE
 main() {  main() {
   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;
     struct SFILE *sfp;
     char *s;
     char str[1024];
     double x;
   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);
   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]);
Line 140  main() {
Line 155  main() {
   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);
   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;
     /* printf("%s",(char *)cw->aux); */      /* printf("%s",(char *)cw->aux); */
       sfp = mh_fopen(s,"r",0);
       while (mh_fgets(str,1024,sfp)) {
         sscanf(str,"%lg",&x); printf("%lg\n",x);
       }
       mh_fclose(sfp);
   }    }
 }  }
 main1() {  main1() {

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.9

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