hmmer-3.3/easel/esl_hyperexp.c
/* Function:  esl_hxp_FitCompleteBinned()
 *
 * Purpose:   Given a histogram <g> with binned observations, where each
 *            bin i holds some number of observed samples x with values from 
 *            lower bound l to upper bound u (that is, $l < x \leq u$),
 *            and given a starting guess <h> for hyperexponential parameters;
 *
 *            Find maximum likelihood parameters <h> by conjugate gradient
 *            descent, starting from the initial <h> and leaving the
 *            optimized solution in <h>.
 *
 * Returns:   <eslOK> on success.
 *
 * Throws:    <eslEMEM> on allocation error, and <h> is left in its
 *            initial state.
 */
esl_hxp_FitCompleteBinned()
Purpose:   Given a histogram  with binned observations, where each
bin i holds some number of observed samples x with values from
lower bound l to upper bound u (that is, $l < x \leq u$),
and given a starting guess  for hyperexponential parameters.

Find maximum likelihood parameters  by conjugate gradient
descent, starting from the initial  and leaving the
optimized solution in .

 on success.

 on allocation error, and  is left in its
initial state.
esl_hxp_FitCompleteBinned () Purpose : Given a histogram with binned observations where each bin i holds some number of observed samples x with values from lower bound l to upper bound u ( that is $l < x \ leq u$ ) and given a starting guess for hyperexponential parameters . Find maximum likelihood parameters by conjugate gradient descent starting from the initial and leaving the optimized solution in . on success . on allocation error and is left in its initial state .
int 
esl_hxp_FitCompleteBinned(ESL_HISTOGRAM *g, ESL_HYPEREXP *h)
{
  struct hyperexp_binned_data data;
  double *p   = NULL;
  double  fx;
  int     i;
  int     np;
  int     status;
  np = 0;
  if (! h->fixmix) np = h->K-1;  
  for (i = 0; i < h->K; i++)     
    if (! h->fixlambda[i]) np++;
  ESL_ALLOC(p,   sizeof(double) * np);
  data.g     = g;
  data.h     = h;
  hyperexp_pack_paramvector(p, np, h);
  status = esl_min_ConjugateGradientDescent(NULL, p, np, 
					    &hyperexp_complete_binned_func, 
					    &hyperexp_complete_binned_gradient,
					    (void *) (&data), &fx, NULL);
  if (status != eslOK) goto ERROR;
  hyperexp_unpack_paramvector(p, np, h);
  free(p);
  esl_hyperexp_SortComponents(h);
  return eslOK;
 ERROR:
  free(p);
  return status;
}
int esl_hxp_FitCompleteBinned ( ESL_HISTOGRAM * g , ESL_HYPEREXP * h ) { struct hyperexp_binned_data data ; double * p = NULL ; double fx ; int i ; int np ; int status ; np = 0 ; if ( ! h -> fixmix ) np = h -> K - 1 ; for ( i = 0 ; i < h -> K ; i ++ ) if ( ! h -> fixlambda [ i ] ) np ++ ; ESL_ALLOC ( p , sizeof ( double ) * np ) ; data . g = g ; data . h = h ; hyperexp_pack_paramvector ( p , np , h ) ; status = esl_min_ConjugateGradientDescent ( NULL , p , np , & hyperexp_complete_binned_func , & hyperexp_complete_binned_gradient , ( void * ) ( & data ) , & fx , NULL ) ; if ( status != eslOK ) goto ERROR ; hyperexp_unpack_paramvector ( p , np , h ) ; free ( p ) ; esl_hyperexp_SortComponents ( h ) ; return eslOK ; ERROR : free ( p ) ; return status ; }
Function:  esl_hxp_FitCompleteBinned()
 Purpose:   Given a histogram <g> with binned observations, where each
            bin i holds some number of observed samples x with values from
            lower bound l to upper bound u (that is, $l < x \leq u$),
            and given a starting guess <h> for hyperexponential parameters;
Function : esl_hxp_FitCompleteBinned () Purpose : Given a histogram <g > with binned observations where each bin i holds some number of observed samples x with values from lower bound l to upper bound u ( that is $l < x \ leq u$ ) and given a starting guess <h > for hyperexponential parameters ;
/* K-1 mix coefficients...      */ /* ...and up to K lambdas free. */ /* Copy shared info into the "data" structure  */ /* From h, create the parameter vector. */ /* Feed it all to the mighty optimizer. */ /* Convert the final parameter vector back to a hyperexponential
   */