double COriginDragDlg::NormDampingSliderPos(double Damping)
{
    const CEditSliderCtrl::INFO&	info = m_SliderInfo[SL_DAMPING];
    double b = info.LogBase;
    double s = info.SliderScale;
    return(s - LogNorm(Damping, b, s));
}
/* Function: P7PriorifyEmissionVector()
 * 
 * Purpose:  Add prior pseudocounts to an observed 
 *           emission count vector and renormalize. 
 *
 *           Can return the posterior mixture probabilities
 *           P(q | counts) if ret_mix[MAXDCHLET] is passed.
 *           Else, pass NULL.  
 * 
 * Args:     vec     - the 4 or 20-long vector of counts to modify
 *           pri     - prior data structure
 *           num     - pri->mnum or pri->inum; # of mixtures
 *           eq      - pri->mq or pri->iq; prior mixture probabilities
 *           e       - pri->i or pri->m; Dirichlet components          
 *           ret_mix - filled with posterior mixture probabilities, or NULL
 *                   
 * Return:   (void)
 *           The counts in vec are changed and normalized to probabilities.
 */                  
void
P7PriorifyEmissionVector(float *vec, struct p7prior_s *pri, 
		       int num, float eq[MAXDCHLET], float e[MAXDCHLET][MAXABET],
		       float *ret_mix)
{
  int   x;                      /* counter over vec                     */
  int   q;                      /* counter over mixtures                */
  float mix[MAXDCHLET];         /* posterior distribution over mixtures */
  float totc;                   /* total counts                         */
  float tota;                   /* total alpha terms                    */
  float xi;                     /* X_i term, Sjolander eq. 41           */

  /* Calculate mix[], which is the posterior probability
   * P(q | n) of mixture component q given the count vector n
   *
   * (side effect note: note that an insert vector in a PAM prior
   * is passed with num = 1, bypassing pam prior code; this means
   * that inserts cannot be mixture Dirichlets...)
   * [SRE, 12/24/00: the above comment is cryptic! what the hell does that
   *  mean, inserts can't be mixtures? doesn't seem to be true. it 
   *  may mean that in a PAM prior, you can't have a mixture for inserts,
   *  but I don't even understand that. The insert vectors aren't passed
   *  with num=1!!]
   */
  mix[0] = 1.0;
  if (pri->strategy == PRI_DCHLET && num > 1) 
    {
      for (q = 0; q < num; q++) 
	{
	  mix[q] =  eq[q] > 0.0 ? log(eq[q]) : -999.;
	  mix[q] += Logp_cvec(vec, Alphabet_size, e[q]);
	}
      LogNorm(mix, num);      /* now mix[q] is P(component_q | n) */
    }
  else if (pri->strategy == PRI_PAM && num > 1) 
    {		/* pam prior uses aa frequencies as `P(q|n)' */
      for (q = 0; q < Alphabet_size; q++) 
	mix[q] = vec[q];
      FNorm(mix, Alphabet_size);
    }

  /* Convert the counts to probabilities, following Sjolander (1996) 
   */
  totc = FSum(vec, Alphabet_size);
  for (x = 0; x < Alphabet_size; x++) {
    xi = 0.0;
    for (q = 0; q < num; q++) {
      tota = FSum(e[q], Alphabet_size);
      xi += mix[q] * (vec[x] + e[q][x]) / (totc + tota);
    }
    vec[x] = xi;
  }
  FNorm(vec, Alphabet_size);

  if (ret_mix != NULL)
    for (q = 0; q < num; q++)
      ret_mix[q] = mix[q];
}
/* Function: P7PriorifyTransitionVector()
 * 
 * Purpose:  Add prior pseudocounts to transition vector,
 *           which contains three different probability vectors
 *           for m, d, and i. 
 *           
 * Args:     t     - state transitions, counts: 3 for M, 2 for I, 2 for D.   
 *           prior - Dirichlet prior information
 *           tq    - prior distribution over Dirichlet components.
 *                   (overrides prior->iq[]; used for alternative
 *                   methods of conditioning prior on structural data)  
 *           
 * Return:   (void)
 *           t is changed, and renormalized -- comes back as
 *           probability vectors.
 */          
void
P7PriorifyTransitionVector(float *t, struct p7prior_s *prior, 
			   float tq[MAXDCHLET])
{
  int   ts;
  int   q;
  float mix[MAXDCHLET];
  float totm, totd, toti;       /* total counts in three transition vecs */
  float xi;                     /* Sjolander's X_i term */

  mix[0] = 1.0;			/* default is simple one component */
  if ((prior->strategy == PRI_DCHLET || prior->strategy == PRI_PAM) && prior->mnum > 1)
    {
      for (q = 0; q < prior->tnum; q++)
        {
          mix[q] =  tq[q] > 0.0 ? log(tq[q]) : -999.;
          mix[q] += Logp_cvec(t,   3, prior->t[q]);   /* 3 match  */
          mix[q] += Logp_cvec(t+3, 2, prior->t[q]+3); /* 2 insert */
	  mix[q] += Logp_cvec(t+5, 2, prior->t[q]+5); /* 2 delete */
        }
      LogNorm(mix, prior->tnum); /* mix[q] is now P(q | counts) */
    }
				/* precalc some denominators */
  totm = FSum(t,3);		
  toti = t[TIM] + t[TII];
  totd = t[TDM] + t[TDD];

  for (ts = 0; ts < 7; ts++)  
    {
      xi = 0.0;
      for (q = 0; q < prior->tnum; q++)
        {
	  switch (ts) {
	  case TMM: case TMI: case TMD: 
	    xi += mix[q] * (t[ts] + prior->t[q][ts]) / 
	      (totm + FSum(prior->t[q], 3)); 
	    break;
	  case TIM: case TII: 
	    xi += mix[q] * (t[ts] + prior->t[q][ts]) / 
	      (toti + prior->t[q][TIM] + prior->t[q][TII]);
	    break;
	  case TDM: case TDD: 
	    xi += mix[q] * (t[ts] + prior->t[q][ts]) / 
	      (totd + prior->t[q][TDM] + prior->t[q][TDD]);
	    break;
	  }
        }
      t[ts] = xi;
    }
  FNorm(t,   3);		/* match  */
  FNorm(t+3, 2);		/* insert */
  FNorm(t+5, 2);		/* delete */
}
double CPosNormVal::Norm(double x) const
{
	return(LogNorm(x, m_LogBase, m_Scale));
}