hmmer-3.3/src/eweight.c
/* Function:  p7_EntropyWeight_exp()
 *
 * Purpose:   Use an alternative "entropy weighting" algorithm to
 *            determine the effective observed counts 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_exp> will range from 0 to 1.  This value will be used
 *            for each column to exponentially scale the observed counts.
 *            If a column has K (possibly weighted) observed letters, the
 *            scaled count will be K^ret_exp. This ensures that all scaled
 *            counts are at least 1.
 *
 *            See p7_hmm_ScaleExponential() for more details.
 *
 * Returns:   <eslOK> on success. 
 *
 * Throws:    <eslEMEM> on allocation failure.
 */
p7_EntropyWeight_exp()
Purpose:   Use an alternative "entropy weighting" algorithm to
determine the effective observed counts 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 1.  This value will be used
for each column to exponentially scale the observed counts.
If a column has K (possibly weighted) observed letters, the
scaled count will be K^ret_exp. This ensures that all scaled
counts are at least 1.

See p7_hmm_ScaleExponential() for more details.

 on success.

 on allocation failure.
p7_EntropyWeight_exp () Purpose : Use an alternative " entropy weighting " algorithm to determine the effective observed counts 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 1 . This value will be used for each column to exponentially scale the observed counts . If a column has K ( possibly weighted ) observed letters the scaled count will be K^ret_exp . This ensures that all scaled counts are at least 1 . See p7_hmm_ScaleExponential () for more details . on success . on allocation failure .
int
p7_EntropyWeight_exp(const P7_HMM *hmm, const P7_BG *bg, const P7_PRIOR *pri, double etarget, double *ret_exp)
{
  int status;
  ESL_ROOTFINDER *R = NULL;
  struct ew_param_s p;
  double exp = 1.;
  double fx;
  p.hmm = hmm;
  p.bg  = bg;
  p.pri = pri;
  if ((p.h2  = p7_hmm_Clone(hmm)) == NULL) return eslEMEM;
  p.etarget = etarget;
  if ((status = eweight_target_exp_f(1.0, &p, &fx)) != eslOK) goto ERROR;
  if (fx > 0.)
  {
      if ((R = esl_rootfinder_Create(eweight_target_exp_f, &p)) == NULL) {status = eslEMEM; goto ERROR;}
      esl_rootfinder_SetAbsoluteTolerance(R, 0.001); 
      if ((status = esl_root_Bisection(R, 0., 1.0, &exp)) != eslOK) goto ERROR;
      esl_rootfinder_Destroy(R);
  }
  p7_hmm_Destroy(p.h2);
  *ret_exp = exp;
  return eslOK;
 ERROR:
  if (p.h2 != NULL)   p7_hmm_Destroy(p.h2);
  if (R    != NULL)   esl_rootfinder_Destroy(R);
  return status;
}
int p7_EntropyWeight_exp ( const P7_HMM * hmm , const P7_BG * bg , const P7_PRIOR * pri , double etarget , double * ret_exp ) { int status ; ESL_ROOTFINDER * R = NULL ; struct ew_param_s p ; double exp = 1. ; double fx ; p . hmm = hmm ; p . bg = bg ; p . pri = pri ; if ( ( p . h2 = p7_hmm_Clone ( hmm ) ) == NULL ) return eslEMEM ; p . etarget = etarget ; if ( ( status = eweight_target_exp_f ( 1.0 , & p , & fx ) ) != eslOK ) goto ERROR ; if ( fx > 0. ) { if ( ( R = esl_rootfinder_Create ( eweight_target_exp_f , & p ) ) == NULL ) { status = eslEMEM ; goto ERROR ; } esl_rootfinder_SetAbsoluteTolerance ( R , 0.001 ) ; if ( ( status = esl_root_Bisection ( R , 0. , 1.0 , & exp ) ) != eslOK ) goto ERROR ; esl_rootfinder_Destroy ( R ) ; } p7_hmm_Destroy ( p . h2 ) ; * ret_exp = exp ; return eslOK ; ERROR : if ( p . h2 != NULL ) p7_hmm_Destroy ( p . h2 ) ; if ( R != NULL ) esl_rootfinder_Destroy ( R ) ; return status ; }
Function:  p7_EntropyWeight_exp()
 Purpose:   Use an alternative "entropy weighting" algorithm to
            determine the effective observed counts we should
            use, and return it in <ret_Neff>.
Function : p7_EntropyWeight_exp () Purpose : Use an alternative " entropy weighting " algorithm to determine the effective observed counts we should use and return it in <ret_Neff > .
/* Store parameters in the structure we'll pass to the rootfinder
   */ //Neff = (double) hmm->nseq; /* getting exp to ~3 sig digits is fine */