typedef struct { char *ALF; int nullchar; int *alfinds; int junkl; int junka; int nomorph; int nograd; int nalf; int Nwords; int infrloop; double infrtol; double gradstep; int learnloop; int Nlocal; int Ntopic; /*int favins;*/ int maxsenlen; int maxstrlen; } auxparamstype; #define NAUX 30 #define Ut(t) (((int)(_(U,0,t)))-1) #define ui(t) (u[t]) #define vj(t) (v[t]) #define UVARR(uv) mxGetCell(RAWVOC,uv) #define UVLEN(uv) mxGetN(UVARR(uv)) #define E10 (e1==NULLCHAR) #define E20 (e2==NULLCHAR) #define E1u (e1==ui(i-1)) #define E2v (e2==vj(j-1)) #define PMPuv PMP(ui(i-1),vj(j-1)) #define PMPu0 PMP(ui(i-1),NULLCHAR) #define PMP0v PMP(NULLCHAR,vj(j-1)) #define PMP00 PMP(NULLCHAR,NULLCHAR) #define RHO0 RHO(NULLCHAR) #define RHOu RHO(ui(i-1)) #define DRHO(x,y,z) DRhoDnu(x,y,z,AUXPARAMS) #define WEQ(j,t) ( ABS(_(Uniq,0,j)-_(U,0,t)) < EPS) /* P(rimitive) M(orphological) P(robability) */ #define PMP(a,b) _3(pmp,AUXPARAMS.alfinds[a-1],AUXPARAMS.alfinds[b-1],ell) #define RHO(a) _(rho,AUXPARAMS.alfinds[a-1],ell) /*#define JUNKELL 0*/ #define JUNKELL (AUXPARAMS.junkl) #define exists_junkell (JUNKELL>=0) /* #define NULLCHAR ('@')*/ #define NULLCHAR (AUXPARAMS.nullchar) #define JUNKTOP (AUXPARAMS.junka) #define NOMORPH (AUXPARAMS.nomorph) #define INFRLOOP (AUXPARAMS.infrloop) #define ITOL (AUXPARAMS.infrtol) #define MAXSTRLEN (AUXPARAMS.maxstrlen) #define MAXSENLEN (AUXPARAMS.maxsenlen) #define NTOPIC (AUXPARAMS.Ntopic) #define NLOCAL (AUXPARAMS.Nlocal) #define NVOCAB (AUXPARAMS.Nwords) #define NALF (AUXPARAMS.nalf) #define GETFLDR(X,s) (*mxGetPr(mxGetField(X,0,s))) void setauxparams(auxparamstype *AP,const mxArray *parampr) { const mxArray *ALFAr,*ALFindAr; int i,nalf,*alfinds,NCI; char *ALF; ALFAr = mxGetField(parampr,0,"ALF0"); ALFindAr = mxGetField(parampr,0,"alfinds"); NCI =(int)GETFLDR(parampr,"NCI")-1; /*index of NULLCHAR in ALFINDS */ AP->junkl =(int)GETFLDR(parampr,"JUNKELL")-1; /*junk state index */ AP->junka =(int)GETFLDR(parampr,"JUNKTOP")-1; /*junk topic index */ AP->nomorph =(int)GETFLDR(parampr,"nomorph"); /*don't do any morphology */ AP->nograd =(int)GETFLDR(parampr,"nograd"); /*don't do the morph. gradient */ AP->infrloop =(int)GETFLDR(parampr,"infrloop"); /*how long to iterate for qa and rv? */ AP->learnloop=(int)GETFLDR(parampr,"learnloop"); /*how many times to iterate updates */ AP->Nlocal =(int)GETFLDR(parampr,"Nlocal"); /*number of local states */ AP->Ntopic =(int)GETFLDR(parampr,"Ntopic"); /*number of topics */ AP->Nwords =(int)GETFLDR(parampr,"Nwords"); /*number of raw vocab words */ /*AP->favins =(int)GETFLDR(parampr,"favins"); /*favor insertions over deletions */ AP->infrtol = GETFLDR(parampr,"infrtol"); /*precision for inference */ AP->gradstep = GETFLDR(parampr,"gradstep"); /*gradient step size */ AP->maxsenlen=(int)GETFLDR(parampr,"maxsenlen"); /*maximum doc length */ AP->maxstrlen=(int)GETFLDR(parampr,"maxstrlen"); /*maximum string length */ /* alphabet-handling bureaucracy */ nalf = mxGetN(ALFAr); ALF = mxCalloc(nalf+1,sizeof(mxChar)); i = mxGetString(ALFAr,ALF,nalf*sizeof(mxChar)+1); alfinds = mxCalloc(mxGetM(ALFindAr),sizeof(int)); for(i=0;iALF = ALF; AP->alfinds = alfinds; AP->nullchar = ALF[NCI]; AP->nalf = nalf; } void freeauxparams(auxparamstype AUXPARAMS) { mxFree(AUXPARAMS.ALF); mxFree(AUXPARAMS.alfinds); } void normpmp(TENSOR3 pmp,auxparamstype AUXPARAMS) { int ell,i,j; double s; for(ell=0;ell