Exemplo n.º 1
0
/**
 * 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;
}
Exemplo n.º 2
0
/**
 * Checks the statistics' data (field m_idDat) for presence and consistency.
 *
 * @param _this
 *           Pointer to CStatistics instance
 * @return <code>O_K</code> if check successfull, a (negative) error code
 *         otherwise
 * @see dat m_idDat
 */
INT16 CGEN_PROTECTED CStatistics_CheckDat(CStatistics* _this)
{
  INT16 nType = 0;
  INT32  N     = 0;
  INT32  C     = 0;
  INT32  nXR   = 0;

  CHECK_THIS_RV(NOT_EXEC);
  IFCHECK printf("\n   Checking statistics data ...");
  IFCHECK printf("\n   - dat (statistics data): ");
  if (!_this->m_idDat)
  {
    IFCHECK printf("not present -> INVALID");
    return NOT_EXEC;
  }
  IFCHECK printf("present");
  nType = CData_IsHomogen(_this->m_idDat);
  IFCHECK  printf("\n     - Data type          : %ld ",(long)nType);
  if (nType!=T_DOUBLE)
  {
    IFCHECK
    {
      if (nType==0) printf("NOT HOMOGENOUS -> INVALID");
      else          printf("BAD TYPE, should be double");
    }
    return NOT_EXEC;
  }
Exemplo n.º 3
0
/**
 * Returns the parent of this instance in the instance tree.
 *
 * @param _this
 *          Pointer to this instance
 * @return The pointer to the root instance.
 */
CDlpObject* CDlpObject_GetRoot(CDlpObject* _this)
{
  CDlpObject* iParent = NULL;                                                   /* Pointer to parent instance        */
  CHECK_THIS_RV(NULL);                                                          /* Check this pointer                */
  iParent = CDlpObject_GetParent(_this);                                        /* Get parent                        */
  if (!iParent) return _this;                                                   /* No parent -> this is root         */
  return CDlpObject_GetRoot(iParent);                                           /* Go ask parent                     */
}
Exemplo n.º 4
0
/*
 * Manual page at fst_man.def
 */
INT16 CGEN_PUBLIC CFst_Cat(CFst* _this, CFst* itSrc)
{
  /* Validate */
  CHECK_THIS_RV(NOT_EXEC);
  CFst_Check(_this);
  CFst_Check(itSrc);

  return CFst_CatEx(_this,itSrc,0,UD_XXU(itSrc));
}
Exemplo n.º 5
0
/**
 * Returns the order of the statistics. The statistic's order <i>K</i> is the
 * greatest exponent <i>k</i> for which the statistics records sums up
 * <i>x<aup>k</sup></i>. The minimal order is two. The maximal order may be
 * specified using the {@link Setup CStatistics_Setup} method.
 *
 * @param _this
 *          Pointer to CStatistics instance
 * @return The order of the statistics or 0 in case of errors
 */
INT32 CGEN_PUBLIC CStatistics_GetOrder(CStatistics* _this)
{
  INT32 N    = 0;
  INT32 nRpb = 0;
  CHECK_THIS_RV(0);
  N    = CStatistics_GetDim(_this);
  nRpb = CData_GetNRecsPerBlock(_this->m_idDat);
  if (N<=0) return 0;
  return nRpb-N-2;
}
Exemplo n.º 6
0
/*
 * Manual page at statistics.def
 */
INT16 CGEN_PUBLIC CStatistics_Setup
(
  CStatistics*    _this,
  INT32         nOrder,
  INT32         nDim,
  INT32         nCls,
  CData*          idLtb,
  INT32         nIcLtb
)
{
  INT32    c     = 0;                                                         /* Statistics class loop counter     */
  INT32    n     = 0;                                                         /* Dimension loop couner             */
  FLOAT64* lpMin = NULL;                                                      /* Ptr. to class' k minimum vector   */
  FLOAT64* lpMax = NULL;                                                      /* Ptr. to class' k maximum vector   */

  /* Validate */                                                                /* --------------------------------- */
  CHECK_THIS_RV(NOT_EXEC);                                                      /* Check this pointer                */
  if (nOrder<2) nOrder = 2;                                                     /* Default order is 2                */
  if (nDim  <1) nDim   = 1;                                                     /* Default dimensionality is 1       */
  if (nCls  <1) nCls   = 1;                                                     /* Default number of classes is 1    */

  /* Initialize statistics */                                                   /* --------------------------------- */
  CStatistics_Reset(_this,TRUE);                                                /* Start over                        */
  IFIELD_RESET(CData,"dat");                                                    /* Create/reset statistic data       */
  CData_Array(_this->m_idDat,T_DOUBLE,nDim,nCls*(nOrder+nDim+2));               /* Allocate statistic data           */
  CData_SetNBlocks(_this->m_idDat,nCls);                                        /* Set number of blocks              */
  if (CData_IsEmpty(_this->m_idDat)) return IERROR(_this,ERR_NOMEM,0,0,0);      /* Check if it worked out...         */
  for (c=0; c<nCls; c++)                                                        /* Loop over classes                 */
  {                                                                             /* >>                                */
    lpMin = CStatistics_GetPtr(_this,c,STA_DAI_MIN);                            /*   Get ptr. to class' k min. vec.  */
    lpMax = CStatistics_GetPtr(_this,c,STA_DAI_MAX);                            /*   Get ptr. to class' k max. vec.  */
    for (n=0; n<nDim; n++)                                                      /*   Loop over dimensions            */
    {                                                                           /*   >>                              */
      lpMin[n] = T_DOUBLE_MAX;                                                  /*     Initialize minimum vector     */
      lpMax[n] = T_DOUBLE_MIN;                                                  /*     Initialize maximum vector     */
    }                                                                           /*   <<                              */
  }                                                                             /* <<                                */

  /* Initialize label table */                                                  /* --------------------------------- */
  if (CData_IsEmpty(idLtb)) return O_K;                                         /* No label table -> that's it       */
  if (CData_GetNRecs(idLtb)!=nCls)                                              /* Bad number of labels              */
    return IERROR(_this,STA_NOTSETUP," (wrong no. of labels in idLtb)",0,0);    /*   -> Error                        */
  if (nIcLtb<0)                                                                 /* Label component not specified     */
    for (nIcLtb=0; nIcLtb<CData_GetNComps(idLtb); nIcLtb++)                     /*   Seek first symbolic component   */
      if (dlp_is_symbolic_type_code(CData_GetCompType(idLtb,nIcLtb)))           /*   ...                             */
        break;                                                                  /*   ...                             */
  if (!dlp_is_symbolic_type_code(CData_GetCompType(idLtb,nIcLtb)))              /* Label component not symbolic      */
    return IERROR(_this,STA_NOTSETUP," (label comp. not found in idLtb)",0,0);  /*   -> Error                        */
  IFIELD_RESET(CData,"ltb");                                                    /* Create/reset label table          */
  CData_SelectComps(_this->m_idLtb,idLtb,nIcLtb,1);                             /* Copy label table                  */

  return O_K;                                                                   /* Done                              */
}
Exemplo n.º 7
0
/**
 * Returns the total sample size over all classes.
 *
 * @param _this
 *          Pointer to CStatistics instance
 * @return The total sample size
 */
INT32 CGEN_PUBLIC CStatistics_GetNSamples(CStatistics* _this)
{
  INT32    c     = 0;                                                            /* Statistics class loop counter     */
  INT32    nSsz  = 0;                                                            /* Total sample size                 */
  FLOAT64* lpSsz = NULL;                                                         /* Ptr. to class' k sample size      */
  CHECK_THIS_RV(0);                                                             /* Check this pointer                */
  for (c=0; c<CStatistics_GetNClasses(_this); c++)                              /* Loop over statistics classes      */
  {                                                                             /* >>                                */
    lpSsz = CStatistics_GetPtr(_this,c,STA_DAI_SSIZE);                          /*   Get ptr. to class' k sample size*/
    if (lpSsz) nSsz += (INT32)*lpSsz;                                            /*   Sum up                          */
  }                                                                             /* <<                                */
  return nSsz;
}
Exemplo n.º 8
0
/**
 * Returns a pointer to one of the data arrays of a statistics' class
 *
 * @param _this
 *           Pointer to CStatistics instance
 * @param c
 *           Statistics class index
 * @param nData
 *           Data array identifier, one of the <code>STA_DAI_XXX</code>
 *           constants
 * @return The pointer to the first double value of the desired array and class
 *         or <code>NULL</code> in case of errors.
 */
FLOAT64* CGEN_PRIVATE CStatistics_GetPtr(CStatistics* _this, INT32 c, INT16 nData)
{
  INT32 N    = 0;                                                               /* Statistics dimensionality         */
  INT32 nRpb = 0;                                                               /* Records per block                 */
  CHECK_THIS_RV(NULL);                                                          /* Check this pointer                */
  N    = CStatistics_GetDim(_this);                                             /* Get statistics dimensionality     */
  nRpb = CData_GetNRecsPerBlock(_this->m_idDat);                                /* Get records per block             */
  if (nData<STA_DAI_KSUM)                                                       /* Before k-th order sums            */
    return (FLOAT64*)CData_XAddr(_this->m_idDat,c*nRpb + nData,0);              /*   Return pointer to data          */
  else if (nData==STA_DAI_KSUM)                                                 /* k-th order sums                   */
    return (FLOAT64*)CData_XAddr(_this->m_idDat,c*nRpb + N+4,0);                /*   Return pointer to data          */
  else return NULL;                                                             /* Cannot happen                     */
}
Exemplo n.º 9
0
/*
 * Manual page at statistics.def
 */
INT16 CGEN_PUBLIC CStatistics_Merge(CStatistics* _this, CStatistics* iSrc)
{
	INT32   nB    = 0;                                                            /* Current block                     */
	INT32   nC    = 0;                                                            /* Current component                 */
	INT32   nR    = 0;                                                            /* Current record                    */
	INT32   nXB   = 0;                                                            /* Number of statistics blocks       */
	INT32   nXC   = 0;                                                            /* Number of components              */
	INT32   nXR   = 0;                                                            /* Number of records per block       */
	FLOAT64 nVal  = 0.;                                                           /* Merged statistics value           */
	FLOAT64 nVal1 = 0.;                                                           /* Statistics value of this instance */
	FLOAT64 nVal2 = 0.;                                                           /* Statistics value of source inst.  */

  /* Initialize */                                                              /* --------------------------------- */
  CHECK_THIS_RV(NOT_EXEC);                                                      /* Check this instance               */
  if (_this==iSrc) return O_K;                                                  /* Nothing to be done                */
  IF_NOK(CStatistics_Check(iSrc))                                               /* Check source statistics           */
    return IERROR(_this,ERR_INVALARG,"iSrc",0,0);                               /* ...                               */

  /* Check-up */                                                                /* --------------------------------- */
  nXB = CData_GetNBlocks      (AS(CData,_this->m_idDat));                       /* Get number of statistics blocks   */
  nXC = CData_GetNComps       (AS(CData,_this->m_idDat));                       /* Get number of components          */
  nXR = CData_GetNRecsPerBlock(AS(CData,_this->m_idDat));                       /* Get number of records per block   */
  if                                                                            /* Instances incompatible if ...     */
  (                                                                             /* |                                 */
    nXB != CData_GetNBlocks      (AS(CData,iSrc->m_idDat)) ||                   /* | ... no. of blocks mismatch   OR */
    nXC != CData_GetNComps       (AS(CData,iSrc->m_idDat)) ||                   /* | ... no. of comps. mismatch   OR */
    nXR != CData_GetNRecsPerBlock(AS(CData,iSrc->m_idDat))                      /* | ... no. of records mismatch     */
  )                                                                             /* |                                 */
  {                                                                             /* >>                                */
  	return IERROR(_this,STA_INCOMPAT,0,0,0);                                    /*   So sorry ...                    */
  }                                                                             /* <<                                */

  /* Do merge */                                                                /* --------------------------------- */
  for (nB=0; nB<nXB; nB++)                                                      /* Loop over blocks                  */
  	for (nR=0; nR<nXR; nR++)                                                    /*   Loop over records of block      */
  		for (nC=0; nC<nXC; nC++)                                                  /*     Loop over components          */
			{                                                                         /*     >>                            */
				nVal1 = CData_Dfetch(AS(CData,_this->m_idDat),nB*nXR+nR,nC);            /*       Get value from this         */
				nVal2 = CData_Dfetch(AS(CData,iSrc ->m_idDat),nB*nXR+nR,nC);            /*       Get value from source       */
				switch (nR)                                                             /*       Depending on value type     */
				{                                                                       /*       >>                          */
				case STA_DAI_MIN: nVal = MIN(nVal1,nVal2); break;                       /*         Aggregate minimums        */
				case STA_DAI_MAX: nVal = MAX(nVal1,nVal2); break;                       /*         Aggregate maximums        */
				default         : nVal = nVal1+nVal2;      break;                       /*         Aggregate all other       */
				}                                                                       /*       <<                          */
				CData_Dstore(AS(CData,_this->m_idDat),nVal,nB*nXR+nR,nC);               /*       Store merged value          */
			}                                                                         /*     <<                            */

  /* Aftermath */                                                               /* --------------------------------- */
  return O_K;                                                                   /* Everything's ok                   */
}
Exemplo n.º 10
0
/**
 * Converts the automaton weights to weights to another semiring.
 *
 * @param nSrType Semiring type (<code>FST_WSR_PROB</code>,
 *                <code>FST_WSR_LOG</code> or <code>FST_WSR_TROP</code>)
 * @return <code>O_K</code> if successfull, a (negative) error code otherwise
 */
INT16 CGEN_PUBLIC CFst_Wsr_Convert(CFst* _this, INT16 nSrType)
{
  INT16 nWsrt = FST_WSR_NONE;
  INT32  nIcW  = -1;
  INT32  nT    = 0;
  INT32  nXXT  = 0;
  INT32  nRlt  = 0;
  BYTE* lpW   = NULL;
  BYTE* lpW0  = NULL;

  /* Validation */                                                              /* --------------------------------- */
  CHECK_THIS_RV(NOT_EXEC);                                                      /* Check this pointer                */
  CFst_Check(_this);                                                            /* Check FST(s)                      */

  /* Initialize */                                                              /* --------------------------------- */
  nWsrt = CFst_Wsr_GetType(_this,&nIcW);                                        /* Get current weight semiring type  */
  if (nWsrt==FST_WSR_NONE) return IERROR(_this,FST_UNWEIGHTED,0,0,0);           /* No weights, no service            */
  if (nWsrt==nSrType     ) return O_K;                                          /* Nothing to be done                */
  lpW0 = CData_XAddr(AS(CData,_this->td),0,nIcW);                               /* Get pointer to weight component   */
  nRlt = CData_GetRecLen(AS(CData,_this->td));                                  /* Get record length of trans. list  */
  nXXT = UD_XXT(_this);                                                         /* Get total number of transitions   */

  /* Convert weights */                                                         /* --------------------------------- */
  switch (nSrType)                                                              /* Branch for target weight sr. type */
  {                                                                             /* >>                                */
  case FST_WSR_PROB:                                                            /* Probability semiring              */
    /* TODO: Push log/tropical weights to the left!!! */                        /* X X X X X X X X X X X X X X X X X */
    IERROR(_this,FST_INTERNALW,"Probabilities may be >1",__FILE__,__LINE__);    /* Warn user!                        */
    for (nT=0,lpW=lpW0; nT<nXXT; nT++,lpW+=nRlt)                                /* Loop over all transitions         */
      *(FST_WTYPE*)lpW = exp(*(FST_WTYPE*)lpW*-1);                              /*   P = exp(-w)                     */
    CData_SetCname(AS(CData,_this->td),nIcW,NC_TD_PSR);                         /*   Rename weight component         */
    break;                                                                      /* ==                                */
  case FST_WSR_LOG:                                                             /* Log semiring                      */
    if (nWsrt==FST_WSR_PROB)                                                    /* Converting from probabilities     */
      for (nT=0,lpW=lpW0; nT<nXXT; nT++,lpW+=nRlt)                              /*   Loop over all transitions       */
        *(FST_WTYPE*)lpW = -1*log(*(FST_WTYPE*)lpW);                            /*     w = -log(P)                   */
    CData_SetCname(AS(CData,_this->td),nIcW,NC_TD_LSR);                         /*   Rename weight component         */
    break;                                                                      /* ==                                */
  case FST_WSR_TROP:                                                            /* Topical semiring                  */
    if (nWsrt==FST_WSR_PROB)                                                    /* Converting from probabilities     */
      for (nT=0,lpW=lpW0; nT<nXXT; nT++,lpW+=nRlt)                              /*   Loop over all transitions       */
        *(FST_WTYPE*)lpW = -1*log(*(FST_WTYPE*)lpW);                            /*     w = -log(P)                   */
    CData_SetCname(AS(CData,_this->td),nIcW,NC_TD_TSR);                         /*   Rename weight component         */
    break;                                                                      /* ==                                */
  default:                                                                      /* nSrType unknown                   */
    return IERROR(_this,FST_INVALID,"weight semiring type",0,0);                /*   Error                           */
  }                                                                             /* <<                                */
  return O_K;                                                                   /* All right                         */
}
Exemplo n.º 11
0
/*
 * Manual page at fst_man.def
 */
INT16 CGEN_PUBLIC CFst_CopyUi(CFst* _this, CFst* itSrc, CData* idIndex, INT32 nPar)
{
  INT32 i  = 0;
  INT32 nU = 0;

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

  if (idIndex)
  {
    if (CData_IsEmpty(idIndex)) return NOT_EXEC;
    if (nPar<0)
      for (i=0; i<CData_GetNComps(idIndex); i++)
        if (dlp_is_numeric_type_code(CData_GetCompType(idIndex,i)))
          { nPar=i; break; }

    if
    (
      nPar<0 || nPar>=CData_GetNComps(idIndex) ||
      !dlp_is_numeric_type_code(CData_GetCompType(idIndex,nPar))
    )
    {
      return IERROR(_this,FST_BADID,"component",nPar,0);
    }
  }

  /* Initialize */
  CREATEVIRTUAL(CFst,itSrc,_this);
  CFst_Reset(BASEINST(_this),TRUE);
  
  if (idIndex)
  {
    /* Loop over records of idIndex */
    for (i=0; i<CData_GetNRecs(idIndex); i++)
    {
      nU = (INT32)CData_Dfetch(idIndex,i,nPar);
      if (nU>=0 && nU<UD_XXU(itSrc)) {
        DLPASSERT(OK(CFst_CatEx(_this,itSrc,nU,1)))
      } else IERROR(_this,FST_BADID2,"unit",nU,0);
    }
  }
  else if (nPar<0)
Exemplo n.º 12
0
/**
 * Returns the type of the weight semiring of an automaton.
 *
 * @param _this   Pointer to automaton instance
 * @param lpnComp Pointer to a long variable to be filled with the component
 *                index of the weight component in the transition table
 *                {@link td} (may be <code>NULL</code>).
 * @return The type of the weight semiring (<code>FST_WSR_PROB</code>,
 *         <code>FST_WSR_LOG</code> or <code>FST_WSR_TROP</code>) or
 *         <code>FST_WSR_NONE</code> if the automaton is unweighted.
 * @see Wsr_Op CFst_Wsr_Op
 */
INT16 CGEN_PUBLIC CFst_Wsr_GetType(CFst* _this, INT32* lpnComp)
{
  INT32 nIc = -1;

  CHECK_THIS_RV(-1);
  if (lpnComp) *lpnComp=-1;

  if ((nIc=CData_FindComp(AS(CData,_this->td),NC_TD_PSR))>=IC_TD_DATA)
  {
    if (lpnComp) *lpnComp=nIc;
    return FST_WSR_PROB;
  }
  if ((nIc=CData_FindComp(AS(CData,_this->td),NC_TD_LSR))>=IC_TD_DATA)
  {
    if (lpnComp) *lpnComp=nIc;
    return FST_WSR_LOG;
  }
  if ((nIc=CData_FindComp(AS(CData,_this->td),NC_TD_TSR))>=IC_TD_DATA)
  {
    if (lpnComp) *lpnComp=nIc;
    return FST_WSR_TROP;
  }
  return FST_WSR_NONE;
}
Exemplo n.º 13
0
/**
 * Copies selected word types.
 *
 * @param _this This instance
 * @param iSrc  Source instance to copy
 * @param nWhat Word type to copy (for more than one use "|")
 */
INT16 CDlpObject_CopySelective(CDlpObject* _this, CDlpObject* iSrc, INT16 nWhat)
{
  hscan_t     hs;
  hnode_t*    hn;
  SWord*      lpWord = NULL;
  CDlpObject* iSrcInt;
  CDlpObject* iDstInt;

  CHECK_THIS_RV(NOT_EXEC);
  DEBUGMSG(-1,"CDlpObject_Copy for '%s'",_this->m_lpInstanceName,0,0);
#ifdef __NORTTI
  if(strcmp(_this->m_lpClassName,"data")){
    IERROR(_this,ERR_DANGEROUS,"CDlpObject_Copy","No fields can be copied in __NORTTI mode.",0);
    DLPASSERT(FALSE);
  }
#endif

  if(_this == iSrc) return O_K;
  if(!iSrc)         return NOT_EXEC;

  /* TODO: Check this! --> */
  /*if(!CDlpObject_IsKindOf(iSrc,_this->m_lpClassName))*/

#ifdef __cplusplus
  if(!iSrc->IsKindOf(_this->m_lpClassName))
#else
  if(!BASEINST(iSrc)->IsKindOf(BASEINST(iSrc),_this->m_lpClassName))
#endif
    return
      IERROR(_this,ERR_NOTOFKIND,iSrc->m_lpInstanceName,_this->m_lpClassName,0);
  /* <-- */

  /* Loop over own dictionary */
  hash_scan_begin(&hs,_this->m_lpDictionary);
  while ((hn = hash_scan_next(&hs))!=NULL)
  {
    DLPASSERT((lpWord = (SWord*)hnode_get(hn))!=NULL); /* NULL entry in dictionary */
    if (!lpWord) continue;
    switch (lpWord->nWordType & nWhat)
    {
      case WL_TYPE_FIELD:
        CDlpObject_CopyField(_this,lpWord,iSrc);
        break;
      case WL_TYPE_INSTANCE:
        iDstInt = (CDlpObject*)lpWord->lpData;
        iSrcInt = CDlpObject_FindInstanceWord(iSrc,lpWord->lpName,NULL);
        if (iSrcInt && iDstInt)
#ifdef __cplusplus
          iDstInt->Copy(iSrcInt);
#else
        BASEINST(iDstInt)->Copy(BASEINST(iDstInt),BASEINST(iSrcInt));
#endif
        break;
      case WL_TYPE_DONTCARE: /* Not supported */
      case WL_TYPE_ERROR:    /* Not supported */
      case WL_TYPE_FACTORY:  /* Not supported */
      case WL_TYPE_METHOD:   /* Not supported */
      case WL_TYPE_OPERATOR: /* Not supported */
      case WL_TYPE_OPTION:   /* Not supported */
      default: break;
    }
  }

  /* Loop over source's dictionary */
  hash_scan_begin(&hs,iSrc->m_lpDictionary);
  while ((hn = hash_scan_next(&hs))!=NULL)
  {
    DLPASSERT((lpWord = (SWord*)hnode_get(hn))!=NULL); /* NULL entry in dictionary */
    if (!lpWord) continue;
    switch (lpWord->nWordType & nWhat)
    {
      case WL_TYPE_INSTANCE:
        iSrcInt = (CDlpObject*)lpWord->lpData;
        iDstInt = CDlpObject_FindInstanceWord(_this,lpWord->lpName,NULL);
        if (iDstInt) continue; /* Has already been copied */
        iDstInt = CDlpObject_Instantiate(_this,iSrcInt->m_lpClassName,iSrcInt->m_lpInstanceName,FALSE);
        if (iSrcInt && iDstInt)
#ifdef __cplusplus
          iDstInt->Copy(iSrcInt);
#else
        BASEINST(iDstInt)->Copy(BASEINST(iDstInt),BASEINST(iSrcInt));
#endif
        break;
      case WL_TYPE_DONTCARE: /* Don't know */
      case WL_TYPE_ERROR:    /* Don't know */
      case WL_TYPE_FACTORY:  /* Don't know */
      case WL_TYPE_METHOD:   /* Don't know */
      case WL_TYPE_OPERATOR: /* Don't know */
      case WL_TYPE_OPTION:   /* Don't know */
      default: break;
    }
  }

  _this->m_nCheck = iSrc->m_nCheck;

  return O_K;
}
Exemplo n.º 14
0
/**
 * Returns the number of statistics classes (labels) C. The number of classes is
 * defined by the number of blocks in the statistics data table
 * {@link dat m_idDat}.
 *
 * @param _this
 *          Pointer to CStatistics instance
 * @return The number of classes or 0 in case of errors
 */
INT32 CGEN_PUBLIC CStatistics_GetNClasses(CStatistics* _this)
{
  CHECK_THIS_RV(0);
  if (CData_IsEmpty(_this->m_idDat)) return 0;
  return CData_GetNBlocks(_this->m_idDat);
}
Exemplo n.º 15
0
/**
 * Returns the statistics' dimensionality N. The dimensionality is defined by
 * the number of components in the statistics data table {@link dat m_idDat}.
 *
 * @param _this
 *          Pointer to CStatistics instance
 * @return The dimensionality or 0 in case of errors
 */
INT32 CGEN_PUBLIC CStatistics_GetDim(CStatistics* _this)
{
  CHECK_THIS_RV(0);
  return CData_GetNComps(_this->m_idDat);
}
Exemplo n.º 16
0
/**
 * <p>Performs an arithmetic operation <code>OP(nW1,nW2)</code> depending on the
 * specified weight semiring type.</p>
 *
 * <p>The following operations are supported (parameter <code><b>nOpc</b></code>):</p>
 * <div class="indent">
 * <table>
 *   <tr><th><code>nOpc      </code></th><th colspan="2">Description                                              </th></tr>
 *   <tr><td><code>OP_ADD    </code></td><td><code>nW1(+)nW2 </code></td><td>Addition                              </td></tr>
 *   <tr><td><code>OP_MULT   </code></td><td><code>nW1(*)nW2 </code></td><td>Multiplication                        </td></tr>
 *   <tr><td><code>OP_DIV    </code></td><td><code>nW1(/)nW2 </code></td><td>Division (multiplicative residual)    </td></tr>
 *   <tr><td><code>OP_EQUAL  </code></td><td><code>nW1==nW2  </code></td><td>Floating point comparison<sup>1)</sup></td></tr>
 *   <tr><td><code>OP_LESS   </code></td><td><code>nW1&lt;nW2</code></td><td>Less than <sup>1)</sup>               </td></tr>
 *   <tr><td><code>OP_GREATER</code></td><td><code>nW1&gt;nW2</code></td><td>Greater than<sup>1)</sup>             </td></tr>
 * </table>
 * <p>1) Result is 1.0 if condition is true, 0.0 otherwise</p>
 * </div>
 *
 * <h3 style="color:red">Important Note:</h3>
 * <p>The method evaluates the field
 * <code>_this->{@link wsr m_nWsr}</code> to  determine the semiring type. This
 * field is <em>not</em> maintained automatically, meaning you must ensure
 * <code>_this->{@link wsr m_nWsr}</code> to specify the correct semiring type
 * prior to calling <code>CFst_Wsr_Op</code>! You can determine the current
 * semiring type by calling {@link Wsr_GetType CFst_Wsr_GetType}.</p>
 *
 * @param _this Pointer to automaton instance
 * @param nW1   Operand 1
 * @param nW2   Operand 2
 * @param nOpc  Operation code (see table above)
 * @return The  result of the operation (<em>no</em> value is reserved for reporting errors!).
 * @see Wsr_GetType CFst_Wsr_GetType
 * @see Wsr_NeAdd   CFst_Wsr_NeAdd
 * @see Wsr_NeMult  CFst_Wsr_NeMult
 */
FST_WTYPE CGEN_PROTECTED CFst_Wsr_Op(CFst* _this, FST_WTYPE nW1, FST_WTYPE nW2, INT16 nOpc)
{
  /* Validation */
  CHECK_THIS_RV(0.);

  /* In case the user forgot: determine current semiring type if not yet set */
  if (_this->m_nWsr<=0) _this->m_nWsr = CFst_Wsr_GetType(_this,NULL);

  /* Operations */
  switch (nOpc)
  {
    /* Addition */
    case OP_ADD:
      switch (_this->m_nWsr)
      {
        case FST_WSR_PROB: return nW1+nW2;
        case FST_WSR_LOG : return dlp_scalop(nW1,nW2,OP_LSADD);
        case FST_WSR_TROP: return nW1<nW2?nW1:nW2;
        case 0           : return 0.;                                          /* Not weighted; just do nothing     */
        default          : DLPASSERT(FMSG("Invalid weight semiring type"));
      }
      return 0.;

    /* Multiplication */
    case OP_MULT:
      switch (_this->m_nWsr)
      {
        case FST_WSR_PROB: return nW1*nW2;
        case FST_WSR_LOG : return nW1+nW2;
        case FST_WSR_TROP: return nW1+nW2;
        case 0           : return 0.;                                          /* Not weighted; just do nothing     */
        default          : DLPASSERT(FMSG("Invalid weight semiring type"));
      }
      return 0.;

    /* Power */
    case OP_POW:
      switch (_this->m_nWsr)
      {
        case FST_WSR_PROB: return dlm_pow(nW1,nW2);
        case FST_WSR_LOG : return nW1*nW2;
        case FST_WSR_TROP: return nW1*nW2;
        case 0           : return 0.;                                          /* Not weighted; just do nothing     */
        default          : DLPASSERT(FMSG("Invalid weight semiring type"));
      }
      return 0.;

    /* Division (multiplicative residual) */
    case OP_DIV:
      switch (_this->m_nWsr)
      {
        case FST_WSR_PROB: return nW1/nW2;
        case FST_WSR_LOG : return nW1-nW2;
        case FST_WSR_TROP: return nW1-nW2;
        case 0           : return 0.;                                          /* Not weighted; just do nothing     */
        default          : DLPASSERT(FMSG("Invalid weight semiring type"));
      }
      return 0.;

    /* Floating point comparison */
    case OP_EQUAL:
      if      (fabs(nW1)<_this->m_nFtol) return (fabs(nW2)<_this->m_nFtol);
      else if (fabs(nW2)<_this->m_nFtol) return (fabs(nW1)<_this->m_nFtol);
      else                               return (fabs((nW1-nW2)/nW1)<_this->m_nFtol);

    /* Less than */
    case OP_LESS:
      switch (_this->m_nWsr)
      {
        case FST_WSR_LOG : return (nW1>nW2);
        case FST_WSR_TROP: return (nW1>nW2);
        case FST_WSR_PROB: return (nW1<nW2);
        case 0           : return (nW1<nW2);
        default          : DLPASSERT(FMSG("Invalid weight semiring type"));
      }
      return 0.;

    /* Greater than */
    case OP_GREATER:
      switch (_this->m_nWsr)
      {
        case FST_WSR_LOG : return (nW1<nW2);
        case FST_WSR_TROP: return (nW1<nW2);
        case FST_WSR_PROB: return (nW1>nW2);
        case 0           : return (nW1>nW2);
        default          : DLPASSERT(FMSG("Invalid weight semiring type"));
      }
      return 0.;

    /* Invalid opcode */
    default:
      DLPASSERT(FMSG("Invalid weight semiring operation"));
      return 0.;
  }
}
Exemplo n.º 17
0
/*
 * 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                            */
}
Exemplo n.º 18
0
/*
 * Manual page at fst_man.def
 */
INT16 CGEN_PUBLIC CFst_Probs(CFst* _this, INT32 nUnit)
{
  INT32          nU     = 0;                                                     /* Current unit                      */
  FST_ITYPE     nS     = 0;                                                     /* Current state                     */
  FST_ITYPE     nT     = 0;                                                     /* Current transition                */
  FST_ITYPE     nXS    = 0;                                                     /* Number of states in current unit  */
  INT16         nWsrt  = 0;                                                     /* Weight semiring type              */
  INT32          nIcW   = -1;                                                    /* Weight component in td            */
  INT32          nIcPfl = -1;                                                    /* Floor probability component in sd */
  INT32          nIcRct = -1;                                                    /* Reference counter component in td */
  INT32          nTrCnt = 0;                                                     /* Number of outgoing trans./state   */
  FST_WTYPE     nW     = 0.;                                                    /* Current weight                    */
  FST_WTYPE     nRc    = 0.;                                                    /* Current reference counter/prob.   */
  FST_WTYPE     nRcSum = 0.;                                                    /* Reference counter sum/state       */
  FST_WTYPE     nTW    = 0.;                                                    /* trans.weight                      */
  FST_WTYPE     nTWAgg = 0.;                                                    /* trans.weight aggregator for MAP   */
  CData*        idTd   = NULL;                                                  /* Pointer to transition table       */
  FST_TID_TYPE* lpTI   = NULL;                                                  /* Automaton iterator data structure */
  BYTE*         lpT    = NULL;                                                  /* Current transition (iteration)    */
  FST_WTYPE     nMAP   = _this->m_bUsemap ? _this->m_nMapexp : 0.;              /* MAP exponent (0:off,1:min,-1:max) */
  INT32          nMAPi  = 0;                                                     /* MAP iteration index               */

  /* Validation */                                                              /* --------------------------------- */
  CHECK_THIS_RV(NOT_EXEC);                                                      /* Check this pointer                */
  CFst_Check(_this);                                                            /* Check FST(s)                      */

  /* Initialize */                                                              /* --------------------------------- */
  idTd   = AS(CData,_this->td);                                                 /* Get pointer to transition table   */
  nIcRct = CData_FindComp(AS(CData,_this->td),NC_TD_RC);                        /* Find reference counters           */
  nWsrt  = CFst_Wsr_GetType(_this,&nIcW);                                       /* Find weights and get type         */
  switch (nWsrt)                                                                /* branch for weight semiring type   */
  {                                                                             /* >>                                */
    case FST_WSR_NONE:                                                          /*   No weights                      */
      CData_AddComp(idTd,NC_TD_PSR,DLP_TYPE(FST_WTYPE));                        /*     Add some                      */
      nIcW = CData_GetNComps(idTd)-1;                                           /*     Get index of new weight comp. */
      for (nT=0; nT<UD_XXT(_this); nT++)                                        /*     Initialize probabilities      */
        CData_Dstore(idTd,1.,nT,nIcW);                                          /*     ...                           */
      break;                                                                    /*     *                             */
    case FST_WSR_PROB:                                                          /*   Probabilities                   */
      break;                                                                    /*     * (nothing to be done)        */
    case FST_WSR_TROP: /* fall through */                                       /*   Tropical weights                */
    case FST_WSR_LOG:                                                           /*   Logarithmic weights             */
      for (nT=0; nT<UD_XXT(_this); nT++)                                        /*     Loop over all transitions     */
        CData_Dstore(idTd,                                                      /*       Convert to probabilities    */
          exp(-1.*CData_Dfetch(idTd,nT,nIcW)),nT,nIcW);                         /*       |                           */
      break;                                                                    /*     *                             */
    default:                                                                    /*   Unknown weight semiring         */
      DLPASSERT(FMSG("Unknown weight semiring"));                               /*     New weight semiring type?     */
      CData_SetCname(idTd,nIcW,NC_TD_PSR);                                      /*     Rename to probabilities       */
      for (nT=0; nT<UD_XXT(_this); nT++)                                        /*     Initialize probabilities      */
        CData_Dstore(idTd,1.,nT,nIcW);                                          /*     ...                           */
  }                                                                             /* <<                                */
  if (_this->m_nSymbols>0 && _this->m_nRcfloor>0.)                              /* Smoothing enabled                 */
  {                                                                             /* >>                                */
    if (CData_FindComp(AS(CData,_this->sd),"~PFL")<0)                           /*   No floor prob. comp. at states  */
      CData_AddComp(AS(CData,_this->sd),"~PFL",DLP_TYPE(FST_WTYPE));            /*     Add it                        */
    nIcPfl = CData_FindComp(AS(CData,_this->sd),"~PFL");                        /*   Get index of floor prob. comp.  */
  }                                                                             /* <<                                */

  /* Loop over units */                                                         /* --------------------------------- */
  for (nU=nUnit<0?0:nUnit; nU<UD_XXU(_this); nU++)                              /* For all units ...                 */
  {                                                                             /* >>                                */
    lpTI = CFst_STI_Init(_this,nU,FSTI_SORTINI);                                /*   Get sorted transition iterator  */

    /* Loop over states */                                                      /*   - - - - - - - - - - - - - - - - */
    for (nS=0,nXS=UD_XS(_this,nU); nS<nXS; nS++)                                /*   For all states of the unit ...  */
    /* Loop over MAP-Iterations if MAP enabled */                               /*   - - - - - - - - - - - - - - - - */
    for(nMAPi=0;nMAPi<(nMAP!=0.?10:1);nMAPi++)                                  /*   For all MAP-iterations ...      */
    {                                                                           /*   >>                              */
      /* Pass 1: Count outgoing transitions and sum up reference counters */    /*                                   */
      nRcSum = 0.;                                                              /*     Reset ref. ctr. accumulator   */
      nTWAgg = 0.;                                                              /*     Reset MAP TW accumulator      */
      nTrCnt = 0;                                                               /*     Reset transition counter      */
      lpT    = NULL;                                                            /*     Initialize transition pointer */
      while ((lpT=CFst_STI_TfromS(lpTI,nS,lpT))!=NULL)                          /*     Enumerate transitions at nS   */
      {                                                                         /*     >>                            */
        nRc = nIcRct>=0                                                         /*       Get ref. ctr. or prob.      */
            ? CData_Dfetch(idTd,CFst_STI_GetTransId(lpTI,lpT),nIcRct)           /*       |                           */
            : *CFst_STI_TW(lpTI,lpT);                                           /*       |                           */
        if (nRc>=0.) nRcSum+=nRc;                                               /*       Accumulate non-neg. values  */
        if (nMAP!=0. && nRc>0.)                                                 /*       if MAP enabled and T. used  */
        {                                                                       /*       >>                          */
          nTW = *CFst_STI_TW(lpTI,lpT);                                         /*         get trans.weight          */
          if(nTW<=0.) nTW=0.0001;                                               /*         solve prob. with 0 TW's   */
          nTWAgg += nTW*log(nTW);                                               /*         acc. TW's                 */
        }                                                                       /*       <<                          */
        nTrCnt++;                                                               /*       Count transitions           */
      }                                                                         /*     <<                            */
      if (nIcPfl)                                                               /*     Smoothing eneabled            */
        CData_Dstore(AS(CData,_this->sd),                                       /*       Store floor probability     */
          _this->m_nRcfloor / (nRcSum + _this->m_nSymbols*_this->m_nRcfloor),   /*       |                           */
          nS,nIcPfl);                                                           /*       |                           */
                                                                                /*                                   */
      /* Pass 2: Calculate probabilities */                                     /*                                   */
      if (nTrCnt)                                                               /*     If there were trans. at nS    */
      {                                                                         /*     >>                            */
        lpT = NULL;                                                             /*       Initialize transition ptr.  */
        while ((lpT=CFst_STI_TfromS(lpTI,nS,lpT))!=NULL)                        /*       Enumerate transitions at nS */
        {                                                                       /*       >>                          */
          nRc = nIcRct>=0                                                       /*         Get ref. ctr. or prob.    */
              ? CData_Dfetch(idTd,CFst_STI_GetTransId(lpTI,lpT),nIcRct)         /*         |                         */
              : *CFst_STI_TW(lpTI,lpT);                                         /*         |                         */
          if (nMAP!=0.)                                                         /*         if MAP enabled            */
          {                                                                     /*         <<                        */
            nTW = *CFst_STI_TW(lpTI,lpT);                                       /*           get trans.weight        */
            if(nTW<=0.) nTW=0.0001;                                             /*           solve prob. with 0 TW's */
            if(nIcRct>=0 && _this->m_nSymbols>0 && _this->m_nRcfloor>0)         /*           do jeffrey smooth?      */
              nRc = nRcSum * (nRc + (FST_WTYPE)_this->m_nRcfloor) /             /*             smooth nRc            */
                (nRcSum + ((FST_WTYPE)_this->m_nSymbols*_this->m_nRcfloor));    /*             |                     */
            nTW = (nRc<=0. ? 0. : (nRc+nMAP*nTW*log(nTW))/(nRcSum+nMAP*nTWAgg));/*           do MAP-iteration        */
            *CFst_STI_TW(lpTI,lpT) = nTW;                                       /*           write trans.weight      */
          }                                                                     /*         >>                        */
          else                                                                  /*         else                      */
            if (nIcRct<0 || _this->m_nSymbols<=0 || _this->m_nRcfloor<=0.)      /*         No ref.ctrs. or smoothing */
              *CFst_STI_TW(lpTI,lpT) =                                          /*           Store equally distrib.  */
                nRcSum==0. ? 1./(FST_WTYPE)nTrCnt : nRc/nRcSum;                 /*           | or renormalized probs.*/
            else                                                                /*         Ref. ctrs. or smoothing   */
              *CFst_STI_TW(lpTI,lpT) =                                          /*           Store Jeffrey smoothed  */
                (nRc + (FST_WTYPE)_this->m_nRcfloor) /                          /*           | probabilities         */
                (nRcSum + ((FST_WTYPE)_this->m_nSymbols*_this->m_nRcfloor));    /*           |                       */
        }                                                                       /*       <<                          */
      }                                                                         /*     <<                            */
    }                                                                           /*   <<                              */
    CFst_STI_Done(lpTI);                                                        /*   Destroy iterator                */
    if (nUnit>=0) break;                                                        /*   Stop in single unit mode        */
  }                                                                             /* <<                                */

  /* Convert back to logarithmic/tropical weights */                            /* --------------------------------- */
  if (nWsrt==FST_WSR_LOG || nWsrt==FST_WSR_TROP)                                /* Loarithmic or tropical weights    */
    for (nT=0; nT<UD_XXT(_this); nT++)                                          /*   Loop over all transitions       */
    {                                                                           /*   >>                              */
      nW = CData_Dfetch(idTd,nT,nIcW);                                          /*     Get probability               */
      nW = nW>0. ? -log(nW) : _this->m_nWceil;                                  /*     Convert to log./trop. weight  */
      CData_Dstore(idTd,nW,nT,nIcW);                                            /*     Store weight                  */
    }                                                                           /*   <<                              */

  /* Clean up */                                                                /* --------------------------------- */
  return O_K;                                                                   /* The end                           */
}
Exemplo n.º 19
0
/*
 * Manual page at fst_man.def
 */
INT16 CGEN_PUBLIC CFst_Product
(
  CFst* _this,
  CFst* itSrc1,
  CFst* itSrc2,
  INT32  nUnit1,
  INT32  nUnit2
)
{
  INT32      nC           = 0;                                                   /* Current component                  */
  INT32      nFCS2        = 0;                                                   /* 1st data comp. of state tab.itSrc2 */
  INT32      nXCS1        = 0;                                                   /* No. of comps. of state tab. itSrc1 */
  INT32      nXCS2        = 0;                                                   /* No. of comps. of state tab. itSrc2 */
  INT32      nFCT2        = 0;                                                   /* 1st data comp. of trans.tab.itSrc2 */
  INT32      nXCT1        = 0;                                                   /* No. of comps. of trans.tab. itSrc1 */
  INT32      nXCT2        = 0;                                                   /* No. of comps. of trans.tab. itSrc2 */
  INT32      nRls1        = 0;                                                   /* Rec. len. of state table of itSrc1 */
  INT32      nRls2        = 0;                                                   /* Rec. len. of state table of itSrc2 */
  INT32      nRlt1        = 0;                                                   /* Rec. len. of trans.table of itSrc1 */
  INT32      nRlt2        = 0;                                                   /* Rec. len. of trans.table of itSrc2 */
  FST_ITYPE nS1          = 0;
  FST_ITYPE nS2          = 0;
  FST_ITYPE nFS1         = 0;
  FST_ITYPE nFS2         = 0;
  FST_ITYPE nXS1         = 0;
  FST_ITYPE nXS2         = 0;
  FST_ITYPE nT           = 0;
  FST_ITYPE nIni         = 0;
  FST_ITYPE nTer         = 0;
  FST_ITYPE nT1          = 0;
  FST_ITYPE nT2          = 0;
  FST_ITYPE nFT1         = 0;
  FST_ITYPE nFT2         = 0;
  FST_ITYPE nXT1         = 0;
  FST_ITYPE nXT2         = 0;
  char*     lpsBuf       = NULL;                                                /* String buffer                      */
  INT16     nVirt        = 0;                                                   /* Auxiliary: patching ovrl.args. bug */
  BOOL      bNoloopsSave = FALSE;                                               /* Save buffer for /noloops option    */

  /* Validate */
  CHECK_THIS_RV(NOT_EXEC);
  if (itSrc1==NULL || itSrc2==NULL)
  {
    CFst_Reset(BASEINST(_this),TRUE);
    return O_K;
  }
  if (nUnit1<0 || nUnit1>=UD_XXU(itSrc1)) return IERROR(_this,FST_BADID,"unit",nUnit1,0);
  if (nUnit2<0 || nUnit2>=UD_XXU(itSrc2)) return IERROR(_this,FST_BADID,"unit",nUnit2,0);

  /* Initialize */
  /* HACK: Multiple overlapping arguments on _this not handled correctly by
           CREATEVIRTUAL --> */
  if (_this==itSrc1 && _this==itSrc2) return IERROR(_this,ERR_GENERIC,"Invalid arguments",0,0);
  if      (itSrc1==_this) { CREATEVIRTUAL(CFst,itSrc1,_this); nVirt=1; }
  else if (itSrc2==_this) { CREATEVIRTUAL(CFst,itSrc2,_this); nVirt=2; }
  /* <-- */
  bNoloopsSave = _this->m_bNoloops;
  CFst_Reset(BASEINST(_this),TRUE);
  _this->m_bNoloops = bNoloopsSave;

  /* Initialize destination state table */
  nFS1  = UD_FS(itSrc1,nUnit1);
  nXS1  = UD_XS(itSrc1,nUnit1);
  nFS2  = UD_FS(itSrc2,nUnit2);
  nXS2  = UD_XS(itSrc2,nUnit2);
  nRls1 = CData_GetRecLen(AS(CData,itSrc1->sd)) - CData_GetCompOffset(AS(CData,itSrc1->sd),IC_SD_DATA);
  nRls2 = CData_GetRecLen(AS(CData,itSrc2->sd)) - CData_GetCompOffset(AS(CData,itSrc2->sd),IC_SD_DATA);
  nXCS1 = CData_GetNComps(AS(CData,itSrc1->sd)) - IC_SD_DATA;
  nXCS2 = CData_GetNComps(AS(CData,itSrc2->sd)) - IC_SD_DATA;
  nFCS2 = IC_SD_DATA + nXCS1;
  for (nC=IC_SD_DATA; nC<IC_SD_DATA+nXCS1; nC++)
    CData_AddComp
    (
      AS(CData,_this->sd),
      CData_GetCname(AS(CData,itSrc1->sd),nC),
      CData_GetCompType(AS(CData,itSrc1->sd),nC)
    );
  for (nC=IC_SD_DATA; nC<IC_SD_DATA+nXCS2; nC++)
    CData_AddComp
    (
      AS(CData,_this->sd),
      CData_GetCname(AS(CData,itSrc2->sd),nC),
      CData_GetCompType(AS(CData,itSrc2->sd),nC)
    );

  /* Initialize destination transition table */
  nFT1  = UD_FT(itSrc1,nUnit1);
  nXT1  = UD_XT(itSrc1,nUnit1);
  nFT2  = UD_FT(itSrc2,nUnit2);
  nXT2  = UD_XT(itSrc2,nUnit2);
  nRlt1 = CData_GetRecLen(AS(CData,itSrc1->td)) - CData_GetCompOffset(AS(CData,itSrc1->td),IC_TD_DATA);
  nRlt2 = CData_GetRecLen(AS(CData,itSrc2->td)) - CData_GetCompOffset(AS(CData,itSrc2->td),IC_TD_DATA);
  nXCT1 = CData_GetNComps(AS(CData,itSrc1->td)) - IC_TD_DATA;
  nXCT2 = CData_GetNComps(AS(CData,itSrc2->td)) - IC_TD_DATA;
  nFCT2 = IC_TD_DATA + nXCT1;
  for (nC=IC_TD_DATA; nC<IC_TD_DATA+nXCT1; nC++)
    CData_AddComp
    (
      AS(CData,_this->td),
      CData_GetCname(AS(CData,itSrc1->td),nC),
      CData_GetCompType(AS(CData,itSrc1->td),nC)
    );
  for (nC=IC_TD_DATA; nC<IC_TD_DATA+nXCT2; nC++)
    CData_AddComp
    (
      AS(CData,_this->td),
      CData_GetCname(AS(CData,itSrc2->td),nC),
      CData_GetCompType(AS(CData,itSrc2->td),nC)
    );

  /* Copy input and output symbol tables */
  CData_Copy(_this->is,itSrc1->is);
  CData_Copy(_this->os,itSrc2->os);

  /* Initialize destination unit */
  lpsBuf = (char*)dlp_calloc
  (
    CData_GetCompType(AS(CData,itSrc1->ud),IC_UD_NAME) +
    CData_GetCompType(AS(CData,itSrc2->ud),IC_UD_NAME) + 2,
    sizeof(char)
  );
  sprintf
  (
    lpsBuf,"%s.%s",
    (const char*)CData_XAddr(AS(CData,itSrc1->ud),nUnit1,IC_UD_NAME),
    (const char*)CData_XAddr(AS(CData,itSrc2->ud),nUnit2,IC_UD_NAME)
  );
  CFst_Addunit(_this,lpsBuf);
  dlp_free(lpsBuf);

  /* Add product states */
  CFst_Addstates(_this,0,nXS1*nXS2,FALSE);

  /* Copy state qualification (including final state flag) */
  for (nS1=0; nS1<nXS1; nS1++)
    for (nS2=0; nS2<nXS2; nS2++)
    {
      if ((SD_FLG(itSrc1,nS1+nFS1)&0x01)==0x01 && (SD_FLG(itSrc2,nS2+nFS2)&0x01)==0x01)
        SD_FLG(_this,nS1*nXS2+nS2) |= 0x01;
      if (nRls1>0)
        dlp_memmove
        (
          CData_XAddr(AS(CData,_this ->sd),nS1*nXS2+nS2,IC_SD_DATA),
          CData_XAddr(AS(CData,itSrc1->sd),nS1+nFS1    ,IC_SD_DATA),
          nRls1
        );
      if (nRls2>0)
        dlp_memmove
        (
          CData_XAddr(AS(CData,_this ->sd),nS1*nXS2+nS2,nFCS2     ),
          CData_XAddr(AS(CData,itSrc2->sd),nS2+nFS2    ,IC_SD_DATA),
          nRls2
        );
    }

  CData_AddRecs(AS(CData,_this->td),nXT1*nXT2,_this->m_nGrany);
  /* Loop over all transitions of both factors */
  for (nT=0, nT1=nFT1; nT1<nFT1+nXT1; nT1++)
    for (nT2=nFT2; nT2<nFT2+nXT2; nT2++, nT++)
    {
      /* Get product of initial and terminal state */
      nIni = TD_INI(itSrc1,nT1)*nXS2 + TD_INI(itSrc2,nT2);
      nTer = TD_TER(itSrc1,nT1)*nXS2 + TD_TER(itSrc2,nT2);
      if (_this->m_bNoloops && nIni==nTer) continue;

      /* Add product transition */
      *(FST_ITYPE*)CData_XAddr(AS(CData,_this->td),nT,IC_TD_INI) = nIni;
      *(FST_ITYPE*)CData_XAddr(AS(CData,_this->td),nT,IC_TD_TER) = nTer;

      /* Copy transition qualification */
      dlp_memmove
      (
        CData_XAddr(AS(CData,_this ->td),nT ,IC_TD_DATA),
        CData_XAddr(AS(CData,itSrc1->td),nT1,IC_TD_DATA),
        nRlt1
      );
      dlp_memmove
      (
        CData_XAddr(AS(CData,_this ->td),nT ,nFCT2     ),
        CData_XAddr(AS(CData,itSrc2->td),nT2,IC_TD_DATA),
        nRlt2
      );
    }

  /* Finish destination instance */
  CData_SelectRecs(AS(CData,_this->td),AS(CData,_this->td),0,nT);
  UD_XT(_this,0) = nT;
  /* TODO: Trim result !? */

  /* Clean up */
  if (nVirt==1) { DESTROYVIRTUAL(itSrc1,_this); }
  if (nVirt==2) { DESTROYVIRTUAL(itSrc2,_this); }
  return O_K;
}
Exemplo n.º 20
0
/**
 * Returns the parent of this instance in the instance tree.
 *
 * @param _this
 *          Pointer to this instance
 * @return Pointer to the parent instance or <code>NULL</code> if the passed
 *         pointer is invalid or this instance is the root of the tree.
 */
CDlpObject* CDlpObject_GetParent(CDlpObject* _this)
{
  CHECK_THIS_RV(NULL);                                                          /* Check this pointer                */
  if (!_this->m_lpContainer) return NULL;                                       /* No container word -> no parent    */
  return _this->m_lpContainer->lpContainer;                                     /* Return owner of container word    */
}
Exemplo n.º 21
0
/**
 * Import and export of non-native file formats.
 *
 * @param _this       This instance.
 * @param sFilename   Name of file to import.
 * @param sFilter     Filter to use for import.
 * @param iInst       Instance where to save imported data.
 * @param nMode       Import or export mode.
 * @return <code>O_K</code> if successful, a (negative) error code otherwise
 */
INT16 CGEN_PROTECTED CDlpFile_ImportExport
(
  CDlpFile*   _this,
  const char* sFilename,
  const char* sFilter,
  CDlpObject* iInst,
  INT16 nMode
)
{
  INT16    retVal     = O_K;
  lnode_t* lpNode     = NULL;
  CFILE_FTYPE* lpType = NULL;
  FILE* lpFile        = NULL;
  char lpsFilenameLoc[L_PATH];
  char lpsCmd[L_PATH*2];

  CHECK_THIS_RV(FALSE);

  if(!dlp_strlen(sFilename)) return IERROR(_this,FIL_FILENAME,0     ,0,0);
  if(!iInst                ) return IERROR(_this,ERR_NULLARG,"iInst",0,0);

  dlp_strcpy(lpsFilenameLoc,sFilename);

  /* create target directory if necessary */
  if(nMode==EXPORT_FILE)
  {
    char lpNewDir[L_PATH] = "";
    char lpCurDir[L_PATH] = "";

#ifndef __TMS
    if(!_this->m_bExecute)
    {
      if(getcwd(lpCurDir,L_PATH) == NULL) return IERROR(_this,ERR_GETCWD,0,0,0);
      dlp_splitpath(lpsFilenameLoc,lpNewDir,NULL);
      if(0<dlp_strlen(lpNewDir))
      {
        if(dlp_chdir(lpNewDir,TRUE))
        {
          dlp_chdir(lpCurDir,FALSE);
          return
          IERROR(_this,ERR_FILEOPEN,lpsFilenameLoc,
              "writing (failed to create directory)",0);
        }
        dlp_chdir(lpCurDir,FALSE);
      }
    }
#endif
  }

#ifndef __TMS
  /* Execute lpsFilenameLoc (initialization & execute if import) */
  if(_this->m_bExecute)
  {
    char lpsBase[L_PATH];
    char *lpsTmp;
    dlp_splitpath(lpsFilenameLoc,NULL,lpsBase);
    if(strchr(lpsBase,' ')) *strchr(lpsBase,' ')='\0';
    lpsTmp=dlp_tempnam(NULL,lpsBase);
    snprintf(lpsCmd, L_PATH*2-1, "%s %c %s", lpsFilenameLoc, nMode==EXPORT_FILE?'<':'>', lpsTmp);
    dlp_strcpy(lpsFilenameLoc,lpsTmp);
    if(nMode==IMPORT_FILE) if(dlp_system(lpsCmd)!=0) return IERROR(_this,ERR_FILEOPEN,lpsCmd,"executing",0);
  }
#endif

  /* test if file is readable/writable */
  if(nMode==IMPORT_FILE)
    lpFile = fopen(lpsFilenameLoc,"r");
  else if(nMode==EXPORT_FILE)
    lpFile = fopen(lpsFilenameLoc,"a");
  else DLPASSERT(FMSG("Unknown operation mode."));

  if(!lpFile)
  {
    if (nMode==IMPORT_FILE)
      return IERROR(_this,ERR_FILEOPEN,sFilename,"reading",0);
    else if (nMode==EXPORT_FILE)
      return IERROR(_this,ERR_FILEOPEN,sFilename,"writing",0);
  }
  fclose(lpFile);

  /* lookup filter function from list */
  lpType = (CFILE_FTYPE*)dlp_calloc(1,sizeof(CFILE_FTYPE));
  if(!lpType) return IERROR(_this,ERR_NOMEM,0,0,0);

  dlp_strncpy(lpType->lpName,sFilter,L_NAMES);
  dlp_strncpy(lpType->lpClassName,iInst->m_lpClassName,L_NAMES);
  lpType->nMode = nMode;

  lpNode = list_find(_this->m_lpFtypes,lpType,CDlpFile_CompareFTypeList);
  if(!lpNode)
  {
    dlp_free(lpType);
    return
      IERROR(_this,FIL_NOIMEX,nMode==IMPORT_FILE?"import":"export",sFilter,
        iInst->m_lpClassName);
  }
  dlp_free(lpType);
  lpType = NULL;

  /* Invoke import function */
  lpType = (CFILE_FTYPE*)lnode_get(lpNode);
  retVal = lpType->FilterFunc(_this,lpsFilenameLoc,iInst,lpType->lpName);

#ifndef __TMS
  /* Execute lpsFilenameLoc (execute if export & finalization) */
  if(_this->m_bExecute)
  {
    if(nMode==EXPORT_FILE) dlp_system(lpsCmd);
    unlink(lpsFilenameLoc);
  }else
#endif
  if(nMode==EXPORT_FILE && _this->m_bZip) dlp_fzip(lpsFilenameLoc,"wb6");

  if(retVal != O_K)
  {
    if(nMode==IMPORT_FILE) return IERROR(_this,FIL_IMPORT,lpsFilenameLoc,sFilter,0);
    else                   return IERROR(_this,FIL_EXPORT,lpsFilenameLoc,sFilter,0);
  }

  return O_K;
}
Exemplo n.º 22
0
/**
 * 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;
}
Exemplo n.º 23
0
/*
 * 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 */
}
Exemplo n.º 24
0
/**
 * Copies the one field from iSrc to this instance
 *
 * @param _this  This (destination) instance
 * @param lpWord Pointer to a SWord structure identifying the field to copy
 * @param iSrc   The source instance to copy the field from
 * @return O_K if successful, an error code otherwise
 *
 * HACK: This implementation copies simple types and strings only!!!
 * TODO: Implement instance and pointer copying
 */
