Пример #1
0
/*----------------------------------------------------------------isValidStart-+
| Determine how a proposed element fits within the current model.              |
|                                                                              |
| On Entry:                                                                    |
|   `pTknCurr'     points a primitive content token                            |
|   `ixElmGiven'   is a handle designating an element (-1 if #PCDATA)          |
|   `isInclusion'  is true if the element belongs to the inclusion list        |
|   `isExclusion'  is true if the element belongs to the exclusion list        |
|                  (both can be true!)                                         |
|                                                                              |
| When returning:                                                              |
|                                                                              |
|   Return code is: (see mdllctr.h for explanations)                           |
|     MDLLCTR_HIT                                                              |
|     MDLLCTR_MISSING                                                          |
|     MDLLCTR_INCLUDED                                                         |
|     MDLLCTR_EXCLUDED                                                         |
|     MDLLCTR_CLOSED                                                           |
|     MDLLCTR_UNCLOSABLE                                                       |
|     MDLLCTR_INTERNAL_ERROR                                                   |
|                                                                              |
| NOTE:                                                                        |
|    The current model we check against can never be EMPTY, #PCDATA:           |
|    - for EMPTY, caller opens and closes the element: not *really* stacked    |
|    - #PCDATA is never stacked.                                               |
|    In case of CDATA or RCDATA, this procedure is called just for <#PCDATA>,  |
|    i.e. ixElmGiven is -1 (PCDATA).  It cannot be a true element,             |
|    because STAGO is not recognized.                                          |
+-----------------------------------------------------------------------------*/
e_MdllctrStatus ModelLocator::isValidStart(
   int ixElmGiven,                            // Proposed element (-1: PCDATA)
   bool const isExclusion,
   bool const isInclusion
)
{
   if (!mdl.isModel()) {                      // declared content
      if (mdl.isAny()) {
         if (isExclusion) {
            return MDLLCTR_EXCLUDED;
         }else {
            return MDLLCTR_HIT;
         }
      }else {                                 // this should be DCDATA
         assert  (ixElmGiven == -1);
         return MDLLCTR_HIT;
      }
   }
   if (!pTknCurr) {                           // model has ended or it's Nil
      if (isInclusion) {
         return isExclusion? MDLLCTR_EXCLUDED : MDLLCTR_INCLUDED;
      }else {
         return MDLLCTR_CLOSED;
      }
   }

   e_MdllctrStatus st = MDLLCTR_HIT;
   do {                                       // get a prim content token
      while (pTknCurr->isGroup()) {
         reset_hits(pTknCurr);                // reset all hit bits
         pTknCurr = pTknCurr->child;          // grab the child
      }
      if (ixElmGiven == pTknCurr->ixElm) {    // Hit!
         if (
            (isExclusion) && (
               (pTknCurr->isOmissible()) || (pTknCurr->parent()->isOrGroup())
            )
         ) {
            st = MDLLCTR_EXCLUDED;            // Valid exclusion
         }
         find_another_candidate(true);
         return st;
      }
   }while (st = find_another_candidate(false), st == MDLLCTR_HIT);

   if (isInclusion) {
      return isExclusion? MDLLCTR_EXCLUDED : MDLLCTR_INCLUDED;
   }
   return st;
}
Пример #2
0
/* Initializes the starting temperature */
void init_starttemp(Annealing *search, int iter) {
  float mean = 0.0, stddev = 0.0;
  float score[iter];
  unsigned int wmcount = search->pssm_count;
  int i, wm;
  PSSM wms[wmcount];

  /* Backup WMs*/
  i = wmcount;
  while (i--) {
    wms[i] = clone_pssm(WM(i));
  }

  search->start_temp = HIGH_TEMP;

  /* FIX search all */
  i = wmcount * 2;
  while (i--) {
    g_pHitTable = search->hits[i];
    g_EndOfEntries = search->hittable_last[i];
    g_curSize = search->hittable_size[i];
    reset_hits();

    SESA_search(search->sesa,  search->wm[i]);

    /* If they are reallocated */
    search->hits[i] = g_pHitTable;
    search->hittable_size[i] = g_curSize;
    search->hittable_last[i] = g_EndOfEntries;
  }

  if (search->loglevel >= VERBOSE) {
    printf("Starting temp search \n");
  }

  i = iter - 1;
  score[i] = (*search->scorefunc)(search);

  wm = 0;
  while (i--) {
    if (wmcount == 2) wm = !wm;
    score[i] = anneal_step_wm(search, HIGH_TEMP, score[i+1], wm);
    mean += fabs(score[i+1] - score[i]);
  }

  if (search->loglevel >= VERBOSE) {
    printf("Stopping temp search\n");
  }

  mean /= (float) iter;

  i = iter;
  while (i--) stddev += (score[i] - mean) * (score[i] - mean);


  stddev /= iter;

  if (search->loglevel >= DBG) {
    printf("MEAN  : %f\n", mean);
    printf("VAR   : %f\n", stddev);
  }

  stddev = sqrt(stddev);

  if (search->loglevel >= DBG) 
    printf("STDDEV: %f\n", stddev);

  search->start_temp = (mean + (stddev * 0.85)) * -log(0.8);

  /* Restore WMs */
  i = wmcount;
  while (i--) {
    copy_pssm(wms[i], WM(i));
    free(wms[i]);
  }

}