示例#1
0
文件: sta_aux.c 项目: gitgun/dLabPro
/**
 * Fills a data table with the sample size (frequency) or the estimated a-priori
 * probability of the classes.
 *
 * @param _this
 *          Pointer to this CStatistics instance
 * @param idDst
 *          Pointer to the destination data instance
 * @param bProb
 *          If <code>TRUE</code> the method estimates class a-priori
 *          probabilities otherwise it stores the classes' sample sizes
 * @return <code>O_K</code> if successsfull, a (negative) error code otherwise
 */
INT16 CGEN_PUBLIC CStatistics_FreqEx
(
  CStatistics* _this,
  CData*       idDst,
  BOOL         bProb
)
{
  INT32    c     = 0;                                                            /* Class loop counter                */
  INT32    C     = 0;                                                            /* Number of statistics classes      */
  INT32    nTsz  = 0;                                                            /* Total sample size                 */
  FLOAT64* lpSsz = NULL;                                                         /* Pointer to class' c sample size   */

  /* Validate */                                                                /* --------------------------------- */
  if (!idDst) return IERROR(_this,ERR_NULLARG,"idDst",0,0);                     /* Check output data instance        */
  CData_Reset(idDst,TRUE);                                                      /* Clear destination instance        */
  CHECK_THIS_RV(NOT_EXEC);                                                      /* Check this pointer                */
  IF_NOK(CStatistics_Check(_this))                                              /* Check instance data               */
    return IERROR(_this,STA_NOTSETUP," ( use -status for details)",0,0);        /* ...                               */

  /* Initialize */                                                              /* --------------------------------- */
  C = CStatistics_GetNClasses(_this);                                           /* Get number of statistics classes  */
  CData_Array(idDst,T_DOUBLE,1,C);                                              /* Allocate output data instance     */
  CData_SetNBlocks(idDst,C);                                                    /* Set block number                  */
  if (!CData_XAddr(idDst,0,0)) return IERROR(_this,ERR_NOMEM,0,0,0);            /* Should have been successfull ...  */

  /* Store sample sizes / estimated a-rpior probabilities */                    /* --------------------------------- */
  nTsz = bProb ? CStatistics_GetNSamples(_this) : 1;                            /* Get frequency divident            */
  for (c=0; c<C; c++)                                                           /* Loop over classes                 */
  {                                                                             /* >>                                */
    DLPASSERT((lpSsz = CStatistics_GetPtr(_this,c,STA_DAI_SSIZE)));             /*   Get ptr. to class' c sample size*/
    CData_Dstore(idDst,lpSsz[0]/(FLOAT64)nTsz,c,0);                              /*   Store sample size of class c    */
  }                                                                             /* <<                                */

  return O_K;
}
示例#2
0
/**
 *  Convert f0-contour with equal spaced sampling points to pitch markers.
 *
 * @param idSrc        source f0-contour
 * @param idDst        target pitch marker
 * @param n            target sum of pitch marker lengths
 * @param srate        sampling rate
 * @return O_K if sucessfull, not exec otherwise
 */
INT16 CGEN_PUBLIC CPMproc::F02pm(CData *idSrc, CData* idDst, INT32 n, INT32 srate) {

  INT16* p_pm = NULL;
  INT32    n_pm = 0;

  if(CData_IsEmpty(idSrc) == TRUE) return NOT_EXEC;
  if(n <= 0)                       return NOT_EXEC;

  DLPASSERT(CData_GetNComps(idSrc) == 1);

  CREATEVIRTUAL(CData,idSrc,idDst);

  CData_Reset(idDst, TRUE);

  dlm_f02pm((FLOAT64*)idSrc->XAddr(0,0), idSrc->GetNRecs(), &p_pm, &n_pm, n, srate);

  CData_AddComp(idDst, "pm",   T_SHORT);
  CData_AddComp(idDst, "v/uv", T_SHORT);
  CData_Allocate(idDst, n_pm);
  ISETFIELD_RVALUE(idDst, "fsr", 1000.0/srate);

  dlp_memmove(idDst->XAddr(0,0), p_pm, 2*n_pm*sizeof(INT16));

  /* clean up */
  DESTROYVIRTUAL(idSrc,idDst)

  dlp_free(p_pm);

  return(O_K);
}
示例#3
0
/**
 *  Expand/reduce number of pitch markers to fit new target sum of period length.
 *
 * @param idSrc        source object
 * @param idDst        target object
 * @param n            target length
 * @return O_K if sucessfull, not exec otherwise
 */
