hmmer-3.3/src/p7_hmm.c
/* Function:  p7_hmm_ScaleExponential()
 * Synopsis:  In a model containing counts, rescale counts by an exponential factor.
 *
 * Purpose:   Given a counts-based model <hmm>, scale core by an
 *            exponential factor <exp>. This should be thought of as
 *            an alternative to p7_hmm_Scale(). Let C_i be the total
 *            observed count in column i, and F be the scale. In
 *            p7_hmm_Scale, the updated total observed count would be
 *            C_i = C_i * F  (i.e. the scaling factor is uniform across
 *            all columns). In this function, C_i = C_i ^ F. The result
 *            is a non-uniform scaling across columns -- columns with
 *            higher C_i will be reduced to a greater extent than will
 *            columns with low counts.
 *
 *            Consider the case where one column has 30 observations and a
 *            bunch of others have 300. This can happen when heavily-
 *            fragmented sequences are used to reconstruct a family MSA, as
 *            in Dfam models ... but isn't likely to have been seen in Pfam
 *            alignments. Though the column with 30 observations isn't nearly
 *            as complete as the one with 300, it still has enough that we
 *            shouldn't be willing to discount the observations entirely -
 *            something that might happen if uniform entropy weighting needs
 *            to push the average observations down 10-fold in order to achieve
 *            the desired avg relative entropy.
 *            e.g.
 *
 *             C_i    F  ->  C_i
 *               3   .8      2.4
 *              30   .8       15
 *             300   .8       96
 *               3   .7      2.2
 *              30   .7       11
 *             300   .7       54
 *               3   .6      1.9
 *              30   .6      7.6
 *             300   .6       30
 *
 *            Note: the observed counts will never drop below 1 in this case.
 *
 *            After computing the per-column total scale for column i, that
 *            scale is applied to the core probability model emissions and
 *            transitions (<t>, <ins>, and <mat>) for position i.
 *
 * Args:      hmm     - counts based HMM.
 *            exp     - exponential factor; 1.0=no scaling.
 *            ret_scaleavg - returns the mean of the per-column scale factors corresponding
 *                           to the factor exp.
 *
 * Returns:   <eslOK> on success.
 */
p7_hmm_ScaleExponential()
Synopsis:  In a model containing counts, rescale counts by an exponential factor.

Given a counts-based model , scale core by an
exponential factor . This should be thought of as
an alternative to p7_hmm_Scale(). Let C_i be the total
observed count in column i, and F be the scale. In
p7_hmm_Scale, the updated total observed count would be
C_i = C_i * F  . In this function, C_i = C_i ^ F. The result
is a non-uniform scaling across columns -- columns with
higher C_i will be reduced to a greater extent than will
columns with low counts.

Consider the case where one column has 30 observations and a
bunch of others have 300. This can happen when heavily
fragmented sequences are used to reconstruct a family MSA, as
in Dfam models ... but isn't likely to have been seen in Pfam
alignments. Though the column with 30 observations isn't nearly
as complete as the one with 300, it still has enough that we
shouldn't be willing to discount the observations entirely
something that might happen if uniform entropy weighting needs
to push the average observations down 10-fold in order to achieve
the desired avg relative entropy.



the observed counts will never drop below 1 in this case.

After computing the per-column total scale for column i, that
scale is applied to the core probability model emissions and
transitions (, , and ) for position i.

hmm     - counts based HMM.
exp     - exponential factor; 1.0=no scaling.
ret_scaleavg - returns the mean of the per-column scale factors corresponding
to the factor exp.

 on success.
p7_hmm_ScaleExponential () Synopsis : In a model containing counts rescale counts by an exponential factor . Given a counts - based model scale core by an exponential factor . This should be thought of as an alternative to p7_hmm_Scale () . Let C_i be the total observed count in column i and F be the scale . In p7_hmm_Scale the updated total observed count would be C_i = C_i * F . In this function C_i = C_i ^ F . The result is a non - uniform scaling across columns -- columns with higher C_i will be reduced to a greater extent than will columns with low counts . Consider the case where one column has 30 observations and a bunch of others have 300 . This can happen when heavily fragmented sequences are used to reconstruct a family MSA as in Dfam models ... but isn ' t likely to have been seen in Pfam alignments . Though the column with 30 observations isn ' t nearly as complete as the one with 300 it still has enough that we shouldn ' t be willing to discount the observations entirely something that might happen if uniform entropy weighting needs to push the average observations down 10 - fold in order to achieve the desired avg relative entropy . the observed counts will never drop below 1 in this case . After computing the per - column total scale for column i that scale is applied to the core probability model emissions and transitions ( and ) for position i . hmm - counts based HMM . exp - exponential factor ; 1 . 0 = no scaling . ret_scaleavg - returns the mean of the per - column scale factors corresponding to the factor exp . on success .
int
p7_hmm_ScaleExponential(P7_HMM *hmm, double exp)
{
  int k;
  for (k = 1; k <= hmm->M; k++) {
    float count = esl_vec_FSum(hmm->mat[k], hmm->abc->K);
    float new_count = pow(count, exp);
    double scale = count>0 ? new_count / count : 1.0;  
    esl_vec_FScale(hmm->t[k],   p7H_NTRANSITIONS, scale);
    esl_vec_FScale(hmm->mat[k], hmm->abc->K,      scale);
    esl_vec_FScale(hmm->ins[k], hmm->abc->K,      scale);
  }
  return eslOK;
}
int p7_hmm_ScaleExponential ( P7_HMM * hmm , double exp ) { int k ; for ( k = 1 ; k <= hmm -> M ; k ++ ) { float count = esl_vec_FSum ( hmm -> mat [ k ] , hmm -> abc -> K ) ; float new_count = pow ( count , exp ) ; double scale = count > 0 ? new_count / count : 1.0 ; esl_vec_FScale ( hmm -> t [ k ] , p7H_NTRANSITIONS , scale ) ; esl_vec_FScale ( hmm -> mat [ k ] , hmm -> abc -> K , scale ) ; esl_vec_FScale ( hmm -> ins [ k ] , hmm -> abc -> K , scale ) ; } return eslOK ; }
Function:  p7_hmm_ScaleExponential()
 Synopsis:  In a model containing counts, rescale counts by an exponential factor.
Function : p7_hmm_ScaleExponential () Synopsis : In a model containing counts rescale counts by an exponential factor .
/* if no counts in the column (strange, but possible), just use default freqs*/