INT16 CDlpObject_CopyField(CDlpObject* _this, SWord* lpWord, CDlpObject* iSrc)
{
  SWord* lpWordSrc = NULL;

  /* Validate input */
  CHECK_THIS_RV(NOT_EXEC);
  if (!lpWord) return NOT_EXEC;
  if (!iSrc  ) return NOT_EXEC;
  if (lpWord->nFlags & (FF_NONAUTOMATIC|FF_NOSAVE)) return NOT_EXEC;

  /* Get source word */
  lpWordSrc = CDlpObject_FindWord(iSrc,lpWord->lpName,WL_TYPE_FIELD);
  DLPASSERT(lpWordSrc);                                     /* Instance type?     */
  DLPASSERT(lpWord->nWordType   ==lpWordSrc->nWordType   ); /* Field overwritten? */
  DLPASSERT(lpWord->ex.fld.nType==lpWordSrc->ex.fld.nType); /* Field overwritten? */

  /*printf("\n Copy field %s.%s --> %s.%s",BASEINST(iSrc)->m_lpInstanceName,lpWord->lpName,BASEINST(_this)->m_lpInstanceName,lpWord->lpName);*/

  /* Copy data */
  switch (lpWord->ex.fld.nType)
  {
  case T_BOOL   : dlp_memmove(lpWord->lpData,lpWordSrc->lpData,sizeof(     BOOL)); return O_K;
  case T_UCHAR  : dlp_memmove(lpWord->lpData,lpWordSrc->lpData,sizeof(    UINT8)); return O_K;
  case T_CHAR   : dlp_memmove(lpWord->lpData,lpWordSrc->lpData,sizeof(     INT8)); return O_K;
  case T_USHORT : dlp_memmove(lpWord->lpData,lpWordSrc->lpData,sizeof(   UINT16)); return O_K;
  case T_SHORT  : dlp_memmove(lpWord->lpData,lpWordSrc->lpData,sizeof(    INT16)); return O_K;
  case T_UINT   : dlp_memmove(lpWord->lpData,lpWordSrc->lpData,sizeof(   UINT32)); return O_K;
  case T_INT    : dlp_memmove(lpWord->lpData,lpWordSrc->lpData,sizeof(    INT32)); return O_K;
  case T_ULONG  : dlp_memmove(lpWord->lpData,lpWordSrc->lpData,sizeof(   UINT64)); return O_K;
  case T_LONG   : dlp_memmove(lpWord->lpData,lpWordSrc->lpData,sizeof(    INT64)); return O_K;
  case T_FLOAT  : dlp_memmove(lpWord->lpData,lpWordSrc->lpData,sizeof(  FLOAT32)); return O_K;
  case T_DOUBLE : dlp_memmove(lpWord->lpData,lpWordSrc->lpData,sizeof(  FLOAT64)); return O_K;
  case T_COMPLEX: dlp_memmove(lpWord->lpData,lpWordSrc->lpData,sizeof(COMPLEX64)); return O_K;
  case T_STRING :
  case T_CSTRING:
  case T_TEXT   :
    dlp_free(*(char**)lpWord->lpData);
    *(char**)lpWord->lpData = NULL;
    if (*(char**)lpWordSrc->lpData)
    {
      *(char**)lpWord->lpData = (char*)dlp_malloc(dlp_size(*(char**)lpWordSrc->lpData));
      dlp_strcpy(*(char**)lpWord->lpData,*(char**)lpWordSrc->lpData);
    }
    return O_K;
  case T_INSTANCE:
    if (*(CDlpObject**)lpWordSrc->lpData)
    {
      if (*(CDlpObject**)lpWord->lpData==NULL)
      {
      #ifdef __cplusplus
        *(CDlpObject**)lpWord->lpData = CDlpObject_CreateInstanceOf(lpWordSrc->ex.fld.lpType,lpWordSrc->lpName);
      #else
        *(CDlpObject**)lpWord->lpData = *(CDlpObject**)CDlpObject_CreateInstanceOf(lpWordSrc->ex.fld.lpType,lpWordSrc->lpName);
      #endif
        if (!*(CDlpObject**)lpWord->lpData)
          IERROR(_this,ERR_CREATEINSTANCE,lpWord->lpName,0,0);
        else
          (*(CDlpObject**)lpWord->lpData)->m_lpContainer=lpWord;
      }
    #ifdef __cplusplus
      return (*(CDlpObject**)lpWord->lpData)->Copy(*(CDlpObject**)lpWordSrc->lpData);
    #else
      return (*(CDlpObject**)lpWord->lpData)->Copy(*(CDlpObject**)lpWord->lpData,*(CDlpObject**)lpWordSrc->lpData);
    #endif
    }
    else if (*(CDlpObject**)lpWord->lpData)
    {
      IDESTROY((*(CDlpObject**)lpWord->lpData));
    }
  default:
    if (lpWord->ex.fld.nType>0 && lpWord->ex.fld.nType<=255)
    {
      dlp_memmove(lpWord->lpData,lpWordSrc->lpData,lpWord->ex.fld.nType);
      return O_K;
    }
    return NOT_EXEC;
  }
}
Exemplo n.º 25
0
/**
 * Base class implementation of the instance self check function.
 *
 * @param nMode Check mode, a combination of the CFM_XXX constants
 * @return <code>O_K</code> if successfull, a (negative) error code otherwise
 */