INT16 CGEN_PUBLIC CPMproc::ExpandPm(CData *idSrc, CData* idDst, INT32 n)
{
  if(CData_IsEmpty(idSrc) == TRUE) return NOT_EXEC;
  if(n <= 0)                       return NOT_EXEC;

  CREATEVIRTUAL(CData,idSrc,idDst);

  DLPASSERT(CData_GetNComps(idSrc) == 2);

  CData_Reset(idDst, TRUE);
  CData_Scopy(idDst,idSrc);

  INT32    nRecsNew = 0;
  INT32    nRecs    = (INT32)CData_GetNRecs(idSrc);
  INT16* pm_new = NULL;

  if(dlm_pm_expand((INT16*)CData_XAddr(idSrc,0,0), nRecs, &pm_new, &nRecsNew, n) != O_K) {
    return IERROR(this,ERR_NULLARG, "", NULL, NULL);
  }
  CData_Allocate(idDst,nRecsNew);
  dlp_memmove(CData_XAddr(idDst,0,0), pm_new, nRecsNew*2*sizeof(INT16));
  dlp_free(pm_new);
  CData_CopyDescr(idDst,idSrc);

  /* clean up */
  DESTROYVIRTUAL(idSrc,idDst)

  return(O_K);
}
示例#4
0
/**
 *  Expand/reduce number of pitch markers to new number.
 *
 * @param idSrc        source object
 * @param idDst        target object
 * @param n            target number of pitch markers
 * @return O_K if sucessfull, not exec otherwise
 */
INT16 CGEN_PUBLIC CPMproc::CompressPm(CData *idSrc, CData* idDst, INT32 n)
{
  if(CData_IsEmpty(idSrc) == TRUE) return NOT_EXEC;
  if(n <= 0)                       return NOT_EXEC;

  CREATEVIRTUAL(CData,idSrc,idDst);

  DLPASSERT(CData_GetNComps(idSrc) == 2);
  CData_Reset(idDst, TRUE);
  CData_Scopy(idDst,idSrc);
  CData_Allocate(idDst, n);

  if(dlm_pm_compress((INT16*)CData_XAddr(idSrc,0,0),
                     CData_GetNRecs(idSrc),
                     (INT16*)CData_XAddr(idDst,0,0),
                     CData_GetNRecs(idDst)) != O_K) {
    return IERROR(this,ERR_NULLARG, "", NULL, NULL);
  }
  CData_CopyDescr(idDst,idSrc);

  /* clean up */
  DESTROYVIRTUAL(idSrc,idDst)

  return(O_K);
}
示例#5
0
/**
 *  Add periods to reach desired sum od periods.
 *
 * @param idSrc        source object
 * @param idDst        target object
 * @param n            target number of pitch markers
 * @param method       fill method
 * @return O_K if sucessfull, not exec otherwise
 */
