hmmer-3.3/easel/esl_hyperexp.c
/* Function:  esl_hxp_FitComplete()
 *
 * Purpose:   Given a vector of <n> observed data samples <x[]> 
 *            (sorted or unsorted), and an initial guess <h> for
 *            a hyperexponential, find maximum likelihood parameters
 *            by conjugate gradient descent optimization, starting
 *            from <h> and leaving the final optimized solution in
 *            <h>.
 *            
 * Returns:   <eslOK> on success, and <h> contains the fitted 
 *            hyperexponential parameters.
 *            
 * Throws:    <eslEMEM> on allocation error, and <h> is left in
 *            in its initial state.           
 */
esl_hxp_FitComplete()
Purpose:   Given a vector of  observed data samples 
(sorted or unsorted), and an initial guess  for
a hyperexponential, find maximum likelihood parameters
by conjugate gradient descent optimization, starting
from  and leaving the final optimized solution in
.

 on success, and  contains the fitted
hyperexponential parameters.

 on allocation error, and  is left in
in its initial state.
esl_hxp_FitComplete () Purpose : Given a vector of observed data samples ( sorted or unsorted ) and an initial guess for a hyperexponential find maximum likelihood parameters by conjugate gradient descent optimization starting from and leaving the final optimized solution in . on success and contains the fitted hyperexponential parameters . on allocation error and is left in in its initial state .
int
esl_hxp_FitComplete(double *x, int n, ESL_HYPEREXP *h)
{
  struct hyperexp_data data;
  double *p   = NULL;
  int     np;
  double  fx;
  int     i;
  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.x   = x;
  data.n   = n;
  data.h   = h;
  hyperexp_pack_paramvector(p, np, h);
  status = esl_min_ConjugateGradientDescent(NULL, p, np, 
					    &hyperexp_complete_func, 
					    &hyperexp_complete_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_FitComplete ( double * x , int n , ESL_HYPEREXP * h ) { struct hyperexp_data data ; double * p = NULL ; int np ; double fx ; int i ; 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 . x = x ; data . n = n ; data . h = h ; hyperexp_pack_paramvector ( p , np , h ) ; status = esl_min_ConjugateGradientDescent ( NULL , p , np , & hyperexp_complete_func , & hyperexp_complete_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_FitComplete()
 Purpose:   Given a vector of <n> observed data samples <x[]>
            (sorted or unsorted), and an initial guess <h> for
            a hyperexponential, find maximum likelihood parameters
            by conjugate gradient descent optimization, starting
            from <h> and leaving the final optimized solution in
            <h>.
Function : esl_hxp_FitComplete () Purpose : Given a vector of <n > observed data samples <x [] > ( sorted or unsorted ) and an initial guess <h > for a hyperexponential find maximum likelihood parameters by conjugate gradient descent optimization starting from <h > and leaving the final optimized solution in <h > .
/* Determine number of free parameters and allocate */ /* 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
   */