hmmer-3.3/src/eweight.c
/* Function:  p7_EntropyWeight()
 * Incept:    SRE, Fri May  4 15:32:59 2007 [Janelia]
 *
 * Purpose:   Use the "entropy weighting" algorithm to determine
 *            what effective sequence number we should use, and
 *            return it in <ret_Neff>.
 *
 *            Caller provides a count-based <hmm>, and the
 *            Dirichlet prior <pri> that's to be used to parameterize
 *            models; neither of these will be modified.
 *            Caller also provides the relative entropy
 *            target in bits in <etarget>.
 *
 *            <ret_Neff> will range from 0 to the true number of
 *            sequences counted into the model, <hmm->nseq>.
 *
 * Returns:   <eslOK> on success.
 *
 * Throws:    <eslEMEM> on allocation failure.
 */


Use the "entropy weighting" algorithm to determine
what effective sequence number we should use, and
return it in .

Caller provides a count-based , and the
Dirichlet prior  that's to be used to parameterize
models; neither of these will be modified.
Caller also provides the relative entropy
target in bits in .

 will range from 0 to the true number of
sequences counted into the model, nseq>.

 on success.

 on allocation failure.
Use the " entropy weighting " algorithm to determine what effective sequence number we should use and return it in . Caller provides a count - based and the Dirichlet prior that ' s to be used to parameterize models ; neither of these will be modified . Caller also provides the relative entropy target in bits in . will range from 0 to the true number of sequences counted into the model nseq > . on success . on allocation failure .
int
p7_EntropyWeight(const P7_HMM *hmm, const P7_BG *bg, const P7_PRIOR *pri, double etarget, double *ret_Neff)
{
  int status;
  ESL_ROOTFINDER *R = NULL;
  struct ew_param_s p;
  double Neff;
  double fx;
  p.hmm = hmm;
  p.bg  = bg;
  p.pri = pri;
  if ((p.h2  = p7_hmm_Clone(hmm)) == NULL) return eslEMEM;
  p.etarget = etarget;
  Neff = (double) hmm->nseq;
  if ((status = eweight_target_f(Neff, &p, &fx)) != eslOK) goto ERROR;
  if (fx > 0.)
    {
      if ((R = esl_rootfinder_Create(eweight_target_f, &p)) == NULL) {status = eslEMEM; goto ERROR;}
      esl_rootfinder_SetAbsoluteTolerance(R, 0.01); 
      if ((status = esl_root_Bisection(R, 0., (double) hmm->nseq, &Neff)) != eslOK) goto ERROR;
      esl_rootfinder_Destroy(R);
    }
  p7_hmm_Destroy(p.h2);
  *ret_Neff = Neff;
  return eslOK;
 ERROR:
  if (p.h2 != NULL)   p7_hmm_Destroy(p.h2);
  if (R    != NULL)   esl_rootfinder_Destroy(R);
  *ret_Neff = (double) hmm->nseq;
  return status;
}
int p7_EntropyWeight ( const P7_HMM * hmm , const P7_BG * bg , const P7_PRIOR * pri , double etarget , double * ret_Neff ) { int status ; ESL_ROOTFINDER * R = NULL ; struct ew_param_s p ; double Neff ; double fx ; p . hmm = hmm ; p . bg = bg ; p . pri = pri ; if ( ( p . h2 = p7_hmm_Clone ( hmm ) ) == NULL ) return eslEMEM ; p . etarget = etarget ; Neff = ( double ) hmm -> nseq ; if ( ( status = eweight_target_f ( Neff , & p , & fx ) ) != eslOK ) goto ERROR ; if ( fx > 0. ) { if ( ( R = esl_rootfinder_Create ( eweight_target_f , & p ) ) == NULL ) { status = eslEMEM ; goto ERROR ; } esl_rootfinder_SetAbsoluteTolerance ( R , 0.01 ) ; if ( ( status = esl_root_Bisection ( R , 0. , ( double ) hmm -> nseq , & Neff ) ) != eslOK ) goto ERROR ; esl_rootfinder_Destroy ( R ) ; } p7_hmm_Destroy ( p . h2 ) ; * ret_Neff = Neff ; return eslOK ; ERROR : if ( p . h2 != NULL ) p7_hmm_Destroy ( p . h2 ) ; if ( R != NULL ) esl_rootfinder_Destroy ( R ) ; * ret_Neff = ( double ) hmm -> nseq ; return status ; }
Function:  p7_EntropyWeight()
 Incept:    SRE, Fri May  4 15:32:59 2007 [Janelia]
Function : p7_EntropyWeight () Incept : SRE Fri May 4 15 : 32 : 59 2007 [ Janelia ]
/* Store parameters in the structure we'll pass to the rootfinder
   */ /* getting Neff to ~2 sig digits is fine */