INT16 CGEN_PUBLIC CPMproc::Fill(CData *idSrc, CData* idDst, INT32 n, const char* method)
{
  INT32       i               = 0;
  INT32       n_new           = 0;
  INT32       sum             = 0;
  INT16      mean_s          = 0;
  FLOAT64     mean            = 0.0;
  const char* method_default = "mean";

  if(CData_IsEmpty(idSrc) == TRUE) return NOT_EXEC;
  if(n <= 0)                       return NOT_EXEC;
  if(method == NULL)               method = method_default;

  CREATEVIRTUAL(CData,idSrc,idDst);

  DLPASSERT(CData_GetNComps(idSrc) == 2);
  CData_Reset(idDst, TRUE);
  CData_Copy(idDst,idSrc);

  for(i = 0; i < idSrc->GetNRecs(); i++) {
    sum += (INT32)idSrc->Dfetch(i,0);
  }

  if(!strcmp(method, "mean")) {
    mean = (FLOAT64)sum / (FLOAT64)idSrc->GetNRecs();
    n_new = (INT32)((FLOAT64)(n-sum) / mean);
    if(n_new >= 0) {
      n_new = MAX(n_new,1);
      i = idDst->GetNRecs();
      idDst->AddRecs(n_new, 1);
      while((sum<n) && (i < idDst->GetNRecs())) {
        mean_s = (INT16)((FLOAT64)(n-sum) / (FLOAT64)(idDst->GetNRecs()-i));
        idDst->Dstore(mean_s,i,0);
        idDst->Dstore(0,i,1);
        i++;
        sum += mean_s;
      }
    }
  }

  while((n-sum) > idDst->Dfetch(idDst->GetNRecs()-1,0)) {
    sum -= (INT32)idDst->Dfetch(idDst->GetNRecs()-1,0);
    idDst->Delete(idDst,idDst->GetNRecs()-1,1);
  }
  idDst->Dstore(idDst->Dfetch(idDst->GetNRecs()-1,0)-(sum-n),idDst->GetNRecs()-1,0);

  CData_CopyDescr(idDst,idSrc);

  /* clean up */
  DESTROYVIRTUAL(idSrc,idDst)

  return(O_K);
}
示例#6
0
文件: file.c 项目: thias42/dLabPro
INT16 CDlpFile_OnFlistChanged(CDlpObject* __this)
{
	GET_THIS_VIRTUAL_RV(CDlpFile,NOT_EXEC);
	{
    CData_Reset(_this->m_idFlistData, TRUE);
    if(dlp_strlen(_this->m_lpsFlist))
    {
      ISETOPTION(_this,"/strings");
      CDlpFile_Import(_this,_this->m_lpsFlist,"ascii",_this->m_idFlistData);
      IRESETOPTIONS(_this);
      _this->m_nLen = CData_GetNRecs(AS(CData,_this->m_idFlistData));
    }
    else _this->m_nLen = 0;
    _this->m_nNfile = -1;
	}

	return O_K;
}
示例#7
0
/**
 * Import midi notes of a midifile into data, needs external program midiconvert
 *
 * @param lpsFilename Name of file to import
 * @param iDst        Pointer to instance to import
 * @param lpsFiletype Type of file to import
 * @return <code>O_K</code> if successful, a (negative) error code otherwise
 */
INT16 CGEN_PROTECTED CDlpFile_Midi_ImportMidi
(
  CDlpFile*   _this,
  const char* lpsFilename,
  CDlpObject* iDst,
  const char* lpsFiletype
)
{
   char  lpsTempFile[L_PATH];
   char  lpsCmdline    [3*L_PATH] = "";
   INT16 nErr                     =O_K;

   strcpy(lpsTempFile,dlp_tempnam(NULL,"dlabpro_midi_import"));
   sprintf(lpsCmdline,"midiconvert %s %s", lpsFilename, lpsTempFile);

   if (system(lpsCmdline)!=0) { nErr=IERROR(_this,FIL_EXEC,lpsCmdline,0,0); }
   else {
      CData *idDst = AS(CData,iDst);
      /*Prepare data*/
      CData_Reset(iDst,TRUE);
      CData_AddComp(idDst,"CHAN",T_UCHAR);
      CData_AddComp(idDst,"VOL",T_UCHAR);
      CData_AddComp(idDst,"INST",T_UCHAR);
      CData_AddComp(idDst,"NOTE",T_UCHAR);
      CData_AddComp(idDst,"TIME",T_UINT);
      CData_AddComp(idDst,"LGTH",T_UINT);
      CData_AddComp(idDst,"VEL",T_UCHAR);
      /*import*/
      IF_NOK(CDlpFile_ImportAsciiToData(_this,lpsTempFile,iDst,"csv"))
        nErr = IERROR(iDst,FIL_IMPORT,lpsTempFile,"csv",0);
      /*Set midifilter specific data descriptions and clean data*/
      CData_SetDescr(idDst, DESCR0, CData_Dfetch(idDst,0,5));
      CData_DeleteRecs(idDst,0,1);
   }
   if (remove(lpsTempFile)==-1) nErr=IERROR(_this,FIL_REMOVE,"temporary ",lpsTempFile,0);
   /* Clean up */
   return nErr;
}
示例#8
0
/**
 *  Convert (unequal spaced) pitch markers to f0-contour with equal spaced
 * sampling points.
 *
 * @param idSrc        source pitch marks
 * @param idDst        target fo-contour
 * @param n            target number of sampling points of f0-contour
 * @param srate        sampling rate
 * @return O_K if sucessfull, not exec otherwise
 */