INT16 CDlpObject_Check(CDlpObject* _this, INT32 nMode)
{
  hscan_t  hs;
  hnode_t* hn;
  INT16    nRet         = O_K;
  SWord*   lpWord       = NULL;
  char     sFqn[L_SSTR];

  CHECK_THIS_RV(NOT_EXEC);
  DEBUGMSG(DM_KERNEL," Checking all fields of instance '%s' !",
    _this->m_lpInstanceName,0,0);

  hash_scan_begin(&hs,_this->m_lpDictionary);
  while ((hn = hash_scan_next(&hs))!=NULL)
  {
    lpWord = (SWord*)hnode_get(hn);
    if (!lpWord) continue;
    switch (lpWord->nWordType)
    {
      case WL_TYPE_FIELD:
        switch (lpWord->ex.fld.nType)
        {
          case T_INSTANCE:
            if (!*(CDlpObject**)lpWord->lpData) continue;
            CHECK_IPTR(*(CDlpObject**)lpWord->lpData,lpWord->ex.fld.nISerialNum);
            if (!*(CDlpObject**)lpWord->lpData)
            {
              sprintf(sFqn,"%s.%s",_this->m_lpInstanceName,lpWord->lpName);
              IERROR(_this,ERR_BADPTR,*(CDlpObject**)lpWord->lpData,"field",
                sFqn);
            }
            else if (nMode & CFM_RECURSIVE)
            {
              if (CDlpObject_GetParent(*(CDlpObject**)lpWord->lpData)==_this)
                CDlpObject_Check(*(CDlpObject**)lpWord->lpData,nMode);
            }
            break;

          case T_STRING:
          case T_CSTRING:
          case T_TEXT:
          case T_PTR:
            if (!*(void**)lpWord->lpData) continue;
            if (!dlp_in_xalloc(*(void**)lpWord->lpData))
            {
                sprintf(sFqn,"%s.%s",_this->m_lpInstanceName,lpWord->lpName);
                IERROR(_this,ERR_BADPTR,*(void**)lpWord->lpData,"field",sFqn);
              *(void**)lpWord->lpData = NULL;
            }
            break;
        }
        break;

      case WL_TYPE_INSTANCE:
        if (!(CDlpObject*)lpWord->lpData) continue;
        if (!CDlpObject_CheckInstancePtr((CDlpObject*)lpWord->lpData,0))
        {
          lpWord->lpData = NULL;
          sprintf(sFqn,"%s.%s",_this->m_lpInstanceName,lpWord->lpName);
          IERROR(_this,ERR_BADPTR,*(CDlpObject**)lpWord->lpData,"instance",
            sFqn);
        }
        else if (nMode & CFM_RECURSIVE)
        {
          if (CDlpObject_GetParent((CDlpObject*)lpWord->lpData)==_this)
            CDlpObject_Check((CDlpObject*)lpWord->lpData,nMode);
        }
        break;
    }
  }

  return nRet;
}
Exemplo n.º 26
0
/*
 * Manual page at fst_man.def
 */
