示例#1
0
extern void copy_theta(
  THETA s,	 		/* source */
  THETA d,			/* destination */
  int w,			/* width of motif */
  int alength			/* length of alphabet */
)
{ 
  int i, j;
  for (i = 0; i < w; i++) {		/* col in motif */
    for (j = 0; j < alength; j++) {	/* row in motif */
        theta_ref(d, i, j) = theta_ref(s, i, j);
    }
  }
}
示例#2
0
static BOOLEAN check_convergence(
  THETA	old_theta,			/* before EM iteration */
  THETA	new_theta,			/* after EM iteration */
  int w,				/* width of motif */
  double distance,			/* convergence radius */
  int alength, 				/* alphabet length */
  int iter,				/* current iteration number */
  int maxiter				/* maximum iterations */
)
{
  int i, j;
  double euclid;		/* distance between old_theta and new_theta */
  BOOLEAN converged;

  /* calculate the euclidean change in theta */
  euclid = 0;
  for(i=0; i<w; i++) {
    for(j=0; j<alength; j++) {
      double diff = theta_ref(old_theta, i, j) - theta_ref(new_theta, i, j);
      euclid += diff * diff;
    }
  }
  euclid = sqrt(euclid);
  if (PRINTALL || PRINT_LL) {ajFmtPrintF(outf," d_theta = %f\n", euclid);}

  if (euclid < distance) {		/* converged? */
    if (TRACE) printf("Converged to motif (< %g change) after %d iterations\n",
      distance, iter+1);
    converged = TRUE;
  } else if (maxiter > 1 && iter == maxiter - 1) {
    /* Use fprintf to print from all nodes in parallel. */
    if (TRACE) 
      fprintf(stdout, "Failed to converge after %d iterations!\n", maxiter);
    converged = FALSE;
  } else {
    converged = FALSE;
  }

  return converged;
}