INT16 CGEN_PUBLIC CPMproc::Pm2f0(CData *idSrc, CData* idDst, INT32 n, INT32 srate) {

  if(CData_IsEmpty(idSrc) == TRUE) return NOT_EXEC;
  if(n <= 0)                       return NOT_EXEC;

  DLPASSERT(CData_GetNComps(idSrc) == 2);

  CREATEVIRTUAL(CData,idSrc,idDst);

  CData_Reset(idDst, TRUE);
  CData_AddComp(idDst, "~F0", T_DOUBLE);

  CData_Allocate(idDst, n);

  dlm_pm2f0((INT16*)idSrc->XAddr(0,0), idSrc->GetNRecs(), (FLOAT64*)idDst->XAddr(0,0), idDst->GetNRecs(), srate);

  ISETFIELD_RVALUE(idDst, "fsr", 1000.0/srate);

  /* clean up */
  DESTROYVIRTUAL(idSrc,idDst)

  return(O_K);
}
示例#9
0
文件: sta_reo.c 项目: gitgun/dLabPro
/*
 * Manual page at statistics.def
 */
INT16 CGEN_PUBLIC CStatistics_Pool
(
  CStatistics* _this,
  CStatistics* iSrc,
  CData*       idMap
)
{
  INT32   i          = 0;                                                        /* Current component index           */
  INT32   nC         = 0;                                                        /* Current pooled statistics class   */
  INT32   nCs        = 0;                                                        /* Current source class index        */
  INT32   nXC        = 0;                                                        /* Number of pooled classes          */
  INT32   nRpb       = 0;                                                        /* Statistics raw data block size    */
  INT16  nCheckSave = 0;                                                        /* Saved check level                 */
  CData* idAux      = NULL;                                                     /* Auxilary data instance #1         */
  CData* idPmp      = NULL;                                                     /* Pooling map                       */
  CData* idPcd      = NULL;                                                     /* Pooled class raw data buffer      */

  /* Initialize */                                                              /* --------------------------------- */
  CHECK_THIS_RV(0);                                                             /* Check this instance               */
  IF_NOK(CStatistics_Check(iSrc))                                               /* Check source statistics           */
    return IERROR(_this,ERR_INVALARG,"iSrc",0,0);                               /* ...                               */
  nCheckSave = _this->m_nCheck;                                                 /* Save check level                  */
  CStatistics_Reset(BASEINST(_this),TRUE);                                      /* Reset destination                 */
  _this->m_nCheck = nCheckSave;                                                 /* Restore check level               */
  IFIELD_RESET(CData,"dat");                                                    /* Create pool raw stats. data inst. */

  /* Protocol */                                                                /* --------------------------------- */
  IFCHECK                                                                       /* On verbose level 1                */
  {                                                                             /* >>                                */
    printf("\n"); dlp_fprint_x_line(stdout,'-',dlp_maxprintcols());             /*   Print protocol header           */
    printf("\n   statistics -pool");                                            /*   ...                             */
    printf("\n"); dlp_fprint_x_line(stdout,'-',dlp_maxprintcols());printf("\n");/*   ...                             */
  }                                                                             /* <<                                */

  /* No map --> pool all classes */                                             /* --------------------------------- */
  if (CData_IsEmpty(idMap))                                                     /* NULL or empty map instance        */
  {                                                                             /* >>                                */
    IFCHECK printf("\n   Empty pooling map --> pool all classes");              /*   Protocol (verbose level 1)      */
    CStatistics_PoolInt(_this->m_idDat,iSrc->m_idDat,0);                        /*   Pool sum data                   */
    CStatistics_PoolInt(_this->m_idDat,iSrc->m_idDat,1);                        /*   Pool min data                   */
    CStatistics_PoolInt(_this->m_idDat,iSrc->m_idDat,2);                        /*   Pool max data                   */
    STA_PROTOCOL_FOOTER(1,"done");                                              /*   Print protocol footer           */
    return O_K;                                                                 /*   That's it                       */
  }

  IFCHECK printf("\n   Pooling by map");                                        /* Protocol (verbose level 1)        */
  ICREATEEX(CData,idAux,"CStatistics_Pool.~idAux",NULL);                        /* Create auxilary data instance #1  */
  ICREATEEX(CData,idPmp,"CStatistics_Pool.~idPmp",NULL);                        /* Create pooling map                */
  ICREATEEX(CData,idPcd,"CStatistics_Pool.~idPcs",NULL);                        /* Create pooled raw stats.data inst.*/

  /* Find and copy map component (pooled class) */                              /* --------------------------------- */
  for (i=0; i<CData_GetNComps(idMap); i++)                                      /* Loop over components of idMap     */
    if (dlp_is_numeric_type_code(CData_GetCompType(idMap,i)))                   /*   Is current component numeric?   */
    {                                                                           /*   >> (Yes)                        */
      CData_SelectComps(idPmp,idMap,i,1);                                       /*     Copy component                */
      break;                                                                    /*     Have ready :)                 */
    }                                                                           /*   <<                              */
  if (CData_IsEmpty(idPmp))                                                     /* Have not got map component        */
  {                                                                             /* >>                                */
    IERROR(_this,STA_BADCOMP,"map",BASEINST(idMap)->m_lpInstanceName,"numeric");/*   Error message                   */
    DLPTHROW(STA_BADCOMP);                                                      /*   Throw exception                 */
  }                                                                             /* <<                                */

  /* Create source class component */                                           /* --------------------------------- */
  CData_AddComp(idPmp,"srcc",T_LONG);                                           /* Add source class index component  */
  for (i=0; i<CData_GetNRecs(idPmp); i++) CData_Dstore(idPmp,i,i,1);            /* Fill it                           */

  /* Finish pooling map and initialize pooling */                               /* --------------------------------- */
  CData_Sortup(idPmp,idPmp,0);                                                  /* Sort map by pooled class index    */
  nXC = (INT32)CData_Dfetch(idPmp,CData_GetNRecs(idPmp)-1,0)+1;                 /* Get greatest pooled class index   */
  IFCHECK printf("\n   Pooling %ld statistics classes",(long)nXC);              /* Protocol (verbose level 1)        */
  IFCHECKEX(3) CData_Print(idPmp);                                              /* Print pooling map (verbose lvl.3) */
  nRpb = CData_GetNRecsPerBlock(iSrc->m_idDat);                                 /* Get block size                    */

  /* Prepare pooled statistics */                                               /* --------------------------------- */
  CData_Scopy(_this->m_idDat,iSrc->m_idDat);                                    /* Create target raw data components */
  CData_Allocate(_this->m_idDat,nRpb*nXC);                                      /* Allocate target raw data          */
  CData_SetNBlocks(_this->m_idDat,nXC);                                         /* Set target statistics block number*/

  /* Pooling loop */                                                            /* --------------------------------- */
  for (i=0; i<CData_GetNRecs(idPmp); )                                          /* Loop over pooling map             */
  {                                                                             /* >>                                */
    /* - Copy raw statistics data of one pooled class */                        /*   - - - - - - - - - - - - - - - - */
    nC = (INT32)CData_Dfetch(idPmp,0,0);                                         /*   Get pooled class index          */
    IFCHECK printf("\n     Pooled class %3ld");                                 /*   Protocol (verbose level 1)      */
    for (i=0; i<CData_GetNRecs(idPmp); i++)                                     /*   Loop over partition of pool.map */
    {                                                                           /*   >>                              */
      if (nC != (INT32)CData_Dfetch(idPmp,0,0)) break;                           /*     Not the current class anymore */
      nCs = (INT32)CData_Dfetch(idPmp,i,1);                                      /*     Get source class index        */
      IFCHECK printf("\n     - Source class %3ld",nCs);                         /*     Protocol (verbose level 1)    */
      CData_SelectBlocks(idAux,iSrc->m_idDat,nCs,1);                            /*     Copy raw stats. data block    */
      CData_Cat(idPcd,idAux);                                                   /*     Append to buffer              */
    }                                                                           /*   <<                              */

    /* - Pool data */                                                           /*   - - - - - - - - - - - - - - - - */
    CData_SetNBlocks(idPcd,CData_GetNRecs(idPcd)/nRpb);                         /*   Set block count of aggr. buffer */
    IFCHECK                                                                     /*   Protocol (verbose level 1)      */
      printf("\n     - Aggregating %ld statistics classes",                     /*   |                               */
      (long)CData_GetNBlocks(idPcd));                                           /*   |                               */
    CStatistics_PoolInt(idAux,idPcd,0);                                         /*   Pool sum data                   */
    CStatistics_PoolInt(idAux,idPcd,1);                                         /*   Pool min data                   */
    CStatistics_PoolInt(idAux,idPcd,2);                                         /*   Pool max data                   */

    /* - Store pooled raw statistics data block */                              /*   - - - - - - - - - - - - - - - - */
    dlp_memmove                                                                 /*   Copy pooled raw stats. data     */
    (                                                                           /*   |                               */
      CData_XAddr(_this->m_idDat,nC*nRpb,0),                                    /*   | To target statistics block    */
      CData_XAddr(idAux,0,0),                                                   /*   | From aggregation buffer       */
      CData_GetNRecs(idAux)*CData_GetRecLen(idAux)                              /*   | Length of aggregation buffer  */
    );                                                                          /*   |                               */

    /* - Clean up auxilary instances */                                         /*   - - - - - - - - - - - - - - - - */
    CData_Reset(idPcd,TRUE);                                                    /*   Clear aggregation buffer        */
  }

  /* Clean up */                                                                /* --------------------------------- */
  IDESTROY(idAux);                                                              /* Destroy auxilary data instance #1 */
  IDESTROY(idPmp);                                                              /* Destroy pooling map               */
  IDESTROY(idPcd);                                                              /* Destroy pooled cls. raw data inst.*/
  STA_PROTOCOL_FOOTER(1,"done");                                                /* Print protocol footer             */
  return O_K;                                                                   /* Ok                                */

DLPCATCH(STA_BADCOMP)                                                           /* == Catch STA_BADCOMP exception    */
  IDESTROY(idAux);                                                              /* Destroy auxilary data instance #1 */
  IDESTROY(idPmp);                                                              /* Destroy pooling map               */
  IDESTROY(idPcd);                                                              /* Destroy pooled cls. raw data inst.*/
  STA_PROTOCOL_FOOTER(1,"FAILED");                                              /* Print protocol footer             */
  return NOT_EXEC;                                                              /* Not ok                            */
}
示例#10
0
文件: fst_ixp.c 项目: gitgun/dLabPro
/**
 * Appends units from a source automaton instance to this instance.
 *
 * @param _this      Pointer to destination automaton instance
 * @param itSrc      Pointer to source automaton instance
 * @param nFirstUnit Index of first unit of <code>itSrc</code> to append to this instance
 * @param nCount     Number of units to append
 * @return O_K if successfull, a (negative) error code otherwise
 */
