/* \file lrt.c Calculates likelihood ratio tests */ #include "migration.h" #include "sighandler.h" #include "tools.h" #include "broyden.h" #include "combroyden.h" #include "options.h" #include "aic.h" #include "migrate_mpi.h" #include "pretty.h" #ifndef LAGUERRE //#include "derivatives2.h" #endif #include "sort.h" //#ifdef UEP //#include "uep.h" //#endif #ifdef DMALLOC_FUNC_CHECK #include <dmalloc.h> #endif void print_lratio_test (world_fmt * world, long *Gmax); void test_loci_like (nr_fmt * nr, MYREAL *param0, MYREAL *param1, long df, long zeros, long loci, world_fmt * world, long *maxwhich, long maxnum, boolean withhead, char *this_string1); long set_test_param (MYREAL *param, lr_data_fmt *lrtdata, world_fmt * world, long lrline, long locus, long *maxwhich, long *maxnum, long *zeros); void print_lrt_box(world_fmt *world, MYREAL *param0, MYREAL *param1, long zeros, long elem, char * this_string1, MYREAL like0, MYREAL like1, long df); long parse_h0(char ***box, long *size, char *thisString, MYREAL *param0, MYREAL *param1 , long elem, world_fmt *world); void parse_h0part(char ***box, long *size, long *tempsize, MYREAL *param, long elem, char head[], world_fmt *world); void parse_h0string(char ***box, long *size, long *tempsize, char *thisString); void print_box(world_fmt* world,char **box,long size, MYREAL like0, MYREAL like1,MYREAL lrt, MYREAL chiprob, MYREAL chiprob2, MYREAL aic, long df, long aicparamnum); long simplify_lrtvalues(char * in, char** out); boolean mywhitespace (char ch) { if (!(ch == ',' || ch == '\0' || ch == '\t' || ch == '\r' || ch == '\n' || ch == ';')) { return TRUE; } return FALSE; } void print_lratio_test (world_fmt * world, long *Gmax) { long c; long r, locus; long df; long zeros; int header; nr_fmt *nr; MYREAL *param0; MYREAL *param1; long *maxwhich; long nparam; long maxnum = 0; long rep = !world->options->replicate ? 0 : (world->options->replicatenum == 0 ? world->options->lchains : world->options->replicatenum); long repstop = world->repstop; param0 = (MYREAL *) mycalloc (1, sizeof (MYREAL) * (world->numpop2 + 1)); param1 = (MYREAL *) mycalloc (1, sizeof (MYREAL) * (world->numpop2 + 1)); maxwhich = (long *) mycalloc (1, sizeof (long) * (world->numpop2 + 1)); if (world->options->progress) FPRINTF (stdout, " Printing likelihood ratio tests\n"); nr = (nr_fmt *) mycalloc (1, sizeof (nr_fmt)); create_nr (nr, world, *Gmax, 0, world->loci, world->repkind, world->rep); for (locus = 0; locus < world->loci; locus++) { if (world->options->replicate) for (r = 0; r < repstop; r++) create_multiapg0 (nr->apg0[r][locus], nr, r, locus); else create_apg0 (nr->apg0[0][locus], nr, &world->atl[0][locus], locus); } if (world->loci > 1) { locus = world->loci; rep = 0; } else { world->locus=0; locus = 0; } PAGEFEEDWORLD; nparam = world->options->gamma ? world->numpop2 + 1 : world->numpop2; for (c = 0; c < world->options->lratio->counter; c++) { header = (c == 0) ? HEADER : NOHEADER; if (world->options->lratio->data[c].type == MLE) { memcpy (param1, world->atl[rep][locus].param, sizeof (MYREAL) * nparam); df = set_test_param (param0, &world->options->lratio->data[c], world, 0, -1, maxwhich, &maxnum, &zeros); test_loci_like (nr, param0, param1, df, zeros, world->loci, world, maxwhich, maxnum, header, world->options->lratio->data[c].value1); } } fflush (world->outfile); myfree(param0); myfree(param1); myfree(maxwhich); destroy_nr (nr, world); } //remember: param0 is the parameterset to test and // NOT the parameterset from migrate. #define BOXSIZE 50 /*defines the print width of the left box containing the H0*/ #define BOXSIZE2 40 /*defines the print width of the left box with the legend*/ void test_loci_like (nr_fmt * nr, MYREAL *param0, MYREAL *param1, long df, long zeros, long loci, world_fmt * world, long *maxwhich, long maxnum, boolean withhead, char *this_string1) { // char *teststat, temp[LRATIO_STRINGS]; MYREAL like1, like0;//, testval, chiprob, chiprob2; // int length; // long numparam; long i, j, g = 0; long elem; //long zi; long z = 0, w = 0; // long pop; //MYREAL normd = 0.0; long *which; MYREAL **hess; MYREAL /**values,*/ *saveparam0; //MYREAL tparam; // long spaces = 0; char temp[100]; helper_fmt helper; MYREAL *lparam0; MYREAL *lparam1; MYREAL aicfull; long aicfullparamnum; // char *message; numparam = world->numpop2 + 1; doublevec2d(&hess,numparam, numparam); lparam0 = (MYREAL *) mycalloc (numparam, sizeof (MYREAL)); lparam1 = (MYREAL *) mycalloc (numparam, sizeof (MYREAL)); which = (long *) mycalloc (1, sizeof (long) * numparam); // message = (char *) mycalloc (20, sizeof (char)); // values = (MYREAL *) mycalloc (1, sizeof (MYREAL) * (world->numpop2 + 1)); saveparam0 = (MYREAL *) mymalloc (sizeof (MYREAL) * numparam); memcpy (saveparam0, param0, sizeof (MYREAL) * numparam); for (i = 0; i < loci; i++) { for (j = 0; j < world->repstop; j++) { if (g < world->atl[j][i].T) g = world->atl[j][i].T; } } elem = world->options->gamma ? numparam : nr->numpop2; nr->skiploci = world->data->skiploci; helper.multilocus = world->loci == 1 ? FALSE : TRUE; if (maxnum > 0) { for (i = 0; i < elem; i++) { if (i != maxwhich[z]) { which[w] = i; nr->values[w++] = param0[i]; } else { if (maxnum > z + 1) z++; } } nr->profilenum = w; maximize (¶m0, world, nr, hess, PROFILE, world->repkind); like0 = nr->llike; //xcode normd = nr->normd; memcpy (param0, world->param0, sizeof (MYREAL) * nr->partsize); } else { set_logparam (lparam0, param0, elem); fill_helper (&helper, param0, lparam0, world, nr); like0 = CALCLIKE (&helper, param0, lparam0); } set_logparam (lparam1, param1, elem); fill_helper (&helper, param1, lparam1, world, nr); like1 = CALCLIKE (&helper, param1, lparam1); // sprintf (message, " %f ", chiprob2); if (withhead) { FPRINTF (world->outfile, "==============================================================================\n"); FPRINTF (world->outfile, "Likelihood ratio tests\n"); FPRINTF (world->outfile, "==============================================================================\n"); FPRINTF (world->outfile, "Over all loci\n"); FPRINTF (world->outfile, "Legend for the LRT tables\n"); print_line(world->outfile,'-',79,CONT); sprintf (temp,"Null-Hypothesis: your test model"); FPRINTF(world->outfile,"%-*.*s | Log(likelihood) of test model\n",BOXSIZE2,BOXSIZE2,temp); sprintf (temp,"=same="); FPRINTF(world->outfile,"%-*.*s | Log(likelihood) of full model\n",BOXSIZE2,BOXSIZE2, temp); sprintf (temp,"full model (the model under which the"); FPRINTF(world->outfile,"%-*.*s | Likelihood ratio test value\n",BOXSIZE2,BOXSIZE2, temp); sprintf (temp,"genealogies were sampled)"); FPRINTF(world->outfile,"%-*.*s | Degrees of freedom of test\n",BOXSIZE2,BOXSIZE2,temp); sprintf (temp,"[Theta values are on the diagonal of the "); FPRINTF(world->outfile,"%-*.*s | Probability*\n",BOXSIZE2,BOXSIZE2,temp); sprintf (temp,"Migration matrix, migration rates are "); FPRINTF(world->outfile,"%-*.*s | Probability**\n",BOXSIZE2,BOXSIZE2,temp); sprintf (temp,"specified as %s]", world->options->usem ? "M" : "Theta * M"); FPRINTF(world->outfile,"%-*.*s | Akaike's Information Criterion***\n",BOXSIZE2,BOXSIZE2,temp); sprintf (temp," "); FPRINTF(world->outfile,"%-*.*s | Number of parameters used\n",BOXSIZE2,BOXSIZE2,temp); print_line(world->outfile,'-',79,CONT); FPRINTF(world->outfile," *) Probability under the assumption that parameters have range -Inf to Inf\n"); FPRINTF(world->outfile," **) Probability under the assumption that parameters have range 0 to Inf\n"); FPRINTF(world->outfile,"***) AIC: the smaller the value the better the model\n"); aicfullparamnum = find_paramnum(world,NULL); aicfull = -2. * like1 + 2. * aicfullparamnum; FPRINTF(world->outfile," [the full model has AIC=%f, num(param)=%li]\n\n",aicfull,aicfullparamnum); pdf_print_lrt_header(aicfull,aicfullparamnum, &world->page_width, &world->page_height); } print_lrt_box(world,param0, param1, zeros, elem, this_string1, like0, like1, df); myfree(lparam0); myfree(lparam1); myfree(saveparam0); myfree(which); myfree(hess[0]); myfree(hess); }
inline void fill() { fill_helper(this->begin(), this->end()); cur = this->begin(); }
/****************************************************************************** * * axfs_do_fill_super * * Description: * Uses the data collected by axfs_get_sb() and populates the superblock * * Parameters: * (OUT) sb - pointer to the super block * * (IN) fsi - pointer to the axfs_fill_super_info struct * * Returns: * 0 or error number * *****************************************************************************/ static int axfs_do_fill_super(struct super_block *sb, struct axfs_fill_super_info *fsi) { struct axfs_super_incore *sbi; struct axfs_super_onmedia *sbo; #if 0 u32 * pointer; /* REMOVEME */ int i; #endif sbo = fsi->onmedia_super_block; sbi = AXFS_SB(sb); #if 0 /* REMOVEME */ printk("AXFS super block dump\n"); pointer = (u32 *)sbo; for (i=0; i<128; i+=4) { printk("0x%06X: %08X %08X %08X %08X\n", (4*i), pointer[i], pointer[i+1], pointer[i+2], pointer[i+3]); } #endif /* Do sanity checks on the superblock */ if (be32_to_cpu(sbo->magic) != AXFS_MAGIC) { printk(KERN_ERR "axfs: wrong magic\n"); goto out; } /* verify the signiture is correct */ if (strncmp(sbo->signature, AXFS_SIGNATURE, sizeof(AXFS_SIGNATURE))) { printk(KERN_ERR "axfs: wrong axfs signature, read %s, expected %s\n", sbo->signature, AXFS_SIGNATURE); goto out; } sbi->magic = be32_to_cpu(sbo->magic); sbi->version_major = sbo->version_major; sbi->version_minor = sbo->version_minor; sbi->version_sub = sbo->version_sub; sbi->files = be64_to_cpu(sbo->files); sbi->size = be64_to_cpu(sbo->size); sbi->blocks = be64_to_cpu(sbo->blocks); sbi->mmap_size = be64_to_cpu(sbo->mmap_size); sbi->cblock_size = be32_to_cpu(sbo->cblock_size); if(fill_helper(sb, sbo->strings, sbi->strings, TRUE)) goto out; if(fill_helper(sb, sbo->xip, sbi->xip, TRUE)) goto out; if(fill_helper(sb, sbo->compressed, sbi->compressed, FALSE)) goto out; if(fill_helper(sb, sbo->byte_aligned, sbi->byte_aligned, FALSE)) goto out; if(fill_helper(sb, sbo->node_type, sbi->node_type, TRUE)) goto out; if(fill_helper(sb, sbo->node_index, sbi->node_index, TRUE)) goto out; if(fill_helper(sb, sbo->cnode_offset, sbi->cnode_offset, TRUE)) goto out; if(fill_helper(sb, sbo->cnode_index, sbi->cnode_index, TRUE)) goto out; if(fill_helper(sb, sbo->banode_offset, sbi->banode_offset, TRUE)) goto out; if(fill_helper(sb, sbo->cblock_offset, sbi->cblock_offset, TRUE)) goto out; if(fill_helper(sb, sbo->inode_file_size, sbi->inode_file_size, TRUE)) goto out; if(fill_helper(sb, sbo->inode_name_offset, sbi->inode_name_offset, TRUE)) goto out; if(fill_helper(sb, sbo->inode_num_entries, sbi->inode_num_entries, TRUE)) goto out; if(fill_helper(sb, sbo->inode_mode_index, sbi->inode_mode_index, TRUE)) goto out; if(fill_helper(sb, sbo->inode_array_index, sbi->inode_array_index, TRUE)) goto out; if(fill_helper(sb, sbo->modes, sbi->modes, TRUE)) goto out; if(fill_helper(sb, sbo->uids, sbi->uids, TRUE)) goto out; if(fill_helper(sb, sbo->gids, sbi->gids, TRUE)) goto out; axfs_fill_metadata_ptrs(sbi); init_rwsem(&sbi->lock); /* Semaphore for kernel premetion */ return 0; out: return -EINVAL; }