INT16 CGEN_PUBLIC CFst_Compose
(
  CFst* _this,
  CFst* itSrc1,
  CFst* itSrc2,
  INT32  nUnit1,
  INT32  nUnit2
)
{
  BOOL          bNoeps;                                                         /* No implicit insertion of e.-loops */
  BOOL          bNoint;                                                         /* No intermediate symbols flag      */
  INT16         nCheck  = 0;                                                    /* Verbose level                     */
  INT16         nVirt   = 0;                                                    /* Auxiliary: patching ovrl.args. bug*/
  const char *err;

  /* Validate */
  CHECK_THIS_RV(NOT_EXEC);
  CFst_Check(itSrc1);
  CFst_Check(itSrc2);
  if (itSrc1==NULL || itSrc2==NULL)
  {
    CFst_Reset(BASEINST(_this),TRUE);
    return O_K;
  }
  if (nUnit1<0 || nUnit1>=UD_XXU(itSrc1)) return IERROR(_this,FST_BADID,"unit",nUnit1,0);
  if (nUnit2<0 || nUnit2>=UD_XXU(itSrc2)) return IERROR(_this,FST_BADID,"unit",nUnit2,0);

  if (CFst_Wsr_GetType(itSrc1,NULL)!=CFst_Wsr_GetType(itSrc2,NULL))
    return IERROR(_this,FST_INCOMPATIBLE,"weight semirings","itSrc1 and itSrc2",0);
  if (CData_FindComp(AS(CData,itSrc1->td),NC_TD_TIS)<0)
    return IERROR(_this,FST_MISS,"input symbol component" ,"","transition table of itSrc1");
  if (CData_FindComp(AS(CData,itSrc1->td),NC_TD_TOS)<0)
    return IERROR(_this,FST_MISS,"output symbol component","","transition table of itSrc1");
  if (CData_FindComp(AS(CData,itSrc2->td),NC_TD_TIS)<0)
    return IERROR(_this,FST_MISS,"input symbol component" ,"","transition table of itSrc2");
  if (CData_FindComp(AS(CData,itSrc2->td),NC_TD_TOS)<0)
    return IERROR(_this,FST_MISS,"output symbol component","","transition table of itSrc2");
  bNoeps = _this->m_bNoeps;
  bNoint = _this->m_bNoint;
  nCheck = BASEINST(_this)->m_nCheck;

  /* Initialize - NO RETURNS BEYOND THIS POINT */
  /* HACK: Multiple overlapping arguments on _this not handled correctly by
           CREATEVIRTUAL --> */
  if (_this==itSrc1 && _this==itSrc2) return IERROR(_this,ERR_GENERIC,"Invalid arguments",0,0);
  if      (itSrc1==_this) { CREATEVIRTUAL(CFst,itSrc1,_this); nVirt=1; }
  else if (itSrc2==_this) { CREATEVIRTUAL(CFst,itSrc2,_this); nVirt=2; }
  /* <-- */

  if((err=fstc_compose(itSrc1,nUnit1,itSrc2,nUnit2,
      bNoeps,bNoint,nCheck,
      _this)))
    return IERROR(_this,FST_INVALID,err,0,0);

  /* Copy input and output symbol tables */
  CData_SelectComps(AS(CData,_this->is),AS(CData,itSrc1->is),IS_XXS(itSrc1)==UD_XXU(itSrc1)?nUnit1:0,1);
  CData_SelectComps(AS(CData,_this->os),AS(CData,itSrc2->os),OS_XXS(itSrc2)==UD_XXU(itSrc2)?nUnit2:0,1);

  /* Clean up */
  if (nVirt==1) { DESTROYVIRTUAL(itSrc1,_this); }
  if (nVirt==2) { DESTROYVIRTUAL(itSrc2,_this); }
  CFst_Check(_this);
  CFst_TrimStates(_this,0);

  return O_K;
}
Exemplo n.º 27
0
/*
 * Manual page at statistics.def
 */