INT16 CGEN_PUBLIC CFst_CatEx(CFst* _this, CFst* itSrc, INT32 nFirstUnit, INT32 nCount)
{
  INT32 nU    = 0;  /* Current unit */
  INT32 nXUd  = 0;  /* Number of units in destination */
  INT32 nFSs  = 0;  /* First source state to append */
  INT32 nXSs  = 0;  /* Number of source states to append */
  INT32 nFTs  = 0;  /* First source transition to append */
  INT32 nXTs  = 0;  /* Number of source transitions to append */
  INT32 nXXSd = 0;  /* Total number of states in destination */
  INT32 nXXTd = 0;  /* Total number of transitions in destination */

  /* Validate */
  CHECK_THIS_RV(NOT_EXEC);
  CFst_Check(_this);
  CFst_Check(itSrc);

  if (nFirstUnit        < 0            ) nFirstUnit = 0;
  if (nFirstUnit+nCount > UD_XXU(itSrc)) nCount     = UD_XXU(itSrc)-nFirstUnit;
  if (nCount            <=0            ) return NOT_EXEC;

  /* Initialize */
  CREATEVIRTUAL(CFst,itSrc,_this);

  /* If destination empty copy all properties from source */
  if (UD_XXU(_this)==0)
  {
    CFst_Copy(BASEINST(_this),BASEINST(itSrc));
    CData_SetNRecs(AS(CData,_this->ud),0);
    CData_SetNRecs(AS(CData,_this->sd),0);
    CData_SetNRecs(AS(CData,_this->td),0);
    CData_Reset(_this->is,0);
    CData_Reset(_this->os,0);
  }

  /* Get some metrics */
  nXUd  = UD_XXU(_this);
  nXXSd = UD_XXS(_this);
  nXXTd = UD_XXT(_this);
  nFSs  = UD_FS(itSrc,nFirstUnit);
  nFTs  = UD_FT(itSrc,nFirstUnit);
  for (nU=nFirstUnit,nXSs=0,nXTs=0; nU<nFirstUnit+nCount; nU++)
  {
    nXSs+=UD_XS(itSrc,nU);
    nXTs+=UD_XT(itSrc,nU);
  }

  /* Cat descriptor tables */
  CDlpTable_CatEx(AS(CData,_this->ud)->m_lpTable,AS(CData,itSrc->ud)->m_lpTable,nFirstUnit,nCount);
  CDlpTable_CatEx(AS(CData,_this->sd)->m_lpTable,AS(CData,itSrc->sd)->m_lpTable,nFSs      ,nXSs  );
  CDlpTable_CatEx(AS(CData,_this->td)->m_lpTable,AS(CData,itSrc->td)->m_lpTable,nFTs      ,nXTs  );

  /* Adjust unit descriptions */
  for (nU=nXUd; nU<nXUd+nCount; nU++)
  {
    UD_FS(_this,nU) += (nXXSd-nFSs);
    UD_FT(_this,nU) += (nXXTd-nFTs);
  }

  /* Copy input and output symbol table components */
  if(!IS_XXS(_this) && IS_XXS(itSrc)) CData_Copy(_this->is,itSrc->is);
  if(!OS_XXS(_this) && OS_XXS(itSrc)) CData_Copy(_this->os,itSrc->os);

  /* Finalize */
  DESTROYVIRTUAL(itSrc,_this);
  CFst_Check(_this); /* TODO: Remove after debugging */
  return O_K;
}
示例#11
0
文件: fst_xsr.c 项目: gitgun/dLabPro
/*
 * Manual page at fst_man.def
 */