INT16 CGEN_PUBLIC CStatistics_Update
(
  CStatistics* _this,
  CData*       idVec,
  INT32         nIcLab,
  CData*       idW
)
{
  INT32        i           = 0;                                                  /* Update vector loop counter        */
  INT32        I           = 0;                                                  /* Number of update vectors          */
  INT32        c           = 0;                                                  /* Class of current update vector    */
  INT32        C           = 0;                                                  /* Number of classes                 */
  INT32        n           = 0;                                                  /* Dimension loop counter            */
  INT32        N           = 0;                                                  /* Statistics' dimensionality        */
  FLOAT64      w           = 0.;                                                 /* Weight of current update vector   */
  char*          lpsLab      = NULL;                                               /* Symbolic label of curr. upd. vec. */
  FLOAT64*     lpX         = NULL;                                               /* Vector copy buffer                */
  INT32        nVecIgnored = 0;                                                  /* Number of ignored vectors         */

  /* Validate */                                                                /* --------------------------------- */
  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);        /* ...                               */
  if (CData_IsEmpty(idVec)) return O_K;                                         /* No input vector(s), no service!   */
  I = CData_GetNRecs(idVec);                                                    /* Get number of update vectors      */
  C = CStatistics_GetNClasses(_this);                                           /* Get number of statitistics classes*/
  N = CStatistics_GetDim(_this);                                                /* Get statistics vector dimension   */
  if (C>1)                                                                      /* Multiclass statistics needs labels*/
  {                                                                             /* >>                                */
    if (_this->m_idLtb)                                                         /*   Need symbolic labels            */
    {                                                                           /*   >>                              */
      if ((nIcLab<0 || nIcLab>=CData_GetNComps(idVec)))                         /*     Symbolic label comp. not spec.*/
        for (nIcLab=0; nIcLab<CData_GetNComps(idVec); nIcLab++)                 /*       Seek label component        */
          if (dlp_is_symbolic_type_code(CData_GetCompType(idVec,nIcLab)))       /*       ...                         */
            break;                                                              /*       ...                         */
      if (!dlp_is_symbolic_type_code(CData_GetCompType(idVec,nIcLab)))          /*     Symbolic label comp. not found*/
        return                                                                  /*       -> Error                    */
          IERROR(_this,STA_BADCOMP,"Label",idVec->m_lpInstanceName,"symbolic"); /*       |                           */
    }                                                                           /*   <<                              */
    else                                                                        /*   Need numeric labels             */
    {                                                                           /*   >>                              */
      if (!dlp_is_numeric_type_code(CData_GetCompType(idVec,nIcLab)) &&         /*     Numeric label comp. not found */
          (nIcLab>=0 || CData_GetNComps(idW)!=C))                               /*     |                             */
        return                                                                  /*       -> Error                    */
          IERROR(_this,STA_BADCOMP,"Label",idVec->m_lpInstanceName,"numeric");  /*       |                           */
    }                                                                           /*   <<                              */
  }                                                                             /* <<                                */
  /*else if (nIcLab>=0) IERROR(_this,STA_IGNORE,"label component",0,0);        / * Only one class  -> ignore labels  */
  if (dlp_is_numeric_type_code(CData_GetCompType(idVec,nIcLab)))                /* Check no. of comps. in idVec ...  */
  {                                                                             /* >>                                */
    if (CData_GetNNumericComps(idVec)!=N+1)                                     /*   Wrong number of numeric comps.  */
      IERROR(_this,STA_DIM,idVec->m_lpInstanceName,"numeric components",N+1);   /*     -> Warning                    */
  }                                                                             /* <<                                */
  else if (CData_GetNNumericComps(idVec)!=N)                                    /* Wrong number of numeric comps.    */
    IERROR(_this,STA_DIM,idVec->m_lpInstanceName,"numeric components",N);       /*   -> Warning                      */

  if (idW)                                                                      /* Weigths passed -> check 'em       */
  {                                                                             /* >>                                */
    if (!dlp_is_numeric_type_code(CData_GetCompType(idW,0)))                    /*   Component 0 not numeric         */
      return                                                                    /*   -> Error                        */
        IERROR(_this,STA_BADCOMP,"Weight",idW->m_lpInstanceName,"numeric");     /*   |                               */
    if (CData_GetNComps(idW)!=1 && CData_GetNComps(idW)!=C)                     /*   More than one component         */
      IERROR(_this,STA_IGNORE,"components in weight sequence",0,0);             /*   -> Warning                      */
    if (CData_GetNRecs(idW)!=I)                                                 /*   Not exactly one weight per vec. */
      IERROR(_this,STA_DIM,idW->m_lpInstanceName,"records",I);                  /*   -> Warning                      */
  }                                                                             /* <<                                */

  /* Initialize - NO RETURNS BEYOND THIS POINT! - */                            /* --------------------------------- */
  lpX = (FLOAT64*)dlp_calloc(N,sizeof(FLOAT64));                                  /* Allocate vector copy buffer       */

  /* Update statistics */                                                       /* --------------------------------- */
  for (i=0; i<I; i++)                                                           /* Loop over update vectors          */
  {                                                                             /* >>                                */
    /* Get vector label */                                                      /*   - - - - - - - - - - - - - - - - */
    if (C>1)                                                                    /*   Multiclass stats. needs labels  */
    {                                                                           /*   >>                              */
      if (_this->m_idLtb)                                                       /*     idVec contains symbolic labs. */
      {                                                                         /*     >>                            */
        INT32 nLIdx = 0;
        DLPASSERT(dlp_is_symbolic_type_code(CData_GetCompType(idVec,nIcLab)));  /*       Must be checked before!     */
        lpsLab = (char*)CData_XAddr(idVec,i,nIcLab);                            /*       Get string ptr. to label    */
        if(_this->m_bLabel){
          nLIdx=strlen(lpsLab)-1;
          if(nLIdx && lpsLab[nLIdx]==']') nLIdx--; else nLIdx=0;
          if(nLIdx && lpsLab[nLIdx]>='0' && lpsLab[nLIdx]<='9') nLIdx--; else nLIdx=0;
          while(nLIdx && lpsLab[nLIdx]>='0' && lpsLab[nLIdx]<='9') nLIdx--;
          if(nLIdx && lpsLab[nLIdx]=='[') lpsLab[nLIdx]='\0'; else nLIdx=0;
        }
        c      = CData_Find(_this->m_idLtb,0,C,1,0,lpsLab);                     /*       Look up label -> class idx. */
        if(nLIdx) lpsLab[nLIdx]='[';
        if (c<0)                                                                /*       Label invalid               */
        {                                                                       /*       >>                          */
          IERROR(_this,STA_SLAB,i,lpsLab?lpsLab:"(null)",0);                    /*         Warning                   */
          continue;                                                             /*         Ignore record             */
        }                                                                       /*       <<                          */
      }                                                                         /*     <<                            */
      else if(nIcLab>=0)                                                        /*     idVec contains numeric labs.  */
      {                                                                         /*     >>                            */
        c = (INT32)CData_Dfetch(idVec,i,nIcLab);                                 /*       Fetch label                 */
        if (c<0 || c>=C)                                                        /*       Label invalid               */
        {                                                                       /*       >>                          */
          IERROR(_this,STA_NLAB,i,c,0);                                         /*         Warning                   */
          continue;                                                             /*         Ignore record             */
        }                                                                       /*       <<                          */
      }                                                                         /*     <<                            */
      else c = 0;                                                               /*     Default class is 0            */
    }                                                                           /*   <<                              */
    else c = 0;                                                                 /*   Default class is 0              */

    do                                                                          /*   Loop over classes               */
    {                                                                           /*   >>                              */

    /* Get (weighted) update vector and update statistics */                    /*   - - - - - - - - - - - - - - - - */
    if (idW)                                                                    /*   Using weights                   */
    {                                                                           /*   >>                              */
      w = CData_Dfetch(idW,i,_this->m_idLtb || nIcLab>=0 ? 0 : c);              /*     Fetch weight for this vector  */
      if(w==0.) continue;                                                       /*     Nothing to do if no weight    */
      _this->m_bWeighted=TRUE;
    } else w=1.;                                                                /*   <<                              */
    CData_DrecFetch(idVec,lpX,i,N,nIcLab);                                      /*   Fetch update vector             */
    fpclassify(0.);
    for (n=0; n<N; n++)                                                         /*   Loop over vector components     */
      if (fabs(lpX[n])>1E100)                                                   /*     Check value                   */
        break;                                                                  /*       There's something wrong ... */
    if (n<N) { nVecIgnored++; continue; }                                       /*   Ignore this vector              */
    CStatistics_UpdateVector(_this,lpX,c,w);                                    /*   Update statistics with vector   */

    }                                                                           /*   <<                              */
    while(!_this->m_idLtb && nIcLab<0 && ++c<C);                                /*   Next class if there is one      */
  }                                                                             /* <<                                */

  /* Clean up */                                                                /* --------------------------------- */
  if (nVecIgnored>0) IERROR(_this,STA_VECIGNORED,nVecIgnored,0,0);              /* Error: some vectors ignored       */
  dlp_free(lpX);                                                                /* Free vector copy buffer           */
  return O_K;                                                                   /* Done                              */
}