INT16 CGEN_PUBLIC CFst_Rcs(CFst* _this, INT32 nUnit, FLOAT64 nSeed)
{
#ifdef __UNENTANGLE_FST

  return IERROR(_this,FST_INTERNAL,__FILE__,__LINE__,0);
  /* NOTE: __UNENTANGLE_FST was defined (probably in dlp_config.h or fst.def).
   *       Undefine it to use this feature!
   */

#else /* #ifdef __UNENTANGLE_FST */

  INT32      nU     = 0;                                                        /* Current unit                       */
  FST_ITYPE nS     = 0;                                                        /* Current state                      */
  FST_ITYPE nS2    = 0;                                                        /* Current state                      */
  FST_ITYPE nFS    = 0;                                                        /* First state of current unit        */
  FST_ITYPE nXS    = 0;                                                        /* Number of states of current unit   */
  FST_ITYPE nT     = 0;                                                        /* Current transition                 */
  FST_ITYPE nFT    = 0;                                                        /* First transition of current unit   */
  FST_ITYPE nXT    = 0;                                                        /* Number of tran. of current unit    */
  CData*    idP    = NULL;                                                     /* Incidence matrix                   */
  CData*    idB    = NULL;                                                     /* Constanct vector of (idP-E)idX=idB */
  CData*    idI    = NULL;                                                     /* idI = (idP-E)^-1                   */
  CData*    idX    = NULL;                                                     /* Solution of (idP-E)idX=idB         */
  FST_WTYPE nPSum  = 0.;                                                       /* Probability sum/state              */
  INT32      nIcW   = -1;                                                       /* Index of probability comp. in td   */
  INT32      nIcRcs = -1;                                                       /* Index of ref. counter comp. in sd  */
  INT32      nIcRct = -1;                                                       /* Index of ref. counter comp. in td  */

  /* Validation */
  CHECK_THIS_RV(NOT_EXEC);
  CFst_Check(_this);

  if (CFst_Wsr_GetType(_this,&nIcW)!=FST_WSR_PROB)
    return IERROR(_this,FST_MISS,"transition probability component",NC_TD_PSR,"transition table");

  /* Initialize - Find or add reference counters */
  nIcRcs = CData_FindComp(AS(CData,_this->sd),NC_SD_RC);
  nIcRct = CData_FindComp(AS(CData,_this->td),NC_TD_RC);
  if (nIcRcs<0)
  {
    CData_AddComp(AS(CData,_this->sd),NC_SD_RC,DLP_TYPE(FST_WTYPE));
    nIcRcs = CData_GetNComps(AS(CData,_this->sd))-1;
  }
  if (nIcRct<0)
  {
    CData_AddComp(AS(CData,_this->td),NC_TD_RC,DLP_TYPE(FST_WTYPE));
    nIcRct = CData_GetNComps(AS(CData,_this->td))-1;
  }

  /* Initialize - Create auxilary instances */
  ICREATEEX(CData,idP,"~CFst_Reverse.idP",NULL);
  ICREATEEX(CData,idB,"~CFst_Reverse.idB",NULL);
  ICREATEEX(CData,idI,"~CFst_Reverse.idI",NULL);
  ICREATEEX(CData,idX,"~CFst_Reverse.idX",NULL);

  /* Loop over units */
  for (nU=nUnit<0?0:nUnit; nU<UD_XXU(_this); nU++)
  {
    CData_Reset(BASEINST(idP),TRUE);
    CData_Reset(BASEINST(idB),TRUE);
    CData_Reset(BASEINST(idI),TRUE);
    CData_Reset(BASEINST(idX),TRUE);
    nFS = UD_FS(_this,nU);
    nXS = UD_XS(_this,nU);
    nFT = UD_FT(_this,nU);
    nXT = UD_XT(_this,nU);

    /* Export transposed ergodic incidence matrix */
    IF_NOK(CData_AddNcomps(idP,DLP_TYPE(FST_WTYPE),UD_XS(_this,nU)+1)) break;
    IF_NOK(CData_Allocate (idP,UD_XS(_this,nU)+1)                    ) break;
    IF_NOK(CData_AddNcomps(idB,DLP_TYPE(FST_WTYPE),1                )) break;
    IF_NOK(CData_Allocate (idB,UD_XS(_this,nU)+1)                    ) break;

    /* Fill transposed incidence matrix
       (summing up probabilities of parallel transitions) */
    for (nT=nFT; nT<nFT+nXT; nT++)
      *(FST_WTYPE*)CData_XAddr(idP,TD_TER(_this,nT),TD_INI(_this,nT)) +=
        *(FST_WTYPE*)CData_XAddr(AS(CData,_this->td),nT,nIcW);

    for (nS=0; nS<nXS; nS++)
    {
      if ((SD_FLG(_this,nS+nFS)&0x01)==0x01)     /* Connect final states with start state */
      {
        for (nS2=1, nPSum=0.; nS2<nXS; nS2++)
          nPSum += *(FST_WTYPE*)CData_XAddr(idP,nS2,nS);

        *(FST_WTYPE*)CData_XAddr(idP,0,nS) = 1.-nPSum;
      }

      *(FST_WTYPE*)CData_XAddr(idP,nS,nS)-=1.;   /* Subtract eigenvalue 1 from main diagonal */
      *(FST_WTYPE*)CData_XAddr(idP,nXS,nS)=1.;   /* Additional equation implementing constraint sum(P_state)=1 */
      *(FST_WTYPE*)CData_XAddr(idP,nS,nXS)=1.;   /* Additional variable making incidence matrix quadratic */
    }

    /* Fill constant vector */
    CData_Fill(idB,CMPLX(1.),CMPLX(0.));

    /* Calculate eigenvector of length 1 and eigenvalue 1
       --> stationary state probabilities */
    CMatrix_Op(idI,idP,T_INSTANCE,NULL,T_IGNORE,OP_INVT);
    CMatrix_Op(idX,idB,T_INSTANCE,idI,T_INSTANCE,OP_MULT);

    /* Fill in state reference counters */
    if (nSeed>0.) nSeed /= CData_Dfetch(idX,0,0); else nSeed = 1.;
    for (nS=0; nS<nXS; nS++)
      CData_Dstore(AS(CData,_this->sd),nSeed*CData_Dfetch(idX,nS,0),nS+nFS,nIcRcs);

    /* Calculate stationary transition probabilities */
    for (nT=nFT; nT<nFT+nXT; nT++)
      CData_Dstore
      (
        AS(CData,_this->td),
        CData_Dfetch(AS(CData,_this->sd),TD_INI(_this,nT)+nFS,nIcRcs) *
          CData_Dfetch(AS(CData,_this->td),nT,nIcW),
        nT,nIcRct
      );

    /* Clean up */
    IDESTROY(idP);
    IDESTROY(idB);
    IDESTROY(idI);
    IDESTROY(idX);

    /* Stop in single unit mode */
    if (nUnit>=0) break;
  }

  return O_K;

#endif /* #ifdef __UNENTANGLE_